Java Code Examples for org.apache.flink.metrics.MetricConfig#setProperty()

The following examples show how to use org.apache.flink.metrics.MetricConfig#setProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testReporterIntervalParsingErrorFallsBackToDefaultValue() throws Exception {
	MetricConfig config = new MetricConfig();
	// in a prior implementation the time amount was applied even if the time unit was invalid
	// in this case this would imply using 1 SECOND as the interval (seconds is the default)
	config.setProperty(ConfigConstants.METRICS_REPORTER_INTERVAL_SUFFIX, "1 UNICORN");

	final ManuallyTriggeredScheduledExecutorService manuallyTriggeredScheduledExecutorService = new ManuallyTriggeredScheduledExecutorService();

	MetricRegistryImpl registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Collections.singletonList(ReporterSetup.forReporter("test", config, new TestReporter3())),
		manuallyTriggeredScheduledExecutorService);
	try {
		Collection<ScheduledFuture<?>> scheduledTasks = manuallyTriggeredScheduledExecutorService.getScheduledTasks();
		ScheduledFuture<?> reportTask = Iterators.getOnlyElement(scheduledTasks.iterator());
		Assert.assertEquals(MetricOptions.REPORTER_INTERVAL.defaultValue().getSeconds(), reportTask.getDelay(TimeUnit.SECONDS));
	} finally {
		registry.shutdown().get();
	}
}
 
Example 2
Source File: AbstractMetricGroupTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testScopeCachingForMultipleReporters() throws Exception {
	Configuration config = new Configuration();
	config.setString(MetricOptions.SCOPE_NAMING_TM, "A.B.C.D");

	MetricConfig metricConfig1 = new MetricConfig();
	metricConfig1.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");

	MetricConfig metricConfig2 = new MetricConfig();
	metricConfig2.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "!");

	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter1.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter2.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "!");

	MetricRegistryImpl testRegistry = new MetricRegistryImpl(
		MetricRegistryConfiguration.fromConfiguration(config),
		Arrays.asList(
			ReporterSetup.forReporter("test1", metricConfig1, new TestReporter1()),
			ReporterSetup.forReporter("test2", metricConfig2, new TestReporter2())));
	try {
		MetricGroup tmGroup = new TaskManagerMetricGroup(testRegistry, "host", "id");
		tmGroup.counter("1");
		assertEquals("Reporters were not properly instantiated", 2, testRegistry.getReporters().size());
		for (MetricReporter reporter : testRegistry.getReporters()) {
			ScopeCheckingTestReporter typedReporter = (ScopeCheckingTestReporter) reporter;
			if (typedReporter.failureCause != null) {
				throw typedReporter.failureCause;
			}
		}
	} finally {
		testRegistry.shutdown().get();
	}
}
 
Example 3
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigurableDelimiterForReporters() throws Exception {
	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");

	MetricRegistryImpl registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Arrays.asList(
			ReporterSetup.forReporter("test1", config1, new TestReporter()),
			ReporterSetup.forReporter("test2", config2, new TestReporter()),
			ReporterSetup.forReporter("test3", config3, new TestReporter())));

	assertEquals(GLOBAL_DEFAULT_DELIMITER, registry.getDelimiter());
	assertEquals('_', registry.getDelimiter(0));
	assertEquals('-', registry.getDelimiter(1));
	assertEquals(GLOBAL_DEFAULT_DELIMITER, registry.getDelimiter(2));
	assertEquals(GLOBAL_DEFAULT_DELIMITER, registry.getDelimiter(3));
	assertEquals(GLOBAL_DEFAULT_DELIMITER, registry.getDelimiter(-1));

	registry.shutdown().get();
}
 
Example 4
Source File: InfluxdbReporterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private MetricRegistryImpl createMetricRegistry(String retentionPolicy) {
	MetricConfig metricConfig = new MetricConfig();
	metricConfig.setProperty(InfluxdbReporterOptions.HOST.key(), "localhost");
	metricConfig.setProperty(InfluxdbReporterOptions.PORT.key(), String.valueOf(wireMockRule.port()));
	metricConfig.setProperty(InfluxdbReporterOptions.DB.key(), TEST_INFLUXDB_DB);
	metricConfig.setProperty(InfluxdbReporterOptions.RETENTION_POLICY.key(), retentionPolicy);

	return new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Collections.singletonList(ReporterSetup.forReporter("test", metricConfig, new InfluxdbReporter())));
}
 
Example 5
Source File: AbstractMetricGroupTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testScopeCachingForMultipleReporters() throws Exception {
	Configuration config = new Configuration();
	config.setString(MetricOptions.SCOPE_NAMING_TM, "A.B.C.D");

	MetricConfig metricConfig1 = new MetricConfig();
	metricConfig1.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");

	MetricConfig metricConfig2 = new MetricConfig();
	metricConfig2.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "!");

	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter1.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter2.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "!");

	MetricRegistryImpl testRegistry = new MetricRegistryImpl(
		MetricRegistryConfiguration.fromConfiguration(config),
		Arrays.asList(
			ReporterSetup.forReporter("test1", metricConfig1, new TestReporter1()),
			ReporterSetup.forReporter("test2", metricConfig2, new TestReporter2())));
	try {
		MetricGroup tmGroup = new TaskManagerMetricGroup(testRegistry, "host", "id");
		tmGroup.counter("1");
		assertEquals("Reporters were not properly instantiated", 2, testRegistry.getReporters().size());
		for (MetricReporter reporter : testRegistry.getReporters()) {
			ScopeCheckingTestReporter typedReporter = (ScopeCheckingTestReporter) reporter;
			if (typedReporter.failureCause != null) {
				throw typedReporter.failureCause;
			}
		}
	} finally {
		testRegistry.shutdown().get();
	}
}
 
Example 6
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigurableDelimiterForReporters() throws Exception {
	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");

	MetricRegistryImpl registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Arrays.asList(
			ReporterSetup.forReporter("test1", config1, new TestReporter()),
			ReporterSetup.forReporter("test2", config2, new TestReporter()),
			ReporterSetup.forReporter("test3", config3, new TestReporter())));

	assertEquals(GLOBAL_DEFAULT_DELIMITER, registry.getDelimiter());
	assertEquals('_', registry.getDelimiter(0));
	assertEquals('-', registry.getDelimiter(1));
	assertEquals(GLOBAL_DEFAULT_DELIMITER, registry.getDelimiter(2));
	assertEquals(GLOBAL_DEFAULT_DELIMITER, registry.getDelimiter(3));
	assertEquals(GLOBAL_DEFAULT_DELIMITER, registry.getDelimiter(-1));

	registry.shutdown().get();
}
 
Example 7
Source File: InfluxdbReporterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private MetricRegistryImpl createMetricRegistry(String retentionPolicy, InfluxDB.ConsistencyLevel consistencyLevel) {
	MetricConfig metricConfig = new MetricConfig();
	metricConfig.setProperty(InfluxdbReporterOptions.HOST.key(), "localhost");
	metricConfig.setProperty(InfluxdbReporterOptions.PORT.key(), String.valueOf(wireMockRule.port()));
	metricConfig.setProperty(InfluxdbReporterOptions.DB.key(), TEST_INFLUXDB_DB);
	metricConfig.setProperty(InfluxdbReporterOptions.RETENTION_POLICY.key(), retentionPolicy);
	metricConfig.setProperty(InfluxdbReporterOptions.CONSISTENCY.key(), consistencyLevel.name());

	return new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Collections.singletonList(ReporterSetup.forReporter("test", metricConfig, new InfluxdbReporter())));
}
 
Example 8
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testConfigurableDelimiterForReportersInGroup() throws Exception {
	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, TestReporter8.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, TestReporter8.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, TestReporter8.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test4." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter8.class.getName());

	MetricRegistryImpl registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.fromConfiguration(config),
		Arrays.asList(
			ReporterSetup.forReporter("test1", config1, new TestReporter8()),
			ReporterSetup.forReporter("test2", config2, new TestReporter8()),
			ReporterSetup.forReporter("test3", config3, new TestReporter8()),
			ReporterSetup.forReporter("test4", new TestReporter8())));

	List<MetricReporter> reporters = registry.getReporters();
	((TestReporter8) reporters.get(0)).expectedDelimiter = '_'; //test1  reporter
	((TestReporter8) reporters.get(1)).expectedDelimiter = '-'; //test2 reporter
	((TestReporter8) reporters.get(2)).expectedDelimiter = GLOBAL_DEFAULT_DELIMITER; //test3 reporter, because 'AA' - not correct delimiter
	((TestReporter8) reporters.get(3)).expectedDelimiter = GLOBAL_DEFAULT_DELIMITER; //for test4 reporter use global delimiter

	TaskManagerMetricGroup group = new TaskManagerMetricGroup(registry, "host", "id");
	group.counter("C");
	group.close();
	registry.shutdown().get();
	assertEquals(4, TestReporter8.numCorrectDelimitersForRegister);
	assertEquals(4, TestReporter8.numCorrectDelimitersForUnregister);
}
 
Example 9
Source File: StatsDReporterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
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();
		ReporterSetup.forReporter("test", config, reporter);
		MetricGroup metricGroup = new UnregisteredMetricsGroup();

		reporter.notifyOfAddedMetric(metric, metricName, metricGroup);
		reporter.report();

		receiver.waitUntilNumLines(expectation.size(), timeout);
		assertEquals(expectation, receiver.getLines());

	} finally {
		if (reporter != null) {
			reporter.close();
		}

		if (receiver != null) {
			receiver.stop();
		}

		if (receiverThread != null) {
			receiverThread.join(joinTimeout);
		}
	}
}
 
Example 10
Source File: PrometheusReporterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
static ReporterSetup createReporterSetup(String reporterName, String portString) {
	MetricConfig metricConfig = new MetricConfig();
	metricConfig.setProperty(ARG_PORT, portString);

	return ReporterSetup.forReporter(reporterName, metricConfig, new PrometheusReporter());
}
 
Example 11
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testConfigurableDelimiterForReportersInGroup() throws Exception {
	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, TestReporter8.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, TestReporter8.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, TestReporter8.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test4." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter8.class.getName());

	MetricRegistryImpl registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.fromConfiguration(config),
		Arrays.asList(
			ReporterSetup.forReporter("test1", config1, new TestReporter8()),
			ReporterSetup.forReporter("test2", config2, new TestReporter8()),
			ReporterSetup.forReporter("test3", config3, new TestReporter8()),
			ReporterSetup.forReporter("test4", new TestReporter8())));

	List<MetricReporter> reporters = registry.getReporters();
	((TestReporter8) reporters.get(0)).expectedDelimiter = '_'; //test1  reporter
	((TestReporter8) reporters.get(1)).expectedDelimiter = '-'; //test2 reporter
	((TestReporter8) reporters.get(2)).expectedDelimiter = GLOBAL_DEFAULT_DELIMITER; //test3 reporter, because 'AA' - not correct delimiter
	((TestReporter8) reporters.get(3)).expectedDelimiter = GLOBAL_DEFAULT_DELIMITER; //for test4 reporter use global delimiter

	TaskManagerMetricGroup group = new TaskManagerMetricGroup(registry, "host", "id");
	group.counter("C");
	group.close();
	registry.shutdown().get();
	assertEquals(4, TestReporter8.numCorrectDelimitersForRegister);
	assertEquals(4, TestReporter8.numCorrectDelimitersForUnregister);
}
 
Example 12
Source File: StatsDReporterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
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();
		ReporterSetup.forReporter("test", config, reporter);
		MetricGroup metricGroup = new UnregisteredMetricsGroup();

		reporter.notifyOfAddedMetric(metric, metricName, metricGroup);
		reporter.report();

		receiver.waitUntilNumLines(expectation.size(), timeout);
		assertEquals(expectation, receiver.getLines());

	} finally {
		if (reporter != null) {
			reporter.close();
		}

		if (receiver != null) {
			receiver.stop();
		}

		if (receiverThread != null) {
			receiverThread.join(joinTimeout);
		}
	}
}
 
Example 13
Source File: PrometheusReporterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
static ReporterSetup createReporterSetup(String reporterName, String portString) {
	MetricConfig metricConfig = new MetricConfig();
	metricConfig.setProperty(ARG_PORT, portString);

	return ReporterSetup.forReporter(reporterName, metricConfig, new PrometheusReporter());
}