Search in sources :

Example 26 with MetricRegistry

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();
}
Also used : MetricRegistryConfiguration(org.apache.flink.runtime.metrics.MetricRegistryConfiguration) Configuration(org.apache.flink.configuration.Configuration) TaskMetricGroup(org.apache.flink.runtime.metrics.groups.TaskMetricGroup) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) TaskManagerJobMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerJobMetricGroup) MetricReporter(org.apache.flink.metrics.reporter.MetricReporter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) AbstractID(org.apache.flink.util.AbstractID) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 27 with MetricRegistry

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();
}
Also used : MetricRegistryConfiguration(org.apache.flink.runtime.metrics.MetricRegistryConfiguration) Configuration(org.apache.flink.configuration.Configuration) Meter(org.apache.flink.metrics.Meter) TaskMetricGroup(org.apache.flink.runtime.metrics.groups.TaskMetricGroup) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) TaskManagerJobMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerJobMetricGroup) MetricRegistryConfiguration(org.apache.flink.runtime.metrics.MetricRegistryConfiguration) MetricReporter(org.apache.flink.metrics.reporter.MetricReporter) DropwizardMeterWrapper(org.apache.flink.dropwizard.metrics.DropwizardMeterWrapper) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) AbstractID(org.apache.flink.util.AbstractID) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 28 with MetricRegistry

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();
        }
    }
}
Also used : MetricRegistryConfiguration(org.apache.flink.runtime.metrics.MetricRegistryConfiguration) Configuration(org.apache.flink.configuration.Configuration) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) MetricRegistryConfiguration(org.apache.flink.runtime.metrics.MetricRegistryConfiguration) MetricReporter(org.apache.flink.metrics.reporter.MetricReporter) Snapshot(com.codahale.metrics.Snapshot) SlidingWindowReservoir(com.codahale.metrics.SlidingWindowReservoir) Test(org.junit.Test)

Example 29 with MetricRegistry

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();
        }
    }
}
Also used : MetricRegistryConfiguration(org.apache.flink.runtime.metrics.MetricRegistryConfiguration) Configuration(org.apache.flink.configuration.Configuration) MBeanInfo(javax.management.MBeanInfo) TestingHistogram(org.apache.flink.runtime.metrics.util.TestingHistogram) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 30 with MetricRegistry

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();
}
Also used : ActorSystem(akka.actor.ActorSystem) TestingHistogram(org.apache.flink.runtime.metrics.util.TestingHistogram) Histogram(org.apache.flink.metrics.Histogram) Configuration(org.apache.flink.configuration.Configuration) MetricRegistryConfiguration(org.apache.flink.runtime.metrics.MetricRegistryConfiguration) Meter(org.apache.flink.metrics.Meter) TestActorRef(akka.testkit.TestActorRef) ActorRef(akka.actor.ActorRef) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) TestActorRef(akka.testkit.TestActorRef) Gauge(org.apache.flink.metrics.Gauge) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) TestingHistogram(org.apache.flink.runtime.metrics.util.TestingHistogram) Test(org.junit.Test)

Aggregations

MetricRegistry (org.apache.flink.runtime.metrics.MetricRegistry)53 Test (org.junit.Test)47 Configuration (org.apache.flink.configuration.Configuration)27 JobID (org.apache.flink.api.common.JobID)26 MetricRegistryConfiguration (org.apache.flink.runtime.metrics.MetricRegistryConfiguration)25 AbstractID (org.apache.flink.util.AbstractID)13 TaskManagerMetricGroup (org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup)12 MetricReporter (org.apache.flink.metrics.reporter.MetricReporter)7 QueryScopeInfo (org.apache.flink.runtime.metrics.dump.QueryScopeInfo)7 DummyCharacterFilter (org.apache.flink.runtime.metrics.util.DummyCharacterFilter)7 Counter (org.apache.flink.metrics.Counter)4 MetricGroup (org.apache.flink.metrics.MetricGroup)4 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)4 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)4 ActorRef (akka.actor.ActorRef)3 UUID (java.util.UUID)3 ObjectName (javax.management.ObjectName)3 Time (org.apache.flink.api.common.time.Time)3 Gauge (org.apache.flink.metrics.Gauge)3 SimpleCounter (org.apache.flink.metrics.SimpleCounter)3