use of org.apache.flink.runtime.metrics.MetricRegistry in project flink by apache.
the class StatsDReporterTest method testAddingMetrics.
/**
* Tests that the registered metrics' names don't contain invalid characters.
*/
@Test
public void testAddingMetrics() throws NoSuchFieldException, IllegalAccessException {
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_REPORTERS_LIST, "test");
configuration.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, "org.apache.flink.metrics.statsd.StatsDReporterTest$TestingStatsDReporter");
configuration.setString(ConfigConstants.METRICS_SCOPE_NAMING_TASK, "<host>.<tm_id>.<job_name>");
configuration.setString(ConfigConstants.METRICS_SCOPE_DELIMITER, "_");
MetricRegistry metricRegistry = new MetricRegistry(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 AbstractID(), 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();
}
use of org.apache.flink.runtime.metrics.MetricRegistry in project flink by apache.
the class ScheduledDropwizardReporterTest method testAddingMetrics.
/**
* Tests that the registered metrics' names don't contain invalid characters.
*/
@Test
public void testAddingMetrics() throws NoSuchFieldException, IllegalAccessException {
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_REPORTERS_LIST, "test");
configuration.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, "org.apache.flink.dropwizard.ScheduledDropwizardReporterTest$TestingScheduledDropwizardReporter");
configuration.setString(ConfigConstants.METRICS_SCOPE_NAMING_TASK, "<host>.<tm_id>.<job_name>");
configuration.setString(ConfigConstants.METRICS_SCOPE_DELIMITER, "_");
MetricRegistryConfiguration metricRegistryConfiguration = MetricRegistryConfiguration.fromConfiguration(configuration);
MetricRegistry metricRegistry = new MetricRegistry(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 AbstractID(), 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();
}
use of org.apache.flink.runtime.metrics.MetricRegistry in project flink by apache.
the class DropwizardFlinkHistogramWrapperTest method testDropwizardHistogramWrapperReporting.
/**
* Tests that the DropwizardHistogramWrapper reports correct dropwizard snapshots to the
* ScheduledReporter.
*/
@Test
public void testDropwizardHistogramWrapperReporting() throws Exception {
long reportingInterval = 1000;
long timeout = 30000;
int size = 10;
String histogramMetricName = "histogram";
Configuration config = new Configuration();
config.setString(ConfigConstants.METRICS_REPORTERS_LIST, "my_reporter");
config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "my_reporter." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestingReporter.class.getName());
config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "my_reporter." + ConfigConstants.METRICS_REPORTER_INTERVAL_SUFFIX, reportingInterval + " MILLISECONDS");
MetricRegistry registry = null;
MetricRegistryConfiguration metricRegistryConfiguration = MetricRegistryConfiguration.fromConfiguration(config);
try {
registry = new MetricRegistry(metricRegistryConfiguration);
DropwizardHistogramWrapper histogramWrapper = new DropwizardHistogramWrapper(new com.codahale.metrics.Histogram(new SlidingWindowReservoir(size)));
TaskManagerMetricGroup metricGroup = new TaskManagerMetricGroup(registry, "localhost", "tmId");
metricGroup.histogram(histogramMetricName, histogramWrapper);
String fullMetricName = metricGroup.getMetricIdentifier(histogramMetricName);
assertTrue(registry.getReporters().size() == 1);
MetricReporter reporter = registry.getReporters().get(0);
assertTrue(reporter instanceof TestingReporter);
TestingReporter testingReporter = (TestingReporter) reporter;
TestingScheduledReporter scheduledReporter = testingReporter.scheduledReporter;
// check that the metric has been registered
assertEquals(1, testingReporter.getMetrics().size());
for (int i = 0; i < size; i++) {
histogramWrapper.update(i);
}
Future<Snapshot> snapshotFuture = scheduledReporter.getNextHistogramSnapshot(fullMetricName);
Snapshot snapshot = snapshotFuture.get(timeout, TimeUnit.MILLISECONDS);
assertEquals(0, snapshot.getMin());
assertEquals((size - 1) / 2.0, snapshot.getMedian(), 0.001);
assertEquals(size - 1, snapshot.getMax());
assertEquals(size, snapshot.size());
registry.unregister(histogramWrapper, "histogram", metricGroup);
// check that the metric has been de-registered
assertEquals(0, testingReporter.getMetrics().size());
} finally {
if (registry != null) {
registry.shutdown();
}
}
}
use of org.apache.flink.runtime.metrics.MetricRegistry in project flink by apache.
the class JMXReporterTest method testHistogramReporting.
/**
* Tests that histograms are properly reported via the JMXReporter.
*/
@Test
public void testHistogramReporting() throws Exception {
MetricRegistry registry = null;
String histogramName = "histogram";
try {
Configuration config = new Configuration();
config.setString(ConfigConstants.METRICS_REPORTERS_LIST, "jmx_test");
config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "jmx_test." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, JMXReporter.class.getName());
registry = new MetricRegistry(MetricRegistryConfiguration.fromConfiguration(config));
TaskManagerMetricGroup metricGroup = new TaskManagerMetricGroup(registry, "localhost", "tmId");
TestingHistogram histogram = new TestingHistogram();
metricGroup.histogram(histogramName, histogram);
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName objectName = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager." + histogramName, JMXReporter.generateJmxTable(metricGroup.getAllVariables()));
MBeanInfo info = mBeanServer.getMBeanInfo(objectName);
MBeanAttributeInfo[] attributeInfos = info.getAttributes();
assertEquals(11, attributeInfos.length);
assertEquals(histogram.getCount(), mBeanServer.getAttribute(objectName, "Count"));
assertEquals(histogram.getStatistics().getMean(), mBeanServer.getAttribute(objectName, "Mean"));
assertEquals(histogram.getStatistics().getStdDev(), mBeanServer.getAttribute(objectName, "StdDev"));
assertEquals(histogram.getStatistics().getMax(), mBeanServer.getAttribute(objectName, "Max"));
assertEquals(histogram.getStatistics().getMin(), mBeanServer.getAttribute(objectName, "Min"));
assertEquals(histogram.getStatistics().getQuantile(0.5), mBeanServer.getAttribute(objectName, "Median"));
assertEquals(histogram.getStatistics().getQuantile(0.75), mBeanServer.getAttribute(objectName, "75thPercentile"));
assertEquals(histogram.getStatistics().getQuantile(0.95), mBeanServer.getAttribute(objectName, "95thPercentile"));
assertEquals(histogram.getStatistics().getQuantile(0.98), mBeanServer.getAttribute(objectName, "98thPercentile"));
assertEquals(histogram.getStatistics().getQuantile(0.99), mBeanServer.getAttribute(objectName, "99thPercentile"));
assertEquals(histogram.getStatistics().getQuantile(0.999), mBeanServer.getAttribute(objectName, "999thPercentile"));
} finally {
if (registry != null) {
registry.shutdown();
}
}
}
use of org.apache.flink.runtime.metrics.MetricRegistry in project flink by apache.
the class MetricQueryServiceTest method testCreateDump.
@Test
public void testCreateDump() throws Exception {
ActorSystem s = AkkaUtils.createLocalActorSystem(new Configuration());
ActorRef serviceActor = MetricQueryService.startMetricQueryService(s, null);
TestActorRef testActorRef = TestActorRef.create(s, Props.create(TestActor.class));
TestActor testActor = (TestActor) testActorRef.underlyingActor();
final Counter c = new SimpleCounter();
final Gauge<String> g = new Gauge<String>() {
@Override
public String getValue() {
return "Hello";
}
};
final Histogram h = new TestingHistogram();
final Meter m = new Meter() {
@Override
public void markEvent() {
}
@Override
public void markEvent(long n) {
}
@Override
public double getRate() {
return 5;
}
@Override
public long getCount() {
return 10;
}
};
MetricRegistry registry = new MetricRegistry(MetricRegistryConfiguration.defaultMetricRegistryConfiguration());
final TaskManagerMetricGroup tm = new TaskManagerMetricGroup(registry, "host", "id");
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);
synchronized (testActor.lock) {
if (testActor.message == null) {
testActor.lock.wait();
}
}
MetricDumpSerialization.MetricSerializationResult dump = (MetricDumpSerialization.MetricSerializationResult) testActor.message;
testActor.message = null;
assertTrue(dump.serializedMetrics.length > 0);
MetricQueryService.notifyOfRemovedMetric(serviceActor, c);
MetricQueryService.notifyOfRemovedMetric(serviceActor, g);
MetricQueryService.notifyOfRemovedMetric(serviceActor, h);
MetricQueryService.notifyOfRemovedMetric(serviceActor, m);
serviceActor.tell(MetricQueryService.getCreateDump(), testActorRef);
synchronized (testActor.lock) {
if (testActor.message == null) {
testActor.lock.wait();
}
}
MetricDumpSerialization.MetricSerializationResult emptyDump = (MetricDumpSerialization.MetricSerializationResult) testActor.message;
testActor.message = null;
assertEquals(0, emptyDump.serializedMetrics.length);
s.shutdown();
}
Aggregations