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());
}
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);
}
Aggregations