Search in sources :

Example 16 with SimpleCounter

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

the class MetricRegistryImplTest method testExceptionIsolation.

@Test
public void testExceptionIsolation() throws Exception {
    MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryTestUtils.defaultMetricRegistryConfiguration(), Arrays.asList(ReporterSetup.forReporter("test1", new FailingReporter()), ReporterSetup.forReporter("test2", new TestReporter7())));
    Counter metric = new SimpleCounter();
    registry.register(metric, "counter", new MetricGroupTest.DummyAbstractMetricGroup(registry));
    assertEquals(metric, TestReporter7.addedMetric);
    assertEquals("counter", TestReporter7.addedMetricName);
    registry.unregister(metric, "counter", new MetricGroupTest.DummyAbstractMetricGroup(registry));
    assertEquals(metric, TestReporter7.removedMetric);
    assertEquals("counter", TestReporter7.removedMetricName);
    registry.shutdown().get();
}
Also used : SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) MetricGroupTest(org.apache.flink.runtime.metrics.groups.MetricGroupTest) MetricGroupTest(org.apache.flink.runtime.metrics.groups.MetricGroupTest) Test(org.junit.Test)

Example 17 with SimpleCounter

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

the class MetricFetcherTest method createRequestDumpAnswer.

private static MetricDumpSerialization.MetricSerializationResult createRequestDumpAnswer(InstanceID tmID, JobID jobID) throws IOException {
    Map<Counter, Tuple2<QueryScopeInfo, String>> counters = new HashMap<>();
    Map<Gauge<?>, Tuple2<QueryScopeInfo, String>> gauges = new HashMap<>();
    Map<Histogram, Tuple2<QueryScopeInfo, String>> histograms = new HashMap<>();
    Map<Meter, Tuple2<QueryScopeInfo, String>> meters = new HashMap<>();
    SimpleCounter c1 = new SimpleCounter();
    SimpleCounter c2 = new SimpleCounter();
    c1.inc(1);
    c2.inc(2);
    counters.put(c1, new Tuple2<QueryScopeInfo, String>(new QueryScopeInfo.OperatorQueryScopeInfo(jobID.toString(), "taskid", 2, "opname", "abc"), "oc"));
    counters.put(c2, new Tuple2<QueryScopeInfo, String>(new QueryScopeInfo.TaskQueryScopeInfo(jobID.toString(), "taskid", 2, "abc"), "tc"));
    meters.put(new Meter() {

        @Override
        public void markEvent() {
        }

        @Override
        public void markEvent(long n) {
        }

        @Override
        public double getRate() {
            return 5;
        }

        @Override
        public long getCount() {
            return 10;
        }
    }, new Tuple2<QueryScopeInfo, String>(new QueryScopeInfo.JobQueryScopeInfo(jobID.toString(), "abc"), "jc"));
    gauges.put(new Gauge<String>() {

        @Override
        public String getValue() {
            return "x";
        }
    }, new Tuple2<QueryScopeInfo, String>(new QueryScopeInfo.TaskManagerQueryScopeInfo(tmID.toString(), "abc"), "gauge"));
    histograms.put(new TestingHistogram(), new Tuple2<QueryScopeInfo, String>(new QueryScopeInfo.JobManagerQueryScopeInfo("abc"), "hist"));
    MetricDumpSerialization.MetricDumpSerializer serializer = new MetricDumpSerialization.MetricDumpSerializer();
    MetricDumpSerialization.MetricSerializationResult dump = serializer.serialize(counters, gauges, histograms, meters);
    serializer.close();
    return dump;
}
Also used : TestingHistogram(org.apache.flink.runtime.metrics.util.TestingHistogram) Histogram(org.apache.flink.metrics.Histogram) HashMap(java.util.HashMap) Meter(org.apache.flink.metrics.Meter) QueryScopeInfo(org.apache.flink.runtime.metrics.dump.QueryScopeInfo) Gauge(org.apache.flink.metrics.Gauge) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) MetricDumpSerialization(org.apache.flink.runtime.metrics.dump.MetricDumpSerialization) Tuple2(org.apache.flink.api.java.tuple.Tuple2) TestingHistogram(org.apache.flink.runtime.metrics.util.TestingHistogram)

Example 18 with SimpleCounter

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

the class PrometheusReporterTaskScopeTest method countersCanBeAddedSeveralTimesIfTheyDifferInLabels.

@Test
void countersCanBeAddedSeveralTimesIfTheyDifferInLabels() throws UnirestException {
    Counter counter1 = new SimpleCounter();
    counter1.inc(1);
    Counter counter2 = new SimpleCounter();
    counter2.inc(2);
    taskMetricGroup1.counter("my_counter", counter1);
    taskMetricGroup2.counter("my_counter", counter2);
    assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_counter", LABEL_NAMES, labelValues1)).isEqualTo(1.);
    assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_counter", LABEL_NAMES, labelValues2)).isEqualTo(2.);
}
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 19 with SimpleCounter

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

the class PrometheusReporterTaskScopeTest method removingSingleInstanceOfMetricDoesNotBreakOtherInstances.

@Test
void removingSingleInstanceOfMetricDoesNotBreakOtherInstances() throws UnirestException {
    Counter counter1 = new SimpleCounter();
    counter1.inc(1);
    Counter counter2 = new SimpleCounter();
    counter2.inc(2);
    taskMetricGroup1.counter("my_counter", counter1);
    taskMetricGroup2.counter("my_counter", counter2);
    assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_counter", LABEL_NAMES, labelValues1)).isEqualTo(1.);
    assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_counter", LABEL_NAMES, labelValues2)).isEqualTo(2.);
    taskMetricGroup2.close();
    assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_counter", LABEL_NAMES, labelValues1)).isEqualTo(1.);
    taskMetricGroup1.close();
    assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_counter", LABEL_NAMES, labelValues1)).isNull();
}
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 20 with SimpleCounter

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

the class StatsDReporterTest method testAddingMetrics.

/**
 * Tests that the registered metrics' names don't contain invalid characters.
 */
@Test
void testAddingMetrics() {
    String counterName = "testCounter";
    final String scope = "scope";
    final char delimiter = '_';
    MetricGroup metricGroup = TestMetricGroup.newBuilder().setMetricIdentifierFunction((metricName, characterFilter) -> scope + delimiter + metricName).build();
    TestingStatsDReporter reporter = new TestingStatsDReporter();
    reporter.open(new MetricConfig());
    SimpleCounter myCounter = new SimpleCounter();
    reporter.notifyOfAddedMetric(myCounter, counterName, metricGroup);
    Map<Counter, String> counters = reporter.getCounters();
    assertThat(counters).containsKey(myCounter);
    String expectedCounterName = reporter.filterCharacters(scope) + delimiter + reporter.filterCharacters(counterName);
    assertThat(counters.get(myCounter)).isEqualTo(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) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) TestMeter(org.apache.flink.metrics.util.TestMeter) Metric(org.apache.flink.metrics.Metric) TestCounter(org.apache.flink.metrics.util.TestCounter) Test(org.junit.jupiter.api.Test) DatagramSocket(java.net.DatagramSocket) HashSet(java.util.HashSet) MetricGroup(org.apache.flink.metrics.MetricGroup) SocketException(java.net.SocketException) TestHistogram(org.apache.flink.metrics.util.TestHistogram) Map(java.util.Map) ConfigConstants(org.apache.flink.configuration.ConfigConstants) Gauge(org.apache.flink.metrics.Gauge) SimpleCounter(org.apache.flink.metrics.SimpleCounter) DatagramPacket(java.net.DatagramPacket) Counter(org.apache.flink.metrics.Counter) MetricConfig(org.apache.flink.metrics.MetricConfig) TestCounter(org.apache.flink.metrics.util.TestCounter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) TestMetricGroup(org.apache.flink.metrics.util.TestMetricGroup) MetricGroup(org.apache.flink.metrics.MetricGroup) Test(org.junit.jupiter.api.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