Amarjit Dhillon
Amarjit Dhillon

Reputation: 2816

unable to add counter in Flink 1.3.2

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();

        }
    }

Upvotes: 0

Views: 78

Answers (1)

David Anderson
David Anderson

Reputation: 43717

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

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

You may find the documentation helpful.

Upvotes: 1

Related Questions