org.apache.flink.metrics.SimpleCounter Java Examples

The following examples show how to use org.apache.flink.metrics.SimpleCounter. 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: PrometheusReporterTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void metricIsRemovedWhenCollectorIsNotUnregisteredYet() throws UnirestException {
	TaskManagerMetricGroup tmMetricGroup = new TaskManagerMetricGroup(registry, HOST_NAME, TASK_MANAGER);

	String metricName = "metric";

	Counter metric1 = new SimpleCounter();
	FrontMetricGroup<TaskManagerJobMetricGroup> metricGroup1 = new FrontMetricGroup<>(0, new TaskManagerJobMetricGroup(registry, tmMetricGroup, JobID.generate(), "job_1"));
	reporter.notifyOfAddedMetric(metric1, metricName, metricGroup1);

	Counter metric2 = new SimpleCounter();
	FrontMetricGroup<TaskManagerJobMetricGroup> metricGroup2 = new FrontMetricGroup<>(0, new TaskManagerJobMetricGroup(registry, tmMetricGroup, JobID.generate(), "job_2"));
	reporter.notifyOfAddedMetric(metric2, metricName, metricGroup2);

	reporter.notifyOfRemovedMetric(metric1, metricName, metricGroup1);

	String response = pollMetrics(reporter.getPort()).getBody();

	assertThat(response, not(containsString("job_1")));
}
 
Example #2
Source File: Slf4jReporterTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddCounter() throws Exception {
	String counterName = "simpleCounter";

	SimpleCounter counter = new SimpleCounter();
	taskMetricGroup.counter(counterName, counter);

	assertTrue(reporter.getCounters().containsKey(counter));

	String expectedCounterReport = reporter.filterCharacters(HOST_NAME) + delimiter
		+ reporter.filterCharacters(TASK_MANAGER_ID) + delimiter + reporter.filterCharacters(JOB_NAME) + delimiter
		+ reporter.filterCharacters(counterName) + ": 0";

	reporter.report();
	TestUtils.checkForLogString(expectedCounterReport);
}
 
Example #3
Source File: PrometheusReporterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void metricIsRemovedWhenCollectorIsNotUnregisteredYet() throws UnirestException {
	TaskManagerMetricGroup tmMetricGroup = new TaskManagerMetricGroup(registry, HOST_NAME, TASK_MANAGER);

	String metricName = "metric";

	Counter metric1 = new SimpleCounter();
	FrontMetricGroup<TaskManagerJobMetricGroup> metricGroup1 = new FrontMetricGroup<>(
		createReporterScopedSettings(),
		new TaskManagerJobMetricGroup(registry, tmMetricGroup, JobID.generate(), "job_1"));
	reporter.notifyOfAddedMetric(metric1, metricName, metricGroup1);

	Counter metric2 = new SimpleCounter();
	FrontMetricGroup<TaskManagerJobMetricGroup> metricGroup2 = new FrontMetricGroup<>(
		createReporterScopedSettings(),
		new TaskManagerJobMetricGroup(registry, tmMetricGroup, JobID.generate(), "job_2"));
	reporter.notifyOfAddedMetric(metric2, metricName, metricGroup2);

	reporter.notifyOfRemovedMetric(metric1, metricName, metricGroup1);

	String response = pollMetrics(reporter.getPort()).getBody();

	assertThat(response, not(containsString("job_1")));
}
 
Example #4
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testMetricQueryServiceSetup() throws Exception {
	MetricRegistryImpl metricRegistry = new MetricRegistryImpl(MetricRegistryConfiguration.defaultMetricRegistryConfiguration());

	Assert.assertNull(metricRegistry.getMetricQueryServiceGatewayRpcAddress());

	metricRegistry.startQueryService(new TestingRpcService(), new ResourceID("mqs"));

	MetricQueryServiceGateway metricQueryServiceGateway = metricRegistry.getMetricQueryServiceGateway();
	Assert.assertNotNull(metricQueryServiceGateway);

	metricRegistry.register(new SimpleCounter(), "counter", UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup());

	boolean metricsSuccessfullyQueried = false;
	for (int x = 0; x < 10; x++) {
		MetricDumpSerialization.MetricSerializationResult metricSerializationResult = metricQueryServiceGateway.queryMetrics(Time.seconds(5))
			.get(5, TimeUnit.SECONDS);

		if (metricSerializationResult.numCounters == 1) {
			metricsSuccessfullyQueried = true;
		} else {
			Thread.sleep(50);
		}
	}
	Assert.assertTrue("metrics query did not return expected result", metricsSuccessfullyQueried);
}
 
Example #5
Source File: PrometheusReporterTaskScopeTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public 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),
		equalTo(1.));
	assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_counter", LABEL_NAMES, labelValues2),
		equalTo(2.));

	taskMetricGroup2.close();
	assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_counter", LABEL_NAMES, labelValues1),
		equalTo(1.));

	taskMetricGroup1.close();
	assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_counter", LABEL_NAMES, labelValues1),
		nullValue());
}
 
Example #6
Source File: PrometheusReporterTaskScopeTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public 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),
		equalTo(1.));
	assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_counter", LABEL_NAMES, labelValues2),
		equalTo(2.));

	taskMetricGroup2.close();
	assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_counter", LABEL_NAMES, labelValues1),
		equalTo(1.));

	taskMetricGroup1.close();
	assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_counter", LABEL_NAMES, labelValues1),
		nullValue());
}
 
Example #7
Source File: TaskIOMetricGroup.java    From flink with Apache License 2.0 6 votes vote down vote up
public TaskIOMetricGroup(TaskMetricGroup parent) {
	super(parent);

	this.numBytesIn = counter(MetricNames.IO_NUM_BYTES_IN);
	this.numBytesOut = counter(MetricNames.IO_NUM_BYTES_OUT);
	this.numBytesInRate = meter(MetricNames.IO_NUM_BYTES_IN_RATE, new MeterView(numBytesIn));
	this.numBytesOutRate = meter(MetricNames.IO_NUM_BYTES_OUT_RATE, new MeterView(numBytesOut));

	this.numRecordsIn = counter(MetricNames.IO_NUM_RECORDS_IN, new SumCounter());
	this.numRecordsOut = counter(MetricNames.IO_NUM_RECORDS_OUT, new SumCounter());
	this.numRecordsInRate = meter(MetricNames.IO_NUM_RECORDS_IN_RATE, new MeterView(numRecordsIn));
	this.numRecordsOutRate = meter(MetricNames.IO_NUM_RECORDS_OUT_RATE, new MeterView(numRecordsOut));

	this.numBuffersOut = counter(MetricNames.IO_NUM_BUFFERS_OUT);
	this.numBuffersOutRate = meter(MetricNames.IO_NUM_BUFFERS_OUT_RATE, new MeterView(numBuffersOut));

	this.idleTimePerSecond = meter(MetricNames.TASK_IDLE_TIME, new MeterView(new SimpleCounter()));
}
 
Example #8
Source File: FlinkMetricContainerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testMeterMonitoringInfoUpdate() {
	MeterView userMeter = new MeterView(new SimpleCounter());
	when(metricGroup.meter(eq("myMeter"), any(Meter.class))).thenReturn(userMeter);
	String namespace = "[\"key\", \"value\", \"MetricGroupType.key\", \"MetricGroupType.value\", \"60\"]";

	MonitoringInfo userMonitoringInfo =
		new SimpleMonitoringInfoBuilder()
			.setUrn(MonitoringInfoConstants.Urns.USER_COUNTER)
			.setLabel(MonitoringInfoConstants.Labels.NAMESPACE, namespace)
			.setLabel(MonitoringInfoConstants.Labels.NAME, "myMeter")
			.setLabel(MonitoringInfoConstants.Labels.PTRANSFORM, "anyPTransform")
			.setInt64Value(111)
			.build();
	assertThat(userMeter.getCount(), is(0L));
	assertThat(userMeter.getRate(), is(0.0));
	container.updateMetrics(
		"step", ImmutableList.of(userMonitoringInfo));
	userMeter.update();
	assertThat(userMeter.getCount(), is(111L));
	assertThat(userMeter.getRate(), is(1.85)); // 111 div 60 = 1.85
}
 
Example #9
Source File: Slf4jReporterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddCounter() throws Exception {
	String counterName = "simpleCounter";

	SimpleCounter counter = new SimpleCounter();
	taskMetricGroup.counter(counterName, counter);

	assertTrue(reporter.getCounters().containsKey(counter));

	String expectedCounterReport = reporter.filterCharacters(HOST_NAME) + delimiter
		+ reporter.filterCharacters(TASK_MANAGER_ID) + delimiter + reporter.filterCharacters(JOB_NAME) + delimiter
		+ reporter.filterCharacters(counterName) + ": 0";

	reporter.report();
	TestUtils.checkForLogString(expectedCounterReport);
}
 
Example #10
Source File: FlinkMetricContainerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCounterMonitoringInfoUpdate() {
	SimpleCounter userCounter = new SimpleCounter();
	when(metricGroup.counter("myCounter")).thenReturn(userCounter);

	MonitoringInfo userMonitoringInfo =
		new SimpleMonitoringInfoBuilder()
			.setUrn(MonitoringInfoConstants.Urns.USER_COUNTER)
			.setLabel(MonitoringInfoConstants.Labels.NAMESPACE, DEFAULT_NAMESPACE)
			.setLabel(MonitoringInfoConstants.Labels.NAME, "myCounter")
			.setLabel(MonitoringInfoConstants.Labels.PTRANSFORM, "anyPTransform")
			.setInt64Value(111)
			.build();

	assertThat(userCounter.getCount(), is(0L));
	container.updateMetrics(
		"step", ImmutableList.of(userMonitoringInfo));
	assertThat(userCounter.getCount(), is(111L));
}
 
Example #11
Source File: PrometheusReporterTaskScopeTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public 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),
		equalTo(1.));
	assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_counter", LABEL_NAMES, labelValues2),
		equalTo(2.));

	taskMetricGroup2.close();
	assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_counter", LABEL_NAMES, labelValues1),
		equalTo(1.));

	taskMetricGroup1.close();
	assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_counter", LABEL_NAMES, labelValues1),
		nullValue());
}
 
Example #12
Source File: Slf4jReporterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddCounter() throws Exception {
	String counterName = "simpleCounter";

	SimpleCounter counter = new SimpleCounter();
	taskMetricGroup.counter(counterName, counter);

	assertTrue(reporter.getCounters().containsKey(counter));

	String expectedCounterReport = reporter.filterCharacters(HOST_NAME) + delimiter
		+ reporter.filterCharacters(TASK_MANAGER_ID) + delimiter + reporter.filterCharacters(JOB_NAME) + delimiter
		+ reporter.filterCharacters(counterName) + ": 0";

	reporter.report();
	assertThat(
		testLoggerResource.getMessages(),
		hasItem(containsString(expectedCounterReport)));
}
 
Example #13
Source File: PrometheusReporterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void metricIsRemovedWhenCollectorIsNotUnregisteredYet() throws UnirestException {
	TaskManagerMetricGroup tmMetricGroup = new TaskManagerMetricGroup(registry, HOST_NAME, TASK_MANAGER);

	String metricName = "metric";

	Counter metric1 = new SimpleCounter();
	FrontMetricGroup<TaskManagerJobMetricGroup> metricGroup1 = new FrontMetricGroup<>(0, new TaskManagerJobMetricGroup(registry, tmMetricGroup, JobID.generate(), "job_1"));
	reporter.notifyOfAddedMetric(metric1, metricName, metricGroup1);

	Counter metric2 = new SimpleCounter();
	FrontMetricGroup<TaskManagerJobMetricGroup> metricGroup2 = new FrontMetricGroup<>(0, new TaskManagerJobMetricGroup(registry, tmMetricGroup, JobID.generate(), "job_2"));
	reporter.notifyOfAddedMetric(metric2, metricName, metricGroup2);

	reporter.notifyOfRemovedMetric(metric1, metricName, metricGroup1);

	String response = pollMetrics(reporter.getPort()).getBody();

	assertThat(response, not(containsString("job_1")));
}
 
Example #14
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testExceptionIsolation() throws Exception {
	MetricRegistryImpl registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.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();
}
 
Example #15
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testMetricQueryServiceSetup() throws Exception {
	MetricRegistryImpl metricRegistry = new MetricRegistryImpl(MetricRegistryConfiguration.defaultMetricRegistryConfiguration());

	Assert.assertNull(metricRegistry.getMetricQueryServiceGatewayRpcAddress());

	metricRegistry.startQueryService(new TestingRpcService(), new ResourceID("mqs"));

	MetricQueryServiceGateway metricQueryServiceGateway = metricRegistry.getMetricQueryServiceGateway();
	Assert.assertNotNull(metricQueryServiceGateway);

	metricRegistry.register(new SimpleCounter(), "counter", UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup());

	boolean metricsSuccessfullyQueried = false;
	for (int x = 0; x < 10; x++) {
		MetricDumpSerialization.MetricSerializationResult metricSerializationResult = metricQueryServiceGateway.queryMetrics(Time.seconds(5))
			.get(5, TimeUnit.SECONDS);

		if (metricSerializationResult.numCounters == 1) {
			metricsSuccessfullyQueried = true;
		} else {
			Thread.sleep(50);
		}
	}
	Assert.assertTrue("metrics query did not return expected result", metricsSuccessfullyQueried);
}
 
Example #16
Source File: PrometheusReporterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * {@link io.prometheus.client.Counter} may not decrease, so report {@link Counter} as {@link io.prometheus.client.Gauge}.
 *
 * @throws UnirestException Might be thrown on HTTP problems.
 */
@Test
public void counterIsReportedAsPrometheusGauge() throws UnirestException {
	Counter testCounter = new SimpleCounter();
	testCounter.inc(7);

	assertThatGaugeIsExported(testCounter, "testCounter", "7.0");
}
 
Example #17
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 #18
Source File: TaskIOMetricGroupTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testTaskIOMetricGroup() {
	TaskMetricGroup task = UnregisteredMetricGroups.createUnregisteredTaskMetricGroup();
	TaskIOMetricGroup taskIO = task.getIOMetricGroup();

	// test counter forwarding
	assertNotNull(taskIO.getNumRecordsInCounter());
	assertNotNull(taskIO.getNumRecordsOutCounter());

	Counter c1 = new SimpleCounter();
	c1.inc(32L);
	Counter c2 = new SimpleCounter();
	c2.inc(64L);

	taskIO.reuseRecordsInputCounter(c1);
	taskIO.reuseRecordsOutputCounter(c2);
	assertEquals(32L, taskIO.getNumRecordsInCounter().getCount());
	assertEquals(64L, taskIO.getNumRecordsOutCounter().getCount());

	// test IOMetrics instantiation
	taskIO.getNumBytesInCounter().inc(100L);
	taskIO.getNumBytesOutCounter().inc(250L);
	taskIO.getNumBuffersOutCounter().inc(3L);

	IOMetrics io = taskIO.createSnapshot();
	assertEquals(32L, io.getNumRecordsIn());
	assertEquals(64L, io.getNumRecordsOut());
	assertEquals(100L, io.getNumBytesIn());
	assertEquals(250L, io.getNumBytesOut());
	assertEquals(3L, taskIO.getNumBuffersOutCounter().getCount());
}
 
Example #19
Source File: StreamTask.java    From flink with Apache License 2.0 5 votes vote down vote up
protected Counter setupNumRecordsInCounter(StreamOperator streamOperator) {
	try {
		return ((OperatorMetricGroup) streamOperator.getMetricGroup()).getIOMetricGroup().getNumRecordsInCounter();
	} catch (Exception e) {
		LOG.warn("An exception occurred during the metrics setup.", e);
		return new SimpleCounter();
	}
}
 
Example #20
Source File: PrometheusReporterTaskScopeTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public 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),
		equalTo(1.));
	assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_counter", LABEL_NAMES, labelValues2),
		equalTo(2.));
}
 
Example #21
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 #22
Source File: MetricMapperTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testMapCounter() {
	Counter counter = new SimpleCounter();
	counter.inc(42L);

	verifyPoint(
		MetricMapper.map(INFO, TIMESTAMP, counter),
		"count=42");
}
 
Example #23
Source File: SequenceReader.java    From alibaba-flink-connectors with Apache License 2.0 5 votes vote down vote up
public SequenceReader(AbstractParallelSourceBase<T, ?> source, InputSplitProvider provider, Configuration config) {
	this.sourceFunction = source;
	this.inputSplitProvider = provider;
	this.config = config;
	RuntimeContext context = source.getRuntimeContext();
	outputCounter = context.getMetricGroup().counter(MetricUtils.METRICS_TPS + "_counter", new SimpleCounter());
	tpsMetric = context.getMetricGroup().meter(MetricUtils.METRICS_TPS, new MeterView(outputCounter, 60));
}
 
Example #24
Source File: StreamNetworkBenchmarkEnvironment.java    From flink with Apache License 2.0 5 votes vote down vote up
private InputGate createInputGateWithMetrics(
	SingleInputGateFactory gateFactory,
	InputGateDeploymentDescriptor gateDescriptor,
	int channelIndex) {

	final SingleInputGate singleGate = gateFactory.create(
		"receiving task[" + channelIndex + "]",
		gateDescriptor,
		SingleInputGateBuilder.NO_OP_PRODUCER_CHECKER,
		InputChannelTestUtils.newUnregisteredInputChannelMetrics());

	return new InputGateWithMetrics(singleGate, new SimpleCounter());
}
 
Example #25
Source File: PrometheusReporterTaskScopeTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public 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),
		equalTo(1.));
	assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_counter", LABEL_NAMES, labelValues2),
		equalTo(2.));
}
 
Example #26
Source File: PrometheusReporterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * {@link io.prometheus.client.Counter} may not decrease, so report {@link Counter} as {@link io.prometheus.client.Gauge}.
 *
 * @throws UnirestException Might be thrown on HTTP problems.
 */
@Test
public void counterIsReportedAsPrometheusGauge() throws UnirestException {
	Counter testCounter = new SimpleCounter();
	testCounter.inc(7);

	assertThatGaugeIsExported(testCounter, "testCounter", "7.0");
}
 
Example #27
Source File: PrometheusReporterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void registeringSameMetricTwiceDoesNotThrowException() {
	Counter counter = new SimpleCounter();
	counter.inc();
	String counterName = "testCounter";

	reporter.notifyOfAddedMetric(counter, counterName, metricGroup);
	reporter.notifyOfAddedMetric(counter, counterName, metricGroup);
}
 
Example #28
Source File: MetricMapperTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testMapCounter() {
	Counter counter = new SimpleCounter();
	counter.inc(42L);

	verifyPoint(
		MetricMapper.map(INFO, TIMESTAMP, counter),
		"count=42");
}
 
Example #29
Source File: FeedbackSinkOperator.java    From stateful-functions with Apache License 2.0 5 votes vote down vote up
@Override
public void open() throws Exception {
  super.open();
  final int indexOfThisSubtask = getRuntimeContext().getIndexOfThisSubtask();
  final SubtaskFeedbackKey<V> key = this.key.withSubTaskIndex(indexOfThisSubtask);

  FeedbackChannelBroker broker = FeedbackChannelBroker.get();
  this.channel = broker.getChannel(key);

  // metrics
  MetricGroup metrics = getRuntimeContext().getMetricGroup();
  SimpleCounter produced = metrics.counter("produced", new SimpleCounter());
  metrics.meter("producedRate", new MeterView(produced, 60));
  this.totalProduced = produced;
}
 
Example #30
Source File: FeedbackSinkOperator.java    From flink-statefun with Apache License 2.0 5 votes vote down vote up
@Override
public void open() throws Exception {
  super.open();
  final int indexOfThisSubtask = getRuntimeContext().getIndexOfThisSubtask();
  final SubtaskFeedbackKey<V> key = this.key.withSubTaskIndex(indexOfThisSubtask);

  FeedbackChannelBroker broker = FeedbackChannelBroker.get();
  this.channel = broker.getChannel(key);

  // metrics
  MetricGroup metrics = getRuntimeContext().getMetricGroup();
  SimpleCounter produced = metrics.counter("produced", new SimpleCounter());
  metrics.meter("producedRate", new MeterView(produced, 60));
  this.totalProduced = produced;
}