org.apache.flink.metrics.util.TestMeter Java Examples

The following examples show how to use org.apache.flink.metrics.util.TestMeter. 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: PrometheusReporterTaskScopeTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void metersCanBeAddedSeveralTimesIfTheyDifferInLabels() throws UnirestException {
	Meter meter = new TestMeter();

	taskMetricGroup1.meter("my_meter", meter);
	taskMetricGroup2.meter("my_meter", meter);

	assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_meter", LABEL_NAMES, labelValues1),
		equalTo(5.));
	assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_meter", LABEL_NAMES, labelValues2),
		equalTo(5.));
}
 
Example #2
Source File: MetricMapperTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testMapMeter() {
	Meter meter = new TestMeter();

	verifyPoint(
		MetricMapper.map(INFO, TIMESTAMP, meter),
		"count=100",
		"rate=5.0");
}
 
Example #3
Source File: PrometheusReporterTaskScopeTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void metersCanBeAddedSeveralTimesIfTheyDifferInLabels() throws UnirestException {
	Meter meter = new TestMeter();

	taskMetricGroup1.meter("my_meter", meter);
	taskMetricGroup2.meter("my_meter", meter);

	assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_meter", LABEL_NAMES, labelValues1),
		equalTo(5.));
	assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_meter", LABEL_NAMES, labelValues2),
		equalTo(5.));
}
 
Example #4
Source File: StatsDReporterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testStatsDMetersReportingOfNegativeValues() throws Exception {
	Set<String> expectedLines = new HashSet<>();
	expectedLines.add("metric.rate:0|g");
	expectedLines.add("metric.rate:-5.3|g");
	expectedLines.add("metric.count:0|g");
	expectedLines.add("metric.count:-50|g");

	testMetricAndAssert(new TestMeter(-50, -5.3), "metric", expectedLines);
}
 
Example #5
Source File: StatsDReporterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that meters are properly reported via the StatsD reporter.
 */
@Test
public void testStatsDMetersReporting() throws Exception {
	Set<String> expectedLines = new HashSet<>(4);
	expectedLines.add("metric.rate:5.0|g");
	expectedLines.add("metric.count:100|g");

	testMetricAndAssert(new TestMeter(), "metric", expectedLines);
}
 
Example #6
Source File: FlinkMeterWrapperTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testWrapper() {
	Meter meter = new TestMeter();

	FlinkMeterWrapper wrapper = new FlinkMeterWrapper(meter);
	assertEquals(0, wrapper.getMeanRate(), DELTA);
	assertEquals(5, wrapper.getOneMinuteRate(), DELTA);
	assertEquals(0, wrapper.getFiveMinuteRate(), DELTA);
	assertEquals(0, wrapper.getFifteenMinuteRate(), DELTA);
	assertEquals(100L, wrapper.getCount());
}
 
Example #7
Source File: MetricQueryServiceTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@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 #8
Source File: MetricMapperTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testMapMeter() {
	Meter meter = new TestMeter();

	verifyPoint(
		MetricMapper.map(INFO, TIMESTAMP, meter),
		"count=100",
		"rate=5.0");
}
 
Example #9
Source File: StatsDReporterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testStatsDMetersReportingOfNegativeValues() throws Exception {
	Set<String> expectedLines = new HashSet<>();
	expectedLines.add("metric.rate:0|g");
	expectedLines.add("metric.rate:-5.3|g");
	expectedLines.add("metric.count:0|g");
	expectedLines.add("metric.count:-50|g");

	testMetricAndAssert(new TestMeter(-50, -5.3), "metric", expectedLines);
}
 
Example #10
Source File: StatsDReporterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that meters are properly reported via the StatsD reporter.
 */
@Test
public void testStatsDMetersReporting() throws Exception {
	Set<String> expectedLines = new HashSet<>(4);
	expectedLines.add("metric.rate:5.0|g");
	expectedLines.add("metric.count:100|g");

	testMetricAndAssert(new TestMeter(), "metric", expectedLines);
}
 
Example #11
Source File: FlinkMeterWrapperTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testWrapper() {
	Meter meter = new TestMeter();

	FlinkMeterWrapper wrapper = new FlinkMeterWrapper(meter);
	assertEquals(0, wrapper.getMeanRate(), DELTA);
	assertEquals(5, wrapper.getOneMinuteRate(), DELTA);
	assertEquals(0, wrapper.getFiveMinuteRate(), DELTA);
	assertEquals(0, wrapper.getFifteenMinuteRate(), DELTA);
	assertEquals(100L, wrapper.getCount());
}
 
Example #12
Source File: MetricQueryServiceTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@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 #13
Source File: MetricMapperTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testMapMeter() {
	Meter meter = new TestMeter();

	verifyPoint(
		MetricMapper.map(INFO, TIMESTAMP, meter),
		"count=100",
		"rate=5.0");
}
 
Example #14
Source File: PrometheusReporterTaskScopeTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void metersCanBeAddedSeveralTimesIfTheyDifferInLabels() throws UnirestException {
	Meter meter = new TestMeter();

	taskMetricGroup1.meter("my_meter", meter);
	taskMetricGroup2.meter("my_meter", meter);

	assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_meter", LABEL_NAMES, labelValues1),
		equalTo(5.));
	assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_meter", LABEL_NAMES, labelValues2),
		equalTo(5.));
}
 
Example #15
Source File: FlinkMeterWrapperTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testWrapper() {
	Meter meter = new TestMeter();

	FlinkMeterWrapper wrapper = new FlinkMeterWrapper(meter);
	assertEquals(0, wrapper.getMeanRate(), DELTA);
	assertEquals(5, wrapper.getOneMinuteRate(), DELTA);
	assertEquals(0, wrapper.getFiveMinuteRate(), DELTA);
	assertEquals(0, wrapper.getFifteenMinuteRate(), DELTA);
	assertEquals(100L, wrapper.getCount());
}
 
Example #16
Source File: MetricQueryServiceTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@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 #17
Source File: PrometheusReporterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void meterRateIsReportedAsPrometheusGauge() throws UnirestException {
	Meter testMeter = new TestMeter();

	assertThatGaugeIsExported(testMeter, "testMeter", "5.0");
}
 
Example #18
Source File: MetricQueryServiceTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@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 #19
Source File: MetricQueryServiceTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@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 #20
Source File: PrometheusReporterTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void meterRateIsReportedAsPrometheusGauge() throws UnirestException {
	Meter testMeter = new TestMeter();

	assertThatGaugeIsExported(testMeter, "testMeter", "5.0");
}
 
Example #21
Source File: PrometheusReporterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void meterRateIsReportedAsPrometheusGauge() throws UnirestException {
	Meter testMeter = new TestMeter();

	assertThatGaugeIsExported(testMeter, "testMeter", "5.0");
}
 
Example #22
Source File: MetricQueryServiceTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@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();
	}
}