use of org.apache.flink.metrics.util.TestHistogram in project flink by apache.
the class DatadogHttpClientTest method serializeHistogram.
@Test
public void serializeHistogram() throws JsonProcessingException {
DHistogram h = new DHistogram(new TestHistogram(), METRIC, HOST, tags, () -> MOCKED_SYSTEM_MILLIS);
DSeries series = new DSeries();
h.addTo(series);
assertSerialization(DatadogHttpClient.serialize(series), new MetricAssertion(MetricType.gauge, true, "4.0", DHistogram.SUFFIX_AVG), new MetricAssertion(MetricType.gauge, true, "1", DHistogram.SUFFIX_COUNT), new MetricAssertion(MetricType.gauge, true, "0.5", DHistogram.SUFFIX_MEDIAN), new MetricAssertion(MetricType.gauge, true, "0.95", DHistogram.SUFFIX_95_PERCENTILE), new MetricAssertion(MetricType.gauge, true, "7", DHistogram.SUFFIX_MIN), new MetricAssertion(MetricType.gauge, true, "6", DHistogram.SUFFIX_MAX));
}
use of org.apache.flink.metrics.util.TestHistogram in project flink by apache.
the class MetricQueryServiceTest method testCreateDump.
@Test
public void testCreateDump() throws Exception {
MetricQueryService queryService = MetricQueryService.createMetricQueryService(rpcService, ResourceID.generate(), Long.MAX_VALUE);
queryService.start();
final Counter c = new SimpleCounter();
final Gauge<String> g = () -> "Hello";
final Histogram h = new TestHistogram();
final Meter m = new TestMeter();
final TaskManagerMetricGroup tm = UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup();
queryService.addMetric("counter", c, tm);
queryService.addMetric("gauge", g, tm);
queryService.addMetric("histogram", h, tm);
queryService.addMetric("meter", m, tm);
MetricDumpSerialization.MetricSerializationResult dump = queryService.queryMetrics(TIMEOUT).get();
assertTrue(dump.serializedCounters.length > 0);
assertTrue(dump.serializedGauges.length > 0);
assertTrue(dump.serializedHistograms.length > 0);
assertTrue(dump.serializedMeters.length > 0);
queryService.removeMetric(c);
queryService.removeMetric(g);
queryService.removeMetric(h);
queryService.removeMetric(m);
MetricDumpSerialization.MetricSerializationResult emptyDump = queryService.queryMetrics(TIMEOUT).get();
assertEquals(0, emptyDump.serializedCounters.length);
assertEquals(0, emptyDump.serializedGauges.length);
assertEquals(0, emptyDump.serializedHistograms.length);
assertEquals(0, emptyDump.serializedMeters.length);
}
use of org.apache.flink.metrics.util.TestHistogram in project flink by apache.
the class MetricFetcherTest method createRequestDumpAnswer.
private static MetricDumpSerialization.MetricSerializationResult createRequestDumpAnswer(ResourceID tmRID, JobID jobID) {
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<>(new QueryScopeInfo.OperatorQueryScopeInfo(jobID.toString(), "taskid", 2, "opname", "abc"), "oc"));
counters.put(c2, new Tuple2<>(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<>(new QueryScopeInfo.JobQueryScopeInfo(jobID.toString(), "abc"), "jc"));
gauges.put(new Gauge<String>() {
@Override
public String getValue() {
return "x";
}
}, new Tuple2<>(new QueryScopeInfo.TaskManagerQueryScopeInfo(tmRID.toString(), "abc"), "gauge"));
histograms.put(new TestHistogram(), new Tuple2<>(new QueryScopeInfo.JobManagerQueryScopeInfo("abc"), "hist"));
MetricDumpSerialization.MetricDumpSerializer serializer = new MetricDumpSerialization.MetricDumpSerializer();
MetricDumpSerialization.MetricSerializationResult dump = serializer.serialize(counters, gauges, histograms, meters);
serializer.close();
return dump;
}
Aggregations