Java Code Examples for org.apache.flink.runtime.metrics.groups.TaskMetricGroup#counter()

The following examples show how to use org.apache.flink.runtime.metrics.groups.TaskMetricGroup#counter() . 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: ScheduledDropwizardReporterTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that the registered metrics' names don't contain invalid characters.
 */
@Test
public void testAddingMetrics() throws Exception {
	Configuration configuration = new Configuration();
	String taskName = "test\"Ta\"..sk";
	String jobName = "testJ\"ob:-!ax..?";
	String hostname = "loc<>al\"::host\".:";
	String taskManagerId = "tas:kMana::ger";
	String counterName = "testCounter";

	configuration.setString(
			ConfigConstants.METRICS_REPORTER_PREFIX + "test." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX,
			"org.apache.flink.dropwizard.ScheduledDropwizardReporterTest$TestingScheduledDropwizardReporter");

	configuration.setString(MetricOptions.SCOPE_NAMING_TASK, "<host>.<tm_id>.<job_name>");
	configuration.setString(MetricOptions.SCOPE_DELIMITER, "_");

	MetricRegistryConfiguration metricRegistryConfiguration = MetricRegistryConfiguration.fromConfiguration(configuration);

	MetricRegistryImpl metricRegistry = new MetricRegistryImpl(metricRegistryConfiguration);

	char delimiter = metricRegistry.getDelimiter();

	TaskManagerMetricGroup tmMetricGroup = new TaskManagerMetricGroup(metricRegistry, hostname, taskManagerId);
	TaskManagerJobMetricGroup tmJobMetricGroup = new TaskManagerJobMetricGroup(metricRegistry, tmMetricGroup, new JobID(), jobName);
	TaskMetricGroup taskMetricGroup = new TaskMetricGroup(metricRegistry, tmJobMetricGroup, new JobVertexID(), new AbstractID(), taskName, 0, 0);

	SimpleCounter myCounter = new SimpleCounter();
	com.codahale.metrics.Meter dropwizardMeter = new com.codahale.metrics.Meter();
	DropwizardMeterWrapper meterWrapper = new DropwizardMeterWrapper(dropwizardMeter);

	taskMetricGroup.counter(counterName, myCounter);
	taskMetricGroup.meter("meter", meterWrapper);

	List<MetricReporter> reporters = metricRegistry.getReporters();

	assertTrue(reporters.size() == 1);
	MetricReporter metricReporter = reporters.get(0);

	assertTrue("Reporter should be of type ScheduledDropwizardReporter", metricReporter instanceof ScheduledDropwizardReporter);

	TestingScheduledDropwizardReporter reporter = (TestingScheduledDropwizardReporter) metricReporter;

	Map<Counter, String> counters = reporter.getCounters();
	assertTrue(counters.containsKey(myCounter));

	Map<Meter, String> meters = reporter.getMeters();
	assertTrue(meters.containsKey(meterWrapper));

	String expectedCounterName = reporter.filterCharacters(hostname)
		+ delimiter
		+ reporter.filterCharacters(taskManagerId)
		+ delimiter
		+ reporter.filterCharacters(jobName)
		+ delimiter
		+ reporter.filterCharacters(counterName);

	assertEquals(expectedCounterName, counters.get(myCounter));

	metricRegistry.shutdown().get();
}
 
Example 2
Source File: StatsDReporterTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that the registered metrics' names don't contain invalid characters.
 */
@Test
public void testAddingMetrics() throws Exception {
	Configuration configuration = new Configuration();
	String taskName = "testTask";
	String jobName = "testJob:-!ax..?";
	String hostname = "local::host:";
	String taskManagerId = "tas:kMana::ger";
	String counterName = "testCounter";

	configuration.setString(
			ConfigConstants.METRICS_REPORTER_PREFIX + "test." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX,
			"org.apache.flink.metrics.statsd.StatsDReporterTest$TestingStatsDReporter");

	configuration.setString(MetricOptions.SCOPE_NAMING_TASK, "<host>.<tm_id>.<job_name>");
	configuration.setString(MetricOptions.SCOPE_DELIMITER, "_");

	MetricRegistryImpl metricRegistry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(configuration));

	char delimiter = metricRegistry.getDelimiter();

	TaskManagerMetricGroup tmMetricGroup = new TaskManagerMetricGroup(metricRegistry, hostname, taskManagerId);
	TaskManagerJobMetricGroup tmJobMetricGroup = new TaskManagerJobMetricGroup(metricRegistry, tmMetricGroup, new JobID(), jobName);
	TaskMetricGroup taskMetricGroup = new TaskMetricGroup(metricRegistry, tmJobMetricGroup, new JobVertexID(), new AbstractID(), taskName, 0, 0);

	SimpleCounter myCounter = new SimpleCounter();

	taskMetricGroup.counter(counterName, myCounter);

	List<MetricReporter> reporters = metricRegistry.getReporters();

	assertTrue(reporters.size() == 1);

	MetricReporter metricReporter = reporters.get(0);

	assertTrue("Reporter should be of type StatsDReporter", metricReporter instanceof StatsDReporter);

	TestingStatsDReporter reporter = (TestingStatsDReporter) metricReporter;

	Map<Counter, String> counters = reporter.getCounters();

	assertTrue(counters.containsKey(myCounter));

	String expectedCounterName = reporter.filterCharacters(hostname)
		+ delimiter
		+ reporter.filterCharacters(taskManagerId)
		+ delimiter
		+ reporter.filterCharacters(jobName)
		+ delimiter
		+ reporter.filterCharacters(counterName);

	assertEquals(expectedCounterName, counters.get(myCounter));

	metricRegistry.shutdown().get();
}
 
Example 3
Source File: ScheduledDropwizardReporterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that the registered metrics' names don't contain invalid characters.
 */
@Test
public void testAddingMetrics() throws Exception {
	Configuration configuration = new Configuration();
	String taskName = "test\"Ta\"..sk";
	String jobName = "testJ\"ob:-!ax..?";
	String hostname = "loc<>al\"::host\".:";
	String taskManagerId = "tas:kMana::ger";
	String counterName = "testCounter";

	configuration.setString(MetricOptions.SCOPE_NAMING_TASK, "<host>.<tm_id>.<job_name>");
	configuration.setString(MetricOptions.SCOPE_DELIMITER, "_");

	MetricRegistryConfiguration metricRegistryConfiguration = MetricRegistryConfiguration.fromConfiguration(configuration);

	MetricRegistryImpl metricRegistry = new MetricRegistryImpl(
		metricRegistryConfiguration,
		Collections.singletonList(ReporterSetup.forReporter("test", new TestingScheduledDropwizardReporter())));

	char delimiter = metricRegistry.getDelimiter();

	TaskManagerMetricGroup tmMetricGroup = new TaskManagerMetricGroup(metricRegistry, hostname, taskManagerId);
	TaskManagerJobMetricGroup tmJobMetricGroup = new TaskManagerJobMetricGroup(metricRegistry, tmMetricGroup, new JobID(), jobName);
	TaskMetricGroup taskMetricGroup = new TaskMetricGroup(metricRegistry, tmJobMetricGroup, new JobVertexID(), new AbstractID(), taskName, 0, 0);

	SimpleCounter myCounter = new SimpleCounter();
	com.codahale.metrics.Meter dropwizardMeter = new com.codahale.metrics.Meter();
	DropwizardMeterWrapper meterWrapper = new DropwizardMeterWrapper(dropwizardMeter);

	taskMetricGroup.counter(counterName, myCounter);
	taskMetricGroup.meter("meter", meterWrapper);

	List<MetricReporter> reporters = metricRegistry.getReporters();

	assertTrue(reporters.size() == 1);
	MetricReporter metricReporter = reporters.get(0);

	assertTrue("Reporter should be of type ScheduledDropwizardReporter", metricReporter instanceof ScheduledDropwizardReporter);

	TestingScheduledDropwizardReporter reporter = (TestingScheduledDropwizardReporter) metricReporter;

	Map<Counter, String> counters = reporter.getCounters();
	assertTrue(counters.containsKey(myCounter));

	Map<Meter, String> meters = reporter.getMeters();
	assertTrue(meters.containsKey(meterWrapper));

	String expectedCounterName = reporter.filterCharacters(hostname)
		+ delimiter
		+ reporter.filterCharacters(taskManagerId)
		+ delimiter
		+ reporter.filterCharacters(jobName)
		+ delimiter
		+ reporter.filterCharacters(counterName);

	assertEquals(expectedCounterName, counters.get(myCounter));

	metricRegistry.shutdown().get();
}
 
Example 4
Source File: StatsDReporterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that the registered metrics' names don't contain invalid characters.
 */
@Test
public void testAddingMetrics() throws Exception {
	Configuration configuration = new Configuration();
	String taskName = "testTask";
	String jobName = "testJob:-!ax..?";
	String hostname = "local::host:";
	String taskManagerId = "tas:kMana::ger";
	String counterName = "testCounter";

	configuration.setString(MetricOptions.SCOPE_NAMING_TASK, "<host>.<tm_id>.<job_name>");
	configuration.setString(MetricOptions.SCOPE_DELIMITER, "_");

	MetricRegistryImpl metricRegistry = new MetricRegistryImpl(
		MetricRegistryConfiguration.fromConfiguration(configuration),
		Collections.singletonList(ReporterSetup.forReporter("test", new TestingStatsDReporter())));

	char delimiter = metricRegistry.getDelimiter();

	TaskManagerMetricGroup tmMetricGroup = new TaskManagerMetricGroup(metricRegistry, hostname, taskManagerId);
	TaskManagerJobMetricGroup tmJobMetricGroup = new TaskManagerJobMetricGroup(metricRegistry, tmMetricGroup, new JobID(), jobName);
	TaskMetricGroup taskMetricGroup = new TaskMetricGroup(metricRegistry, tmJobMetricGroup, new JobVertexID(), new AbstractID(), taskName, 0, 0);

	SimpleCounter myCounter = new SimpleCounter();

	taskMetricGroup.counter(counterName, myCounter);

	List<MetricReporter> reporters = metricRegistry.getReporters();

	assertTrue(reporters.size() == 1);

	MetricReporter metricReporter = reporters.get(0);

	assertTrue("Reporter should be of type StatsDReporter", metricReporter instanceof StatsDReporter);

	TestingStatsDReporter reporter = (TestingStatsDReporter) metricReporter;

	Map<Counter, String> counters = reporter.getCounters();

	assertTrue(counters.containsKey(myCounter));

	String expectedCounterName = reporter.filterCharacters(hostname)
		+ delimiter
		+ reporter.filterCharacters(taskManagerId)
		+ delimiter
		+ reporter.filterCharacters(jobName)
		+ delimiter
		+ reporter.filterCharacters(counterName);

	assertEquals(expectedCounterName, counters.get(myCounter));

	metricRegistry.shutdown().get();
}
 
Example 5
Source File: ScheduledDropwizardReporterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that the registered metrics' names don't contain invalid characters.
 */
@Test
public void testAddingMetrics() throws Exception {
	Configuration configuration = new Configuration();
	String taskName = "test\"Ta\"..sk";
	String jobName = "testJ\"ob:-!ax..?";
	String hostname = "loc<>al\"::host\".:";
	String taskManagerId = "tas:kMana::ger";
	String counterName = "testCounter";

	configuration.setString(MetricOptions.SCOPE_NAMING_TASK, "<host>.<tm_id>.<job_name>");
	configuration.setString(MetricOptions.SCOPE_DELIMITER, "_");

	MetricRegistryConfiguration metricRegistryConfiguration = MetricRegistryConfiguration.fromConfiguration(configuration);

	MetricRegistryImpl metricRegistry = new MetricRegistryImpl(
		metricRegistryConfiguration,
		Collections.singletonList(ReporterSetup.forReporter("test", new TestingScheduledDropwizardReporter())));

	char delimiter = metricRegistry.getDelimiter();

	TaskManagerMetricGroup tmMetricGroup = new TaskManagerMetricGroup(metricRegistry, hostname, taskManagerId);
	TaskManagerJobMetricGroup tmJobMetricGroup = new TaskManagerJobMetricGroup(metricRegistry, tmMetricGroup, new JobID(), jobName);
	TaskMetricGroup taskMetricGroup = new TaskMetricGroup(metricRegistry, tmJobMetricGroup, new JobVertexID(), new AbstractID(), taskName, 0, 0);

	SimpleCounter myCounter = new SimpleCounter();
	com.codahale.metrics.Meter dropwizardMeter = new com.codahale.metrics.Meter();
	DropwizardMeterWrapper meterWrapper = new DropwizardMeterWrapper(dropwizardMeter);

	taskMetricGroup.counter(counterName, myCounter);
	taskMetricGroup.meter("meter", meterWrapper);

	List<MetricReporter> reporters = metricRegistry.getReporters();

	assertTrue(reporters.size() == 1);
	MetricReporter metricReporter = reporters.get(0);

	assertTrue("Reporter should be of type ScheduledDropwizardReporter", metricReporter instanceof ScheduledDropwizardReporter);

	TestingScheduledDropwizardReporter reporter = (TestingScheduledDropwizardReporter) metricReporter;

	Map<Counter, String> counters = reporter.getCounters();
	assertTrue(counters.containsKey(myCounter));

	Map<Meter, String> meters = reporter.getMeters();
	assertTrue(meters.containsKey(meterWrapper));

	String expectedCounterName = reporter.filterCharacters(hostname)
		+ delimiter
		+ reporter.filterCharacters(taskManagerId)
		+ delimiter
		+ reporter.filterCharacters(jobName)
		+ delimiter
		+ reporter.filterCharacters(counterName);

	assertEquals(expectedCounterName, counters.get(myCounter));

	metricRegistry.shutdown().get();
}
 
Example 6
Source File: StatsDReporterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that the registered metrics' names don't contain invalid characters.
 */
@Test
public void testAddingMetrics() throws Exception {
	Configuration configuration = new Configuration();
	String taskName = "testTask";
	String jobName = "testJob:-!ax..?";
	String hostname = "local::host:";
	String taskManagerId = "tas:kMana::ger";
	String counterName = "testCounter";

	configuration.setString(MetricOptions.SCOPE_NAMING_TASK, "<host>.<tm_id>.<job_name>");
	configuration.setString(MetricOptions.SCOPE_DELIMITER, "_");

	MetricRegistryImpl metricRegistry = new MetricRegistryImpl(
		MetricRegistryConfiguration.fromConfiguration(configuration),
		Collections.singletonList(ReporterSetup.forReporter("test", new TestingStatsDReporter())));

	char delimiter = metricRegistry.getDelimiter();

	TaskManagerMetricGroup tmMetricGroup = new TaskManagerMetricGroup(metricRegistry, hostname, taskManagerId);
	TaskManagerJobMetricGroup tmJobMetricGroup = new TaskManagerJobMetricGroup(metricRegistry, tmMetricGroup, new JobID(), jobName);
	TaskMetricGroup taskMetricGroup = new TaskMetricGroup(metricRegistry, tmJobMetricGroup, new JobVertexID(), new AbstractID(), taskName, 0, 0);

	SimpleCounter myCounter = new SimpleCounter();

	taskMetricGroup.counter(counterName, myCounter);

	List<MetricReporter> reporters = metricRegistry.getReporters();

	assertTrue(reporters.size() == 1);

	MetricReporter metricReporter = reporters.get(0);

	assertTrue("Reporter should be of type StatsDReporter", metricReporter instanceof StatsDReporter);

	TestingStatsDReporter reporter = (TestingStatsDReporter) metricReporter;

	Map<Counter, String> counters = reporter.getCounters();

	assertTrue(counters.containsKey(myCounter));

	String expectedCounterName = reporter.filterCharacters(hostname)
		+ delimiter
		+ reporter.filterCharacters(taskManagerId)
		+ delimiter
		+ reporter.filterCharacters(jobName)
		+ delimiter
		+ reporter.filterCharacters(counterName);

	assertEquals(expectedCounterName, counters.get(myCounter));

	metricRegistry.shutdown().get();
}