0

I am trying to add a counter in Flink as mentioned here, but the issue is that counter.inc() is returning void instead of Integer. Code for my Metric is given as below

    private  static class myMetric extends RichMapFunction<String,Integer> {
       private Counter counter ;

        @Override
        public void open(Configuration parameters) throws Exception {
            super.open(parameters);
            this.getRuntimeContext().
                    getMetricGroup().
                    counter("countit");
        }

        @Override
        public Integer map(String s) throws Exception {

            return this.counter.inc();

        }
    }
David Anderson
  • 39,434
  • 4
  • 33
  • 60
Amarjit Dhillon
  • 2,718
  • 3
  • 23
  • 62

1 Answers1

1

It should work better if you assign a value to your counter:

    this.counter = getRuntimeContext()
      .getMetricGroup()
      .counter("countit");

You may find the documentation helpful.

David Anderson
  • 39,434
  • 4
  • 33
  • 60