org.apache.flink.metrics.util.TestHistogram Java Examples
The following examples show how to use
org.apache.flink.metrics.util.TestHistogram.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetricMapperTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testMapHistogram() { Histogram histogram = new TestHistogram(); verifyPoint( MetricMapper.map(INFO, TIMESTAMP, histogram), "count=3", "max=6", "mean=4.0", "min=7", "p50=0.5", "p75=0.75", "p95=0.95", "p98=0.98", "p99=0.99", "p999=0.999", "stddev=5.0"); }
Example #2
Source File: PrometheusReporterTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void histogramIsReportedAsPrometheusSummary() throws UnirestException { Histogram testHistogram = new TestHistogram(); String histogramName = "testHistogram"; String summaryName = SCOPE_PREFIX + histogramName; String response = addMetricAndPollResponse(testHistogram, histogramName); assertThat(response, containsString(HELP_PREFIX + summaryName + " " + histogramName + " (scope: taskmanager)\n" + TYPE_PREFIX + summaryName + " summary" + "\n" + summaryName + "_count" + DEFAULT_LABELS + " 1.0" + "\n")); for (String quantile : Arrays.asList("0.5", "0.75", "0.95", "0.98", "0.99", "0.999")) { assertThat(response, containsString( summaryName + "{" + DIMENSIONS + ",quantile=\"" + quantile + "\",} " + quantile + "\n")); } }
Example #3
Source File: PrometheusReporterTaskScopeTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void histogramsCanBeAddedSeveralTimesIfTheyDifferInLabels() throws UnirestException { Histogram histogram = new TestHistogram(); taskMetricGroup1.histogram("my_histogram", histogram); taskMetricGroup2.histogram("my_histogram", histogram); final String exportedMetrics = pollMetrics(reporter.getPort()).getBody(); assertThat(exportedMetrics, containsString("subtask_index=\"0\",quantile=\"0.5\",} 0.5")); // histogram assertThat(exportedMetrics, containsString("subtask_index=\"1\",quantile=\"0.5\",} 0.5")); // histogram final String[] labelNamesWithQuantile = addToArray(LABEL_NAMES, "quantile"); for (Double quantile : PrometheusReporter.HistogramSummaryProxy.QUANTILES) { assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_histogram", labelNamesWithQuantile, addToArray(labelValues1, "" + quantile)), equalTo(quantile)); assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_histogram", labelNamesWithQuantile, addToArray(labelValues2, "" + quantile)), equalTo(quantile)); } }
Example #4
Source File: PrometheusReporterTaskScopeTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void histogramsCanBeAddedSeveralTimesIfTheyDifferInLabels() throws UnirestException { Histogram histogram = new TestHistogram(); taskMetricGroup1.histogram("my_histogram", histogram); taskMetricGroup2.histogram("my_histogram", histogram); final String exportedMetrics = pollMetrics(reporter.getPort()).getBody(); assertThat(exportedMetrics, containsString("subtask_index=\"0\",quantile=\"0.5\",} 0.5")); // histogram assertThat(exportedMetrics, containsString("subtask_index=\"1\",quantile=\"0.5\",} 0.5")); // histogram final String[] labelNamesWithQuantile = addToArray(LABEL_NAMES, "quantile"); for (Double quantile : PrometheusReporter.HistogramSummaryProxy.QUANTILES) { assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_histogram", labelNamesWithQuantile, addToArray(labelValues1, "" + quantile)), equalTo(quantile)); assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_histogram", labelNamesWithQuantile, addToArray(labelValues2, "" + quantile)), equalTo(quantile)); } }
Example #5
Source File: PrometheusReporterTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void histogramIsReportedAsPrometheusSummary() throws UnirestException { Histogram testHistogram = new TestHistogram(); String histogramName = "testHistogram"; String summaryName = SCOPE_PREFIX + histogramName; String response = addMetricAndPollResponse(testHistogram, histogramName); assertThat(response, containsString(HELP_PREFIX + summaryName + " " + histogramName + " (scope: taskmanager)\n" + TYPE_PREFIX + summaryName + " summary" + "\n" + summaryName + "_count" + DEFAULT_LABELS + " 1.0" + "\n")); for (String quantile : Arrays.asList("0.5", "0.75", "0.95", "0.98", "0.99", "0.999")) { assertThat(response, containsString( summaryName + "{" + DIMENSIONS + ",quantile=\"" + quantile + "\",} " + quantile + "\n")); } }
Example #6
Source File: MetricMapperTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testMapHistogram() { Histogram histogram = new TestHistogram(); verifyPoint( MetricMapper.map(INFO, TIMESTAMP, histogram), "count=3", "max=6", "mean=4.0", "min=7", "p50=0.5", "p75=0.75", "p95=0.95", "p98=0.98", "p99=0.99", "p999=0.999", "stddev=5.0"); }
Example #7
Source File: Slf4jReporterTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testAddHistogram() throws Exception { String histogramName = "histogram"; Histogram histogram = taskMetricGroup.histogram(histogramName, new TestHistogram()); assertTrue(reporter.getHistograms().containsKey(histogram)); String expectedHistogramName = reporter.filterCharacters(HOST_NAME) + delimiter + reporter.filterCharacters(TASK_MANAGER_ID) + delimiter + reporter.filterCharacters(JOB_NAME) + delimiter + reporter.filterCharacters(histogramName); reporter.report(); assertThat( testLoggerResource.getMessages(), hasItem(containsString(expectedHistogramName))); }
Example #8
Source File: StatsDReporterTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that histograms are properly reported via the StatsD reporter. */ @Test public void testStatsDHistogramReporting() throws Exception { Set<String> expectedLines = new HashSet<>(6); expectedLines.add("metric.count:1|g"); expectedLines.add("metric.mean:4.0|g"); expectedLines.add("metric.min:7|g"); expectedLines.add("metric.max:6|g"); expectedLines.add("metric.stddev:5.0|g"); expectedLines.add("metric.p75:0.75|g"); expectedLines.add("metric.p98:0.98|g"); expectedLines.add("metric.p99:0.99|g"); expectedLines.add("metric.p999:0.999|g"); expectedLines.add("metric.p95:0.95|g"); expectedLines.add("metric.p50:0.5|g"); testMetricAndAssert(new TestHistogram(), "metric", expectedLines); }
Example #9
Source File: StatsDReporterTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that histograms are properly reported via the StatsD reporter. */ @Test public void testStatsDHistogramReporting() throws Exception { Set<String> expectedLines = new HashSet<>(6); expectedLines.add("metric.count:1|g"); expectedLines.add("metric.mean:4.0|g"); expectedLines.add("metric.min:7|g"); expectedLines.add("metric.max:6|g"); expectedLines.add("metric.stddev:5.0|g"); expectedLines.add("metric.p75:0.75|g"); expectedLines.add("metric.p98:0.98|g"); expectedLines.add("metric.p99:0.99|g"); expectedLines.add("metric.p999:0.999|g"); expectedLines.add("metric.p95:0.95|g"); expectedLines.add("metric.p50:0.5|g"); testMetricAndAssert(new TestHistogram(), "metric", expectedLines); }
Example #10
Source File: MetricMapperTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testMapHistogram() { Histogram histogram = new TestHistogram(); verifyPoint( MetricMapper.map(INFO, TIMESTAMP, histogram), "count=3", "max=6", "mean=4.0", "min=7", "p50=0.5", "p75=0.75", "p95=0.95", "p98=0.98", "p99=0.99", "p999=0.999", "stddev=5.0"); }
Example #11
Source File: PrometheusReporterTaskScopeTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void histogramsCanBeAddedSeveralTimesIfTheyDifferInLabels() throws UnirestException { Histogram histogram = new TestHistogram(); taskMetricGroup1.histogram("my_histogram", histogram); taskMetricGroup2.histogram("my_histogram", histogram); final String exportedMetrics = pollMetrics(reporter.getPort()).getBody(); assertThat(exportedMetrics, containsString("subtask_index=\"0\",quantile=\"0.5\",} 0.5")); // histogram assertThat(exportedMetrics, containsString("subtask_index=\"1\",quantile=\"0.5\",} 0.5")); // histogram final String[] labelNamesWithQuantile = addToArray(LABEL_NAMES, "quantile"); for (Double quantile : PrometheusReporter.HistogramSummaryProxy.QUANTILES) { assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_histogram", labelNamesWithQuantile, addToArray(labelValues1, "" + quantile)), equalTo(quantile)); assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_histogram", labelNamesWithQuantile, addToArray(labelValues2, "" + quantile)), equalTo(quantile)); } }
Example #12
Source File: PrometheusReporterTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void histogramIsReportedAsPrometheusSummary() throws UnirestException { Histogram testHistogram = new TestHistogram(); String histogramName = "testHistogram"; String summaryName = SCOPE_PREFIX + histogramName; String response = addMetricAndPollResponse(testHistogram, histogramName); assertThat(response, containsString(HELP_PREFIX + summaryName + " " + histogramName + " (scope: taskmanager)\n" + TYPE_PREFIX + summaryName + " summary" + "\n" + summaryName + "_count" + DEFAULT_LABELS + " 1.0" + "\n")); for (String quantile : Arrays.asList("0.5", "0.75", "0.95", "0.98", "0.99", "0.999")) { assertThat(response, containsString( summaryName + "{" + DIMENSIONS + ",quantile=\"" + quantile + "\",} " + quantile + "\n")); } }
Example #13
Source File: Slf4jReporterTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testAddHistogram() throws Exception { String histogramName = "histogram"; Histogram histogram = taskMetricGroup.histogram(histogramName, new TestHistogram()); assertTrue(reporter.getHistograms().containsKey(histogram)); String expectedHistogramName = reporter.filterCharacters(HOST_NAME) + delimiter + reporter.filterCharacters(TASK_MANAGER_ID) + delimiter + reporter.filterCharacters(JOB_NAME) + delimiter + reporter.filterCharacters(histogramName); reporter.report(); TestUtils.checkForLogString(expectedHistogramName); }
Example #14
Source File: StatsDReporterTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testStatsDHistogramReportingOfNegativeValues() throws Exception { TestHistogram histogram = new TestHistogram(); histogram.setCount(-101); histogram.setMean(-104); histogram.setMin(-107); histogram.setMax(-106); histogram.setStdDev(-105); Set<String> expectedLines = new HashSet<>(); expectedLines.add("metric.count:0|g"); expectedLines.add("metric.count:-101|g"); expectedLines.add("metric.mean:0|g"); expectedLines.add("metric.mean:-104.0|g"); expectedLines.add("metric.min:0|g"); expectedLines.add("metric.min:-107|g"); expectedLines.add("metric.max:0|g"); expectedLines.add("metric.max:-106|g"); expectedLines.add("metric.stddev:0|g"); expectedLines.add("metric.stddev:-105.0|g"); expectedLines.add("metric.p75:0.75|g"); expectedLines.add("metric.p98:0.98|g"); expectedLines.add("metric.p99:0.99|g"); expectedLines.add("metric.p999:0.999|g"); expectedLines.add("metric.p95:0.95|g"); expectedLines.add("metric.p50:0.5|g"); testMetricAndAssert(histogram, "metric", expectedLines); }
Example #15
Source File: MetricQueryServiceTest.java From flink with Apache License 2.0 | 5 votes |
@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); }
Example #16
Source File: StatsDReporterTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testStatsDHistogramReportingOfNegativeValues() throws Exception { TestHistogram histogram = new TestHistogram(); histogram.setCount(-101); histogram.setMean(-104); histogram.setMin(-107); histogram.setMax(-106); histogram.setStdDev(-105); Set<String> expectedLines = new HashSet<>(); expectedLines.add("metric.count:0|g"); expectedLines.add("metric.count:-101|g"); expectedLines.add("metric.mean:0|g"); expectedLines.add("metric.mean:-104.0|g"); expectedLines.add("metric.min:0|g"); expectedLines.add("metric.min:-107|g"); expectedLines.add("metric.max:0|g"); expectedLines.add("metric.max:-106|g"); expectedLines.add("metric.stddev:0|g"); expectedLines.add("metric.stddev:-105.0|g"); expectedLines.add("metric.p75:0.75|g"); expectedLines.add("metric.p98:0.98|g"); expectedLines.add("metric.p99:0.99|g"); expectedLines.add("metric.p999:0.999|g"); expectedLines.add("metric.p95:0.95|g"); expectedLines.add("metric.p50:0.5|g"); testMetricAndAssert(histogram, "metric", expectedLines); }
Example #17
Source File: MetricQueryServiceTest.java From flink with Apache License 2.0 | 5 votes |
@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); }
Example #18
Source File: Slf4jReporterTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testAddHistogram() throws Exception { String histogramName = "histogram"; Histogram histogram = taskMetricGroup.histogram(histogramName, new TestHistogram()); assertTrue(reporter.getHistograms().containsKey(histogram)); String expectedHistogramName = reporter.filterCharacters(HOST_NAME) + delimiter + reporter.filterCharacters(TASK_MANAGER_ID) + delimiter + reporter.filterCharacters(JOB_NAME) + delimiter + reporter.filterCharacters(histogramName); reporter.report(); TestUtils.checkForLogString(expectedHistogramName); }
Example #19
Source File: MetricQueryServiceTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testCreateDump() throws Exception { ActorSystem s = AkkaUtils.createLocalActorSystem(new Configuration()); try { ActorRef serviceActor = MetricQueryService.startMetricQueryService(s, null, Long.MAX_VALUE); TestActorRef testActorRef = TestActorRef.create(s, Props.create(TestActor.class)); TestActor testActor = (TestActor) testActorRef.underlyingActor(); 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(); MetricQueryService.notifyOfAddedMetric(serviceActor, c, "counter", tm); MetricQueryService.notifyOfAddedMetric(serviceActor, g, "gauge", tm); MetricQueryService.notifyOfAddedMetric(serviceActor, h, "histogram", tm); MetricQueryService.notifyOfAddedMetric(serviceActor, m, "meter", tm); serviceActor.tell(MetricQueryService.getCreateDump(), testActorRef); testActor.waitForResult(); MetricDumpSerialization.MetricSerializationResult dump = testActor.getSerializationResult(); assertTrue(dump.serializedCounters.length > 0); assertTrue(dump.serializedGauges.length > 0); assertTrue(dump.serializedHistograms.length > 0); assertTrue(dump.serializedMeters.length > 0); MetricQueryService.notifyOfRemovedMetric(serviceActor, c); MetricQueryService.notifyOfRemovedMetric(serviceActor, g); MetricQueryService.notifyOfRemovedMetric(serviceActor, h); MetricQueryService.notifyOfRemovedMetric(serviceActor, m); serviceActor.tell(MetricQueryService.getCreateDump(), testActorRef); testActor.waitForResult(); MetricDumpSerialization.MetricSerializationResult emptyDump = testActor.getSerializationResult(); assertEquals(0, emptyDump.serializedCounters.length); assertEquals(0, emptyDump.serializedGauges.length); assertEquals(0, emptyDump.serializedHistograms.length); assertEquals(0, emptyDump.serializedMeters.length); } finally { s.terminate(); } }
Example #20
Source File: MetricQueryServiceTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testHandleOversizedMetricMessage() throws Exception { final long sizeLimit = 200L; MetricQueryService queryService = MetricQueryService.createMetricQueryService(rpcService, ResourceID.generate(), sizeLimit); queryService.start(); final TaskManagerMetricGroup tm = UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(); final String gaugeValue = "Hello"; final long requiredGaugesToExceedLimit = sizeLimit / gaugeValue.length() + 1; List<Tuple2<String, Gauge<String>>> gauges = LongStream.range(0, requiredGaugesToExceedLimit) .mapToObj(x -> Tuple2.of("gauge" + x, (Gauge<String>) () -> "Hello" + x)) .collect(Collectors.toList()); gauges.forEach(gauge -> queryService.addMetric(gauge.f0, gauge.f1, tm)); queryService.addMetric("counter", new SimpleCounter(), tm); queryService.addMetric("histogram", new TestHistogram(), tm); queryService.addMetric("meter", new TestMeter(), tm); MetricDumpSerialization.MetricSerializationResult dump = queryService.queryMetrics(TIMEOUT).get(); assertTrue(dump.serializedCounters.length > 0); assertEquals(1, dump.numCounters); assertTrue(dump.serializedMeters.length > 0); assertEquals(1, dump.numMeters); // gauges exceeded the size limit and will be excluded assertEquals(0, dump.serializedGauges.length); assertEquals(0, dump.numGauges); assertTrue(dump.serializedHistograms.length > 0); assertEquals(1, dump.numHistograms); // unregister all but one gauge to ensure gauges are reported again if the remaining fit for (int x = 1; x < gauges.size(); x++) { queryService.removeMetric(gauges.get(x).f1); } MetricDumpSerialization.MetricSerializationResult recoveredDump = queryService.queryMetrics(TIMEOUT).get(); assertTrue(recoveredDump.serializedCounters.length > 0); assertEquals(1, recoveredDump.numCounters); assertTrue(recoveredDump.serializedMeters.length > 0); assertEquals(1, recoveredDump.numMeters); assertTrue(recoveredDump.serializedGauges.length > 0); assertEquals(1, recoveredDump.numGauges); assertTrue(recoveredDump.serializedHistograms.length > 0); assertEquals(1, recoveredDump.numHistograms); }
Example #21
Source File: MetricFetcherTest.java From flink with Apache License 2.0 | 4 votes |
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; }
Example #22
Source File: MetricFetcherTest.java From flink with Apache License 2.0 | 4 votes |
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; }
Example #23
Source File: MetricQueryServiceTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testHandleOversizedMetricMessage() throws Exception { final long sizeLimit = 200L; MetricQueryService queryService = MetricQueryService.createMetricQueryService(rpcService, ResourceID.generate(), sizeLimit); queryService.start(); final TaskManagerMetricGroup tm = UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(); final String gaugeValue = "Hello"; final long requiredGaugesToExceedLimit = sizeLimit / gaugeValue.length() + 1; List<Tuple2<String, Gauge<String>>> gauges = LongStream.range(0, requiredGaugesToExceedLimit) .mapToObj(x -> Tuple2.of("gauge" + x, (Gauge<String>) () -> "Hello" + x)) .collect(Collectors.toList()); gauges.forEach(gauge -> queryService.addMetric(gauge.f0, gauge.f1, tm)); queryService.addMetric("counter", new SimpleCounter(), tm); queryService.addMetric("histogram", new TestHistogram(), tm); queryService.addMetric("meter", new TestMeter(), tm); MetricDumpSerialization.MetricSerializationResult dump = queryService.queryMetrics(TIMEOUT).get(); assertTrue(dump.serializedCounters.length > 0); assertEquals(1, dump.numCounters); assertTrue(dump.serializedMeters.length > 0); assertEquals(1, dump.numMeters); // gauges exceeded the size limit and will be excluded assertEquals(0, dump.serializedGauges.length); assertEquals(0, dump.numGauges); assertTrue(dump.serializedHistograms.length > 0); assertEquals(1, dump.numHistograms); // unregister all but one gauge to ensure gauges are reported again if the remaining fit for (int x = 1; x < gauges.size(); x++) { queryService.removeMetric(gauges.get(x).f1); } MetricDumpSerialization.MetricSerializationResult recoveredDump = queryService.queryMetrics(TIMEOUT).get(); assertTrue(recoveredDump.serializedCounters.length > 0); assertEquals(1, recoveredDump.numCounters); assertTrue(recoveredDump.serializedMeters.length > 0); assertEquals(1, recoveredDump.numMeters); assertTrue(recoveredDump.serializedGauges.length > 0); assertEquals(1, recoveredDump.numGauges); assertTrue(recoveredDump.serializedHistograms.length > 0); assertEquals(1, recoveredDump.numHistograms); }
Example #24
Source File: MetricFetcherTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
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; }
Example #25
Source File: MetricQueryServiceTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testHandleOversizedMetricMessage() throws Exception { ActorSystem s = AkkaUtils.createLocalActorSystem(new Configuration()); try { final long sizeLimit = 200L; ActorRef serviceActor = MetricQueryService.startMetricQueryService(s, null, sizeLimit); TestActorRef testActorRef = TestActorRef.create(s, Props.create(TestActor.class)); TestActor testActor = (TestActor) testActorRef.underlyingActor(); final TaskManagerMetricGroup tm = UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(); final String gaugeValue = "Hello"; final long requiredGaugesToExceedLimit = sizeLimit / gaugeValue.length() + 1; List<Tuple2<String, Gauge<String>>> gauges = LongStream.range(0, requiredGaugesToExceedLimit) .mapToObj(x -> Tuple2.of("gauge" + x, (Gauge<String>) () -> "Hello" + x)) .collect(Collectors.toList()); gauges.forEach(gauge -> MetricQueryService.notifyOfAddedMetric(serviceActor, gauge.f1, gauge.f0, tm)); MetricQueryService.notifyOfAddedMetric(serviceActor, new SimpleCounter(), "counter", tm); MetricQueryService.notifyOfAddedMetric(serviceActor, new TestHistogram(), "histogram", tm); MetricQueryService.notifyOfAddedMetric(serviceActor, new TestMeter(), "meter", tm); serviceActor.tell(MetricQueryService.getCreateDump(), testActorRef); testActor.waitForResult(); MetricDumpSerialization.MetricSerializationResult dump = testActor.getSerializationResult(); assertTrue(dump.serializedCounters.length > 0); assertEquals(1, dump.numCounters); assertTrue(dump.serializedMeters.length > 0); assertEquals(1, dump.numMeters); // gauges exceeded the size limit and will be excluded assertEquals(0, dump.serializedGauges.length); assertEquals(0, dump.numGauges); assertTrue(dump.serializedHistograms.length > 0); assertEquals(1, dump.numHistograms); // unregister all but one gauge to ensure gauges are reported again if the remaining fit for (int x = 1; x < gauges.size(); x++) { MetricQueryService.notifyOfRemovedMetric(serviceActor, gauges.get(x).f1); } serviceActor.tell(MetricQueryService.getCreateDump(), testActorRef); testActor.waitForResult(); MetricDumpSerialization.MetricSerializationResult recoveredDump = testActor.getSerializationResult(); assertTrue(recoveredDump.serializedCounters.length > 0); assertEquals(1, recoveredDump.numCounters); assertTrue(recoveredDump.serializedMeters.length > 0); assertEquals(1, recoveredDump.numMeters); assertTrue(recoveredDump.serializedGauges.length > 0); assertEquals(1, recoveredDump.numGauges); assertTrue(recoveredDump.serializedHistograms.length > 0); assertEquals(1, recoveredDump.numHistograms); } finally { s.terminate(); } }