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