Search in sources :

Example 1 with ScopeFormats

use of org.apache.flink.runtime.metrics.scope.ScopeFormats in project flink by apache.

the class MetricRegistryTest method testScopeConfig.

/**
	 * Verifies that the scope configuration is properly extracted.
	 */
@Test
public void testScopeConfig() {
    Configuration config = new Configuration();
    config.setString(ConfigConstants.METRICS_SCOPE_NAMING_TM, "A");
    config.setString(ConfigConstants.METRICS_SCOPE_NAMING_TM_JOB, "B");
    config.setString(ConfigConstants.METRICS_SCOPE_NAMING_TASK, "C");
    config.setString(ConfigConstants.METRICS_SCOPE_NAMING_OPERATOR, "D");
    ScopeFormats scopeConfig = MetricRegistryConfiguration.createScopeConfig(config);
    assertEquals("A", scopeConfig.getTaskManagerFormat().format());
    assertEquals("B", scopeConfig.getTaskManagerJobFormat().format());
    assertEquals("C", scopeConfig.getTaskFormat().format());
    assertEquals("D", scopeConfig.getOperatorFormat().format());
}
Also used : Configuration(org.apache.flink.configuration.Configuration) ScopeFormats(org.apache.flink.runtime.metrics.scope.ScopeFormats) Test(org.junit.Test)

Example 2 with ScopeFormats

use of org.apache.flink.runtime.metrics.scope.ScopeFormats in project flink by apache.

the class MetricRegistryConfiguration method fromConfiguration.

// ------------------------------------------------------------------------
//  Static factory methods
// ------------------------------------------------------------------------
/**
	 * Create a metric registry configuration object from the given {@link Configuration}.
	 *
	 * @param configuration to generate the metric registry configuration from
	 * @return Metric registry configuration generated from the configuration
	 */
public static MetricRegistryConfiguration fromConfiguration(Configuration configuration) {
    ScopeFormats scopeFormats;
    try {
        scopeFormats = createScopeConfig(configuration);
    } catch (Exception e) {
        LOG.warn("Failed to parse scope format, using default scope formats", e);
        scopeFormats = new ScopeFormats();
    }
    char delim;
    try {
        delim = configuration.getString(ConfigConstants.METRICS_SCOPE_DELIMITER, ".").charAt(0);
    } catch (Exception e) {
        LOG.warn("Failed to parse delimiter, using default delimiter.", e);
        delim = '.';
    }
    final String definedReporters = configuration.getString(ConfigConstants.METRICS_REPORTERS_LIST, null);
    List<Tuple2<String, Configuration>> reporterConfigurations;
    if (definedReporters == null) {
        reporterConfigurations = Collections.emptyList();
    } else {
        String[] namedReporters = splitPattern.split(definedReporters);
        reporterConfigurations = new ArrayList<>(namedReporters.length);
        for (String namedReporter : namedReporters) {
            DelegatingConfiguration delegatingConfiguration = new DelegatingConfiguration(configuration, ConfigConstants.METRICS_REPORTER_PREFIX + namedReporter + '.');
            reporterConfigurations.add(Tuple2.of(namedReporter, (Configuration) delegatingConfiguration));
        }
    }
    return new MetricRegistryConfiguration(scopeFormats, delim, reporterConfigurations);
}
Also used : DelegatingConfiguration(org.apache.flink.configuration.DelegatingConfiguration) Configuration(org.apache.flink.configuration.Configuration) DelegatingConfiguration(org.apache.flink.configuration.DelegatingConfiguration) Tuple2(org.apache.flink.api.java.tuple.Tuple2) ScopeFormats(org.apache.flink.runtime.metrics.scope.ScopeFormats)

Aggregations

Configuration (org.apache.flink.configuration.Configuration)2 ScopeFormats (org.apache.flink.runtime.metrics.scope.ScopeFormats)2 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 DelegatingConfiguration (org.apache.flink.configuration.DelegatingConfiguration)1 Test (org.junit.Test)1