Search in sources :

Example 21 with SimpleCounter

use of org.apache.flink.metrics.SimpleCounter in project flink by apache.

the class InfluxdbReporterTest method testMetricRegistration.

@Test
void testMetricRegistration() {
    InfluxdbReporter reporter = createReporter(InfluxdbReporterOptions.RETENTION_POLICY.defaultValue(), InfluxdbReporterOptions.CONSISTENCY.defaultValue());
    String metricName = "TestCounter";
    Counter counter = new SimpleCounter();
    reporter.notifyOfAddedMetric(counter, metricName, metricGroup);
    MeasurementInfo measurementInfo = reporter.counters.get(counter);
    assertThat(measurementInfo).isNotNull();
    assertThat(measurementInfo.getName()).isEqualTo("taskmanager_" + metricName);
    assertThat(measurementInfo.getTags()).containsEntry("host", METRIC_HOSTNAME);
}
Also used : SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Test(org.junit.jupiter.api.Test)

Example 22 with SimpleCounter

use of org.apache.flink.metrics.SimpleCounter in project flink by apache.

the class MetricMapperTest method testMapCounter.

@Test
void testMapCounter() {
    Counter counter = new SimpleCounter();
    counter.inc(42L);
    verifyPoint(MetricMapper.map(INFO, TIMESTAMP, counter), "count=42");
}
Also used : SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Test(org.junit.jupiter.api.Test)

Example 23 with SimpleCounter

use of org.apache.flink.metrics.SimpleCounter in project flink by apache.

the class DCounterTest method testGetMetricValue.

@Test
public void testGetMetricValue() {
    final Counter backingCounter = new SimpleCounter();
    final DCounter counter = new DCounter(backingCounter, "counter", "localhost", Collections.emptyList(), () -> 0);
    // sane initial state
    assertEquals(0L, counter.getMetricValue());
    counter.ackReport();
    assertEquals(0L, counter.getMetricValue());
    // value is compared against initial state 0
    backingCounter.inc(10);
    assertEquals(10L, counter.getMetricValue());
    // last value was not acked, should still be compared against initial state 0
    backingCounter.inc(10);
    assertEquals(20L, counter.getMetricValue());
    // last value (20) acked, now target of comparison
    counter.ackReport();
    assertEquals(0L, counter.getMetricValue());
    // we now compare against the acked value
    backingCounter.inc(10);
    assertEquals(10L, counter.getMetricValue());
    // properly handle decrements
    backingCounter.dec(10);
    assertEquals(0L, counter.getMetricValue());
}
Also used : SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Test(org.junit.Test)

Example 24 with SimpleCounter

use of org.apache.flink.metrics.SimpleCounter in project flink by apache.

the class ScheduledDropwizardReporterTest method testAddingMetrics.

/**
 * Tests that the registered metrics' names don't contain invalid characters.
 */
@Test
void testAddingMetrics() {
    final String scope = "scope";
    final char delimiter = '_';
    final String counterName = "testCounter";
    final MetricGroup metricGroup = TestMetricGroup.newBuilder().setMetricIdentifierFunction((metricName, characterFilter) -> characterFilter.orElse(s -> s).filterCharacters(scope + delimiter + metricName)).build();
    final TestingScheduledDropwizardReporter reporter = new TestingScheduledDropwizardReporter();
    SimpleCounter myCounter = new SimpleCounter();
    com.codahale.metrics.Meter dropwizardMeter = new com.codahale.metrics.Meter();
    DropwizardMeterWrapper meterWrapper = new DropwizardMeterWrapper(dropwizardMeter);
    reporter.notifyOfAddedMetric(myCounter, counterName, metricGroup);
    reporter.notifyOfAddedMetric(meterWrapper, "meter", metricGroup);
    Map<Counter, String> counters = reporter.getCounters();
    assertThat(counters).containsKey(myCounter);
    Map<Meter, String> meters = reporter.getMeters();
    assertThat(meters).containsKey(meterWrapper);
    String expectedCounterName = reporter.filterCharacters(scope) + delimiter + reporter.filterCharacters(counterName);
    assertThat(counters).containsEntry(myCounter, expectedCounterName);
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig) UnregisteredMetricsGroup(org.apache.flink.metrics.groups.UnregisteredMetricsGroup) TestMetricGroup(org.apache.flink.metrics.util.TestMetricGroup) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ScheduledReporter(com.codahale.metrics.ScheduledReporter) DropwizardMeterWrapper(org.apache.flink.dropwizard.metrics.DropwizardMeterWrapper) TestMeter(org.apache.flink.metrics.util.TestMeter) Histogram(org.apache.flink.metrics.Histogram) Test(org.junit.jupiter.api.Test) Meter(org.apache.flink.metrics.Meter) MetricGroup(org.apache.flink.metrics.MetricGroup) TestHistogram(org.apache.flink.metrics.util.TestHistogram) Map(java.util.Map) Gauge(org.apache.flink.metrics.Gauge) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) TestMeter(org.apache.flink.metrics.util.TestMeter) Meter(org.apache.flink.metrics.Meter) TestMetricGroup(org.apache.flink.metrics.util.TestMetricGroup) MetricGroup(org.apache.flink.metrics.MetricGroup) DropwizardMeterWrapper(org.apache.flink.dropwizard.metrics.DropwizardMeterWrapper) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Test(org.junit.jupiter.api.Test)

Example 25 with SimpleCounter

use of org.apache.flink.metrics.SimpleCounter in project beam by apache.

the class FlinkMetricContainerTest method testDropUnexpectedMonitoringInfoTypes.

@Test
public void testDropUnexpectedMonitoringInfoTypes() {
    MetricsContainerImpl step = container.getMetricsContainer("step");
    MonitoringInfo intCounter = new SimpleMonitoringInfoBuilder().setUrn(MonitoringInfoConstants.Urns.USER_SUM_INT64).setLabel(MonitoringInfoConstants.Labels.NAMESPACE, "ns1").setLabel(MonitoringInfoConstants.Labels.NAME, "int_counter").setLabel(MonitoringInfoConstants.Labels.PTRANSFORM, "step").setInt64SumValue(111).build();
    MonitoringInfo doubleCounter = new SimpleMonitoringInfoBuilder().setUrn(MonitoringInfoConstants.Urns.USER_SUM_DOUBLE).setLabel(MonitoringInfoConstants.Labels.NAMESPACE, "ns2").setLabel(MonitoringInfoConstants.Labels.NAME, "double_counter").setLabel(MonitoringInfoConstants.Labels.PTRANSFORM, "step").setDoubleSumValue(222).build();
    MonitoringInfo intDistribution = new SimpleMonitoringInfoBuilder().setUrn(MonitoringInfoConstants.Urns.USER_DISTRIBUTION_INT64).setLabel(MonitoringInfoConstants.Labels.NAMESPACE, "ns3").setLabel(MonitoringInfoConstants.Labels.NAME, "int_distribution").setLabel(MonitoringInfoConstants.Labels.PTRANSFORM, "step").setInt64DistributionValue(DistributionData.create(30, 10, 1, 5)).build();
    MonitoringInfo doubleDistribution = new SimpleMonitoringInfoBuilder().setUrn(MonitoringInfoConstants.Urns.USER_DISTRIBUTION_DOUBLE).setLabel(MonitoringInfoConstants.Labels.NAMESPACE, "ns4").setLabel(MonitoringInfoConstants.Labels.NAME, "double_distribution").setLabel(MonitoringInfoConstants.Labels.PTRANSFORM, "step").setDoubleDistributionValue(10, 30, 1, 5).build();
    // Mock out the counter that Flink returns; the distribution gets created by
    // FlinkMetricContainer, not by Flink itself, so we verify it in a different way below
    SimpleCounter counter = new SimpleCounter();
    when(metricGroup.counter("ns1.int_counter")).thenReturn(counter);
    container.updateMetrics("step", ImmutableList.of(intCounter, doubleCounter, intDistribution, doubleDistribution));
    // Flink's MetricGroup should only have asked for one counter (the integer-typed one) to be
    // created (the double-typed one is dropped currently)
    verify(metricGroup).counter(eq("ns1.int_counter"));
    // Verify that the counter injected into flink has the right value
    assertThat(counter.getCount(), is(111L));
    // Verify the counter in the java SDK MetricsContainer
    long count = ((CounterCell) step.tryGetCounter(MonitoringInfoMetricName.of(intCounter))).getCumulative();
    assertThat(count, is(111L));
    // The one Flink distribution that gets created is a FlinkDistributionGauge; here we verify its
    // initial (and in this test, final) value
    verify(metricGroup).gauge(eq("ns3.int_distribution"), argThat(new ArgumentMatcher<FlinkDistributionGauge>() {

        @Override
        public boolean matches(FlinkDistributionGauge argument) {
            DistributionResult actual = ((FlinkDistributionGauge) argument).getValue();
            DistributionResult expected = DistributionResult.create(30, 10, 1, 5);
            return actual.equals(expected);
        }
    }));
    // Verify that the Java SDK MetricsContainer holds the same information
    DistributionData distributionData = ((DistributionCell) step.getDistribution(MonitoringInfoMetricName.of(intDistribution))).getCumulative();
    assertThat(distributionData, is(DistributionData.create(30, 10, 1, 5)));
}
Also used : MetricsContainerImpl(org.apache.beam.runners.core.metrics.MetricsContainerImpl) CounterCell(org.apache.beam.runners.core.metrics.CounterCell) DistributionResult(org.apache.beam.sdk.metrics.DistributionResult) MonitoringInfo(org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo) SimpleMonitoringInfoBuilder(org.apache.beam.runners.core.metrics.SimpleMonitoringInfoBuilder) SimpleCounter(org.apache.flink.metrics.SimpleCounter) DistributionData(org.apache.beam.runners.core.metrics.DistributionData) ArgumentMatcher(org.mockito.ArgumentMatcher) FlinkDistributionGauge(org.apache.beam.runners.flink.metrics.FlinkMetricContainer.FlinkDistributionGauge) DistributionCell(org.apache.beam.runners.core.metrics.DistributionCell) Test(org.junit.Test)

Aggregations

SimpleCounter (org.apache.flink.metrics.SimpleCounter)31 Counter (org.apache.flink.metrics.Counter)23 Test (org.junit.Test)13 Test (org.junit.jupiter.api.Test)12 Meter (org.apache.flink.metrics.Meter)8 Histogram (org.apache.flink.metrics.Histogram)7 TestHistogram (org.apache.flink.metrics.util.TestHistogram)7 Gauge (org.apache.flink.metrics.Gauge)6 TestMeter (org.apache.flink.metrics.util.TestMeter)5 MonitoringInfo (org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo)4 SimpleMonitoringInfoBuilder (org.apache.beam.runners.core.metrics.SimpleMonitoringInfoBuilder)4 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)4 MetricGroupTest (org.apache.flink.runtime.metrics.groups.MetricGroupTest)4 HashMap (java.util.HashMap)3 MetricGroup (org.apache.flink.metrics.MetricGroup)3 UnregisteredMetricsGroup (org.apache.flink.metrics.groups.UnregisteredMetricsGroup)3 TestMetricGroup (org.apache.flink.metrics.util.TestMetricGroup)3 List (java.util.List)2 Map (java.util.Map)2 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)2