use of org.apache.flink.metrics.Counter in project flink by apache.
the class MetricListenerTest method testRegisterMetrics.
@Test
public void testRegisterMetrics() {
MetricListener metricListener = new MetricListener();
final MetricGroup metricGroup = metricListener.getMetricGroup();
// Counter
final Counter counter = metricGroup.counter(COUNTER_NAME);
counter.inc(15213);
final Optional<Counter> registeredCounter = metricListener.getCounter(COUNTER_NAME);
assertTrue(registeredCounter.isPresent());
assertEquals(15213L, registeredCounter.get().getCount());
// Gauge
metricGroup.gauge(GAUGE_NAME, () -> 15213);
final Optional<Gauge<Integer>> registeredGauge = metricListener.getGauge(GAUGE_NAME);
assertTrue(registeredGauge.isPresent());
assertEquals(Integer.valueOf(15213), registeredGauge.get().getValue());
// Meter
metricGroup.meter(METER_NAME, new Meter() {
@Override
public void markEvent() {
}
@Override
public void markEvent(long n) {
}
@Override
public double getRate() {
return 15213.0;
}
@Override
public long getCount() {
return 18213L;
}
});
final Optional<Meter> registeredMeter = metricListener.getMeter(METER_NAME);
assertTrue(registeredMeter.isPresent());
assertEquals(15213.0, registeredMeter.get().getRate(), 0.1);
assertEquals(18213L, registeredMeter.get().getCount());
// Histogram
metricGroup.histogram(HISTOGRAM_NAME, new Histogram() {
@Override
public void update(long value) {
}
@Override
public long getCount() {
return 15213L;
}
@Override
public HistogramStatistics getStatistics() {
return null;
}
});
final Optional<Histogram> registeredHistogram = metricListener.getHistogram(HISTOGRAM_NAME);
assertTrue(registeredHistogram.isPresent());
assertEquals(15213L, registeredHistogram.get().getCount());
}
use of org.apache.flink.metrics.Counter in project flink by apache.
the class MetricListenerTest method testRegisterMetricGroup.
@Test
public void testRegisterMetricGroup() {
MetricListener metricListener = new MetricListener();
final MetricGroup rootGroup = metricListener.getMetricGroup();
final MetricGroup groupA1 = rootGroup.addGroup(GROUP_A).addGroup(GROUP_A_1);
final MetricGroup groupB = rootGroup.addGroup(GROUP_B);
final MetricGroup groupB1 = groupB.addGroup(GROUP_B_1);
final MetricGroup groupB2 = groupB.addGroup(GROUP_B_2);
groupA1.counter(COUNTER_NAME).inc(18213L);
groupB1.gauge(GAUGE_NAME, () -> 15213L);
groupB2.counter(COUNTER_NAME).inc(15513L);
// groupA.groupA_1.testCounter
final Optional<Counter> counterA = metricListener.getCounter(GROUP_A, GROUP_A_1, COUNTER_NAME);
assertTrue(counterA.isPresent());
assertEquals(18213L, counterA.get().getCount());
// groupB.groupB_1.testGauge
final Optional<Gauge<Long>> gauge = metricListener.getGauge(GROUP_B, GROUP_B_1, GAUGE_NAME);
assertTrue(gauge.isPresent());
assertEquals(15213L, (long) gauge.get().getValue());
// groupB.groupB_2.testCounter
final Optional<Counter> counterB = metricListener.getCounter(GROUP_B, GROUP_B_2, COUNTER_NAME);
assertTrue(counterB.isPresent());
assertEquals(15513L, counterB.get().getCount());
}
use of org.apache.flink.metrics.Counter in project flink by apache.
the class RowTimeRowsUnboundedPrecedingFunctionTest method testLateRecordMetrics.
@Test
public void testLateRecordMetrics() throws Exception {
RowTimeRowsUnboundedPrecedingFunction<RowData> function = new RowTimeRowsUnboundedPrecedingFunction<>(1000, 2000, aggsHandleFunction, accTypes, inputFieldTypes, 2);
KeyedProcessOperator<RowData, RowData, RowData> operator = new KeyedProcessOperator<>(function);
OneInputStreamOperatorTestHarness<RowData, RowData> testHarness = createTestHarness(operator);
testHarness.open();
Counter counter = function.getCounter();
// put some records
testHarness.processElement(insertRecord("key", 1L, 100L));
testHarness.processElement(insertRecord("key", 1L, 100L));
testHarness.processElement(insertRecord("key", 1L, 500L));
testHarness.processWatermark(new Watermark(500L));
// late record
testHarness.processElement(insertRecord("key", 1L, 400L));
assertEquals(1L, counter.getCount());
}
Aggregations