Search in sources :

Example 11 with MetricConfig

use of org.apache.flink.metrics.MetricConfig in project flink by apache.

the class InfluxdbReporterTest method createReporter.

private InfluxdbReporter createReporter(String retentionPolicy, InfluxDB.ConsistencyLevel consistencyLevel) {
    MetricConfig metricConfig = new MetricConfig();
    metricConfig.setProperty(InfluxdbReporterOptions.HOST.key(), "localhost");
    metricConfig.setProperty(InfluxdbReporterOptions.PORT.key(), String.valueOf(wireMockRule.getPort()));
    metricConfig.setProperty(InfluxdbReporterOptions.DB.key(), TEST_INFLUXDB_DB);
    metricConfig.setProperty(InfluxdbReporterOptions.RETENTION_POLICY.key(), retentionPolicy);
    metricConfig.setProperty(InfluxdbReporterOptions.CONSISTENCY.key(), consistencyLevel.name());
    final InfluxdbReporter reporter = new InfluxdbReporter();
    reporter.open(metricConfig);
    return reporter;
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig)

Example 12 with MetricConfig

use of org.apache.flink.metrics.MetricConfig in project flink by apache.

the class PrometheusPushGatewayReporterFactory method createMetricReporter.

@Override
public PrometheusPushGatewayReporter createMetricReporter(Properties properties) {
    MetricConfig metricConfig = (MetricConfig) properties;
    String host = metricConfig.getString(HOST.key(), HOST.defaultValue());
    int port = metricConfig.getInteger(PORT.key(), PORT.defaultValue());
    String configuredJobName = metricConfig.getString(JOB_NAME.key(), JOB_NAME.defaultValue());
    boolean randomSuffix = metricConfig.getBoolean(RANDOM_JOB_NAME_SUFFIX.key(), RANDOM_JOB_NAME_SUFFIX.defaultValue());
    boolean deleteOnShutdown = metricConfig.getBoolean(DELETE_ON_SHUTDOWN.key(), DELETE_ON_SHUTDOWN.defaultValue());
    Map<String, String> groupingKey = parseGroupingKey(metricConfig.getString(GROUPING_KEY.key(), GROUPING_KEY.defaultValue()));
    String hostUrlConfig = metricConfig.getString(HOST_URL.key(), HOST_URL.defaultValue());
    final String hostUrl;
    if (!StringUtils.isNullOrWhitespaceOnly(hostUrlConfig)) {
        hostUrl = hostUrlConfig;
    } else {
        if (StringUtils.isNullOrWhitespaceOnly(host) || port < 1) {
            throw new IllegalArgumentException("Invalid host/port configuration. Host: " + host + " Port: " + port);
        } else {
            hostUrl = "http://" + host + ":" + port;
        }
    }
    String jobName = configuredJobName;
    if (randomSuffix) {
        jobName = configuredJobName + new AbstractID();
    }
    LOG.info("Configured PrometheusPushGatewayReporter with {hostUrl:{}, jobName:{}, randomJobNameSuffix:{}, deleteOnShutdown:{}, groupingKey:{}}", hostUrl, jobName, randomSuffix, deleteOnShutdown, groupingKey);
    try {
        return new PrometheusPushGatewayReporter(new URL(hostUrl), jobName, groupingKey, deleteOnShutdown);
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig) MalformedURLException(java.net.MalformedURLException) AbstractID(org.apache.flink.util.AbstractID) HOST_URL(org.apache.flink.metrics.prometheus.PrometheusPushGatewayReporterOptions.HOST_URL) URL(java.net.URL)

Example 13 with MetricConfig

use of org.apache.flink.metrics.MetricConfig in project flink by apache.

the class DropwizardFlinkHistogramWrapperTest method testDropwizardHistogramWrapperReporting.

/**
 * Tests that the DropwizardHistogramWrapper reports correct dropwizard snapshots to the
 * ScheduledReporter.
 */
@Test
void testDropwizardHistogramWrapperReporting() throws Exception {
    int size = 10;
    String histogramMetricName = "histogram";
    final TestingReporter testingReporter = new TestingReporter();
    testingReporter.open(new MetricConfig());
    DropwizardHistogramWrapper histogramWrapper = new DropwizardHistogramWrapper(new com.codahale.metrics.Histogram(new SlidingWindowReservoir(size)));
    final MetricGroup metricGroup = TestMetricGroup.newBuilder().build();
    testingReporter.notifyOfAddedMetric(histogramWrapper, histogramMetricName, metricGroup);
    // check that the metric has been registered
    assertThat(testingReporter.getMetrics()).hasSize(1);
    for (int i = 0; i < size; i++) {
        histogramWrapper.update(i);
    }
    testingReporter.report();
    String fullMetricName = metricGroup.getMetricIdentifier(histogramMetricName);
    Snapshot snapshot = testingReporter.getNextHistogramSnapshot(fullMetricName);
    assertThat(snapshot.getMin()).isEqualTo(0);
    assertThat(snapshot.getMedian()).isCloseTo((size - 1) / 2.0, offset(0.001));
    assertThat(snapshot.getMax()).isEqualTo(size - 1);
    assertThat(snapshot.size()).isEqualTo(size);
    testingReporter.notifyOfRemovedMetric(histogramWrapper, histogramMetricName, metricGroup);
    // check that the metric has been de-registered
    assertThat(testingReporter.getMetrics()).hasSize(0);
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig) Snapshot(com.codahale.metrics.Snapshot) SlidingWindowReservoir(com.codahale.metrics.SlidingWindowReservoir) TestMetricGroup(org.apache.flink.metrics.util.TestMetricGroup) MetricGroup(org.apache.flink.metrics.MetricGroup) Test(org.junit.jupiter.api.Test) AbstractHistogramTest(org.apache.flink.metrics.AbstractHistogramTest)

Example 14 with MetricConfig

use of org.apache.flink.metrics.MetricConfig in project flink by apache.

the class PrometheusReporterTest method createReporterSetup.

static ReporterSetup createReporterSetup(String reporterName, String portString) {
    MetricConfig metricConfig = new MetricConfig();
    metricConfig.setProperty(ARG_PORT, portString);
    PrometheusReporter metricReporter = prometheusReporterFactory.createMetricReporter(metricConfig);
    return ReporterSetup.forReporter(reporterName, metricConfig, metricReporter);
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig)

Example 15 with MetricConfig

use of org.apache.flink.metrics.MetricConfig in project flink by apache.

the class MetricRegistryImplTest method testConfigurableDelimiterForReportersInGroup.

@Test
public void testConfigurableDelimiterForReportersInGroup() throws Exception {
    String name = "C";
    MetricConfig config1 = new MetricConfig();
    config1.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "_");
    MetricConfig config2 = new MetricConfig();
    config2.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");
    MetricConfig config3 = new MetricConfig();
    config3.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "AA");
    Configuration config = new Configuration();
    config.setString(MetricOptions.SCOPE_NAMING_TM, "A.B");
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "_");
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, CollectingMetricsReporter.class.getName());
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, CollectingMetricsReporter.class.getName());
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test3." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "AA");
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test3." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, CollectingMetricsReporter.class.getName());
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test4." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, CollectingMetricsReporter.class.getName());
    List<ReporterSetup> reporterConfigurations = Arrays.asList(ReporterSetup.forReporter("test1", config1, new CollectingMetricsReporter()), ReporterSetup.forReporter("test2", config2, new CollectingMetricsReporter()), ReporterSetup.forReporter("test3", config3, new CollectingMetricsReporter()), ReporterSetup.forReporter("test4", new CollectingMetricsReporter()));
    MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryTestUtils.fromConfiguration(config), reporterConfigurations);
    TaskManagerMetricGroup group = TaskManagerMetricGroup.createTaskManagerMetricGroup(registry, "host", new ResourceID("id"));
    group.counter(name);
    group.close();
    registry.shutdown().get();
    for (ReporterSetup cfg : reporterConfigurations) {
        String delimiter = cfg.getConfiguration().getProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER);
        if (delimiter == null || delimiter.equals("AA")) {
            // test3 reporter: 'AA' - not correct
            // for test4 reporter use global delimiter
            delimiter = String.valueOf(GLOBAL_DEFAULT_DELIMITER);
        }
        String expected = (config.get(MetricOptions.SCOPE_NAMING_TM) + ".C").replaceAll("\\.", delimiter);
        CollectingMetricsReporter reporter = (CollectingMetricsReporter) cfg.getReporter();
        for (MetricGroupAndName groupAndName : Arrays.asList(reporter.findAdded(name), reporter.findRemoved(name))) {
            assertEquals(expected, groupAndName.group.getMetricIdentifier(name));
            assertEquals(expected, groupAndName.group.getMetricIdentifier(name, reporter));
        }
    }
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig) Configuration(org.apache.flink.configuration.Configuration) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) MetricGroupAndName(org.apache.flink.runtime.metrics.CollectingMetricsReporter.MetricGroupAndName) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) MetricGroupTest(org.apache.flink.runtime.metrics.groups.MetricGroupTest) Test(org.junit.Test)

Aggregations

MetricConfig (org.apache.flink.metrics.MetricConfig)19 Test (org.junit.jupiter.api.Test)6 Test (org.junit.Test)5 MetricGroup (org.apache.flink.metrics.MetricGroup)4 MetricGroupTest (org.apache.flink.runtime.metrics.groups.MetricGroupTest)4 Map (java.util.Map)3 ConfigConstants (org.apache.flink.configuration.ConfigConstants)3 Configuration (org.apache.flink.configuration.Configuration)3 TestMetricGroup (org.apache.flink.metrics.util.TestMetricGroup)3 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 MetricOptions (org.apache.flink.configuration.MetricOptions)2 UnregisteredMetricsGroup (org.apache.flink.metrics.groups.UnregisteredMetricsGroup)2 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)2 MetricGroupAndName (org.apache.flink.runtime.metrics.CollectingMetricsReporter.MetricGroupAndName)2 SlidingWindowReservoir (com.codahale.metrics.SlidingWindowReservoir)1 Snapshot (com.codahale.metrics.Snapshot)1 File (java.io.File)1 IOException (java.io.IOException)1