Search in sources :

Example 6 with TaskManagerMetricGroup

use of org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup in project flink by apache.

the class MetricRegistryTest method testReporterNotifications.

/**
	 * Verifies that reporters are notified of added/removed metrics.
	 */
@Test
public void testReporterNotifications() {
    Configuration config = new Configuration();
    config.setString(ConfigConstants.METRICS_REPORTERS_LIST, "test1,test2");
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter6.class.getName());
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter7.class.getName());
    MetricRegistry registry = new MetricRegistry(MetricRegistryConfiguration.fromConfiguration(config));
    TaskManagerMetricGroup root = new TaskManagerMetricGroup(registry, "host", "id");
    root.counter("rootCounter");
    root.close();
    assertTrue(TestReporter6.addCalled);
    assertTrue(TestReporter6.removeCalled);
    assertTrue(TestReporter7.addCalled);
    assertTrue(TestReporter7.removeCalled);
    registry.shutdown();
}
Also used : Configuration(org.apache.flink.configuration.Configuration) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) Test(org.junit.Test)

Example 7 with TaskManagerMetricGroup

use of org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup in project flink by apache.

the class StatsDReporterTest method testStatsDMetersReporting.

/**
	 * Tests that meters are properly reported via the StatsD reporter
	 */
@Test
public void testStatsDMetersReporting() throws Exception {
    MetricRegistry registry = null;
    DatagramSocketReceiver receiver = null;
    Thread receiverThread = null;
    long timeout = 5000;
    long joinTimeout = 30000;
    String meterName = "meter";
    try {
        receiver = new DatagramSocketReceiver();
        receiverThread = new Thread(receiver);
        receiverThread.start();
        int port = receiver.getPort();
        Configuration config = new Configuration();
        config.setString(ConfigConstants.METRICS_REPORTERS_LIST, "test");
        config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, StatsDReporter.class.getName());
        config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test." + ConfigConstants.METRICS_REPORTER_INTERVAL_SUFFIX, "1 SECONDS");
        config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test.host", "localhost");
        config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test.port", "" + port);
        registry = new MetricRegistry(MetricRegistryConfiguration.fromConfiguration(config));
        TaskManagerMetricGroup metricGroup = new TaskManagerMetricGroup(registry, "localhost", "tmId");
        TestMeter meter = new TestMeter();
        metricGroup.meter(meterName, meter);
        String prefix = metricGroup.getMetricIdentifier(meterName);
        Set<String> expectedLines = new HashSet<>();
        expectedLines.add(prefix + ".rate:5.0|g");
        expectedLines.add(prefix + ".count:100|g");
        receiver.waitUntilNumLines(expectedLines.size(), timeout);
        Set<String> lines = receiver.getLines();
        assertEquals(expectedLines, lines);
    } finally {
        if (registry != null) {
            registry.shutdown();
        }
        if (receiver != null) {
            receiver.stop();
        }
        if (receiverThread != null) {
            receiverThread.join(joinTimeout);
        }
    }
}
Also used : TestMeter(org.apache.flink.metrics.util.TestMeter) 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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with TaskManagerMetricGroup

use of org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup 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 9 with TaskManagerMetricGroup

use of org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup 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 10 with TaskManagerMetricGroup

use of org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup 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)

Aggregations

TaskManagerMetricGroup (org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup)16 Configuration (org.apache.flink.configuration.Configuration)15 Test (org.junit.Test)15 MetricRegistry (org.apache.flink.runtime.metrics.MetricRegistry)13 MetricRegistryConfiguration (org.apache.flink.runtime.metrics.MetricRegistryConfiguration)10 MetricReporter (org.apache.flink.metrics.reporter.MetricReporter)6 JobID (org.apache.flink.api.common.JobID)4 MBeanServer (javax.management.MBeanServer)3 ObjectName (javax.management.ObjectName)3 Counter (org.apache.flink.metrics.Counter)3 SimpleCounter (org.apache.flink.metrics.SimpleCounter)3 BroadcastVariableManager (org.apache.flink.runtime.broadcast.BroadcastVariableManager)3 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)3 FileCache (org.apache.flink.runtime.filecache.FileCache)3 IOManager (org.apache.flink.runtime.io.disk.iomanager.IOManager)3 NetworkEnvironment (org.apache.flink.runtime.io.network.NetworkEnvironment)3 MemoryManager (org.apache.flink.runtime.memory.MemoryManager)3 TaskMetricGroup (org.apache.flink.runtime.metrics.groups.TaskMetricGroup)3 TaskSlotTable (org.apache.flink.runtime.taskexecutor.slot.TaskSlotTable)3 TaskManagerLocation (org.apache.flink.runtime.taskmanager.TaskManagerLocation)3