org.apache.flink.runtime.metrics.util.TestReporter Java Examples

The following examples show how to use org.apache.flink.runtime.metrics.util.TestReporter. 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: MetricGroupTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that calling {@link AbstractMetricGroup#getLogicalScope(CharacterFilter, char, int)} on {@link GenericValueMetricGroup}
 * should ignore value as well.
 */
@Test
public void testLogicalScopeShouldIgnoreValueGroupName() throws Exception {
	Configuration config = new Configuration();
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter.class.getName());

	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(config));
	try {
		GenericMetricGroup root = new GenericMetricGroup(registry, new DummyAbstractMetricGroup(registry), "root");

		String key = "key";
		String value = "value";

		MetricGroup group = root.addGroup(key, value);

		String logicalScope = ((AbstractMetricGroup) group)
			.getLogicalScope(new DummyCharacterFilter(), registry.getDelimiter(), 0);
		assertThat("Key is missing from logical scope.", logicalScope, containsString(key));
		assertThat("Value is present in logical scope.", logicalScope, not(containsString(value)));
	} finally {
		registry.shutdown().get();
	}
}
 
Example #2
Source File: MetricRegistryImplTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigurableDelimiterForReporters() throws Exception {
	Configuration config = new Configuration();
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "_");
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter.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, TestReporter.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, TestReporter.class.getName());

	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(config));

	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 #3
Source File: MetricGroupTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that calling {@link AbstractMetricGroup#getLogicalScope(CharacterFilter, char, int)} on {@link GenericValueMetricGroup}
 * should ignore value as well.
 */
@Test
public void testLogicalScopeShouldIgnoreValueGroupName() throws Exception {
	Configuration config = new Configuration();
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter.class.getName());

	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(config));
	try {
		GenericMetricGroup root = new GenericMetricGroup(registry, new DummyAbstractMetricGroup(registry), "root");

		String key = "key";
		String value = "value";

		MetricGroup group = root.addGroup(key, value);

		String logicalScope = ((AbstractMetricGroup) group)
			.getLogicalScope(new DummyCharacterFilter(), registry.getDelimiter(), 0);
		assertThat("Key is missing from logical scope.", logicalScope, containsString(key));
		assertThat("Value is present in logical scope.", logicalScope, not(containsString(value)));
	} finally {
		registry.shutdown().get();
	}
}
 
Example #4
Source File: MetricGroupTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that calling {@link AbstractMetricGroup#getLogicalScope(CharacterFilter, char, int)} on {@link GenericValueMetricGroup}
 * should ignore value as well.
 */
@Test
public void testLogicalScopeShouldIgnoreValueGroupName() throws Exception {
	Configuration config = new Configuration();
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter.class.getName());

	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(config));
	try {
		GenericMetricGroup root = new GenericMetricGroup(registry, new DummyAbstractMetricGroup(registry), "root");

		String key = "key";
		String value = "value";

		MetricGroup group = root.addGroup(key, value);

		String logicalScope = ((AbstractMetricGroup) group)
			.getLogicalScope(new DummyCharacterFilter(), registry.getDelimiter(), 0);
		assertThat("Key is missing from logical scope.", logicalScope, containsString(key));
		assertThat("Value is present in logical scope.", logicalScope, not(containsString(value)));
	} finally {
		registry.shutdown().get();
	}
}
 
Example #5
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 #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: JMXReporterTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Verifies that we can connect to multiple JMXReporters running on the same machine.
 *
 * @throws Exception
 */
@Test
public void testJMXAvailability() throws Exception {
	Configuration cfg = new Configuration();
	cfg.setString(ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter.class.getName());

	cfg.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, JMXReporter.class.getName());
	cfg.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1.port", "9040-9055");

	cfg.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, JMXReporter.class.getName());
	cfg.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2.port", "9040-9055");

	MetricRegistryImpl reg = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(cfg));

	TaskManagerMetricGroup mg = new TaskManagerMetricGroup(reg, "host", "tm");

	List<MetricReporter> reporters = reg.getReporters();

	assertTrue(reporters.size() == 2);

	MetricReporter rep1 = reporters.get(0);
	MetricReporter rep2 = reporters.get(1);

	Gauge<Integer> g1 = new Gauge<Integer>() {
		@Override
		public Integer getValue() {
			return 1;
		}
	};
	Gauge<Integer> g2 = new Gauge<Integer>() {
		@Override
		public Integer getValue() {
			return 2;
		}
	};

	rep1.notifyOfAddedMetric(g1, "rep1", new FrontMetricGroup<>(0, new TaskManagerMetricGroup(reg, "host", "tm")));

	rep2.notifyOfAddedMetric(g2, "rep2", new FrontMetricGroup<>(1, new TaskManagerMetricGroup(reg, "host", "tm")));

	ObjectName objectName1 = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager.rep1", JMXReporter.generateJmxTable(mg.getAllVariables()));
	ObjectName objectName2 = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager.rep2", JMXReporter.generateJmxTable(mg.getAllVariables()));

	JMXServiceURL url1 = new JMXServiceURL("service:jmx:rmi://localhost:" + ((JMXReporter) rep1).getPort() + "/jndi/rmi://localhost:" + ((JMXReporter) rep1).getPort() + "/jmxrmi");
	JMXConnector jmxCon1 = JMXConnectorFactory.connect(url1);
	MBeanServerConnection mCon1 = jmxCon1.getMBeanServerConnection();

	assertEquals(1, mCon1.getAttribute(objectName1, "Value"));
	assertEquals(2, mCon1.getAttribute(objectName2, "Value"));

	jmxCon1.close();

	JMXServiceURL url2 = new JMXServiceURL("service:jmx:rmi://localhost:" + ((JMXReporter) rep2).getPort() + "/jndi/rmi://localhost:" + ((JMXReporter) rep2).getPort() + "/jmxrmi");
	JMXConnector jmxCon2 = JMXConnectorFactory.connect(url2);
	MBeanServerConnection mCon2 = jmxCon2.getMBeanServerConnection();

	assertEquals(1, mCon2.getAttribute(objectName1, "Value"));
	assertEquals(2, mCon2.getAttribute(objectName2, "Value"));

	rep1.notifyOfRemovedMetric(g1, "rep1", null);
	rep1.notifyOfRemovedMetric(g2, "rep2", null);

	jmxCon2.close();

	rep1.close();
	rep2.close();
	mg.close();
	reg.shutdown().get();
}
 
Example #8
Source File: ReporterSetupTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public MetricReporter createMetricReporter(Properties config) {
	lastConfig = config;
	return new TestReporter();
}
 
Example #9
Source File: ReporterSetupTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public MetricReporter createMetricReporter(Properties config) {
	lastConfig = config;
	return new TestReporter();
}