Search in sources :

Example 1 with MetricConfig

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

the class ReporterSetup method setupReporters.

private static List<ReporterSetup> setupReporters(Map<String, MetricReporterFactory> reporterFactories, List<Tuple2<String, Configuration>> reporterConfigurations) {
    List<ReporterSetup> reporterSetups = new ArrayList<>(reporterConfigurations.size());
    for (Tuple2<String, Configuration> reporterConfiguration : reporterConfigurations) {
        String reporterName = reporterConfiguration.f0;
        Configuration reporterConfig = reporterConfiguration.f1;
        try {
            Optional<MetricReporter> metricReporterOptional = loadReporter(reporterName, reporterConfig, reporterFactories);
            // massage user variables keys into scope format for parity to variable exclusion
            Map<String, String> additionalVariables = reporterConfig.get(ADDITIONAL_VARIABLES).entrySet().stream().collect(Collectors.toMap(e -> ScopeFormat.asVariable(e.getKey()), Entry::getValue));
            metricReporterOptional.ifPresent(reporter -> {
                MetricConfig metricConfig = new MetricConfig();
                reporterConfig.addAllToProperties(metricConfig);
                reporterSetups.add(createReporterSetup(reporterName, metricConfig, reporter, additionalVariables));
            });
        } catch (Throwable t) {
            LOG.error("Could not instantiate metrics reporter {}. Metrics might not be exposed/reported.", reporterName, t);
        }
    }
    return reporterSetups;
}
Also used : ConfigOptions(org.apache.flink.configuration.ConfigOptions) MetricConfig(org.apache.flink.metrics.MetricConfig) Tuple2(org.apache.flink.api.java.tuple.Tuple2) DelegatingConfiguration(org.apache.flink.configuration.DelegatingConfiguration) LoggerFactory(org.slf4j.LoggerFactory) InterceptInstantiationViaReflection(org.apache.flink.metrics.reporter.InterceptInstantiationViaReflection) HashMap(java.util.HashMap) MetricReporter(org.apache.flink.metrics.reporter.MetricReporter) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Matcher(java.util.regex.Matcher) InstantiateViaFactory(org.apache.flink.metrics.reporter.InstantiateViaFactory) ScopeFormat(org.apache.flink.runtime.metrics.scope.ScopeFormat) Map(java.util.Map) ConfigConstants(org.apache.flink.configuration.ConfigConstants) ServiceConfigurationError(java.util.ServiceConfigurationError) ConfigOption(org.apache.flink.configuration.ConfigOption) Nullable(javax.annotation.Nullable) MetricReporterFactory(org.apache.flink.metrics.reporter.MetricReporterFactory) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Configuration(org.apache.flink.configuration.Configuration) Set(java.util.Set) ServiceLoader(java.util.ServiceLoader) MetricOptions(org.apache.flink.configuration.MetricOptions) Collectors(java.util.stream.Collectors) File(java.io.File) Iterators(org.apache.flink.shaded.guava30.com.google.common.collect.Iterators) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting) List(java.util.List) PluginManager(org.apache.flink.core.plugin.PluginManager) Entry(java.util.Map.Entry) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) MetricConfig(org.apache.flink.metrics.MetricConfig) DelegatingConfiguration(org.apache.flink.configuration.DelegatingConfiguration) Configuration(org.apache.flink.configuration.Configuration) ArrayList(java.util.ArrayList) MetricReporter(org.apache.flink.metrics.reporter.MetricReporter)

Example 2 with MetricConfig

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

the class ReporterSetup method loadViaFactory.

private static Optional<MetricReporter> loadViaFactory(final Configuration reporterConfig, final MetricReporterFactory factory) {
    final MetricConfig metricConfig = new MetricConfig();
    reporterConfig.addAllToProperties(metricConfig);
    return Optional.of(factory.createMetricReporter(metricConfig));
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig)

Example 3 with MetricConfig

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

the class Slf4jReporterTest method setUp.

@BeforeAll
static void setUp() {
    delimiter = '.';
    metricGroup = TestMetricGroup.newBuilder().setMetricIdentifierFunction((s, characterFilter) -> SCOPE + delimiter + s).build();
    reporter = new Slf4jReporter();
    reporter.open(new MetricConfig());
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 4 with MetricConfig

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

the class StatsDReporterTest method testMetricAndAssert.

private void testMetricAndAssert(Metric metric, String metricName, Set<String> expectation) throws Exception {
    StatsDReporter reporter = null;
    DatagramSocketReceiver receiver = null;
    Thread receiverThread = null;
    long timeout = 5000;
    long joinTimeout = 30000;
    try {
        receiver = new DatagramSocketReceiver();
        receiverThread = new Thread(receiver);
        receiverThread.start();
        int port = receiver.getPort();
        MetricConfig config = new MetricConfig();
        config.setProperty("host", "localhost");
        config.setProperty("port", String.valueOf(port));
        reporter = new StatsDReporter();
        reporter.open(config);
        MetricGroup metricGroup = new UnregisteredMetricsGroup();
        reporter.notifyOfAddedMetric(metric, metricName, metricGroup);
        reporter.report();
        receiver.waitUntilNumLines(expectation.size(), timeout);
        assertThat(receiver.getLines()).isEqualTo(expectation);
    } finally {
        if (reporter != null) {
            reporter.close();
        }
        if (receiver != null) {
            receiver.stop();
        }
        if (receiverThread != null) {
            receiverThread.join(joinTimeout);
        }
    }
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig) UnregisteredMetricsGroup(org.apache.flink.metrics.groups.UnregisteredMetricsGroup) TestMetricGroup(org.apache.flink.metrics.util.TestMetricGroup) MetricGroup(org.apache.flink.metrics.MetricGroup)

Example 5 with MetricConfig

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

the class PrometheusReporterFactory method createMetricReporter.

@Override
public PrometheusReporter createMetricReporter(Properties properties) {
    MetricConfig metricConfig = (MetricConfig) properties;
    String portsConfig = metricConfig.getString(ARG_PORT, DEFAULT_PORT);
    Iterator<Integer> ports = NetUtils.getPortRangeFromString(portsConfig);
    return new PrometheusReporter(ports);
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig)

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