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();
}
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;
}
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.);
}
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();
}
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);
}
Aggregations