Java Code Examples for org.apache.flink.runtime.metrics.MetricRegistryConfiguration#defaultMetricRegistryConfiguration()

The following examples show how to use org.apache.flink.runtime.metrics.MetricRegistryConfiguration#defaultMetricRegistryConfiguration() . 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: JobManagerGroupTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testCloseClosesAll() throws Exception {
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.defaultMetricRegistryConfiguration());
	final JobManagerMetricGroup group = new JobManagerMetricGroup(registry, "localhost");

	final JobID jid1 = new JobID();
	final JobID jid2 = new JobID();

	final String jobName1 = "testjob";
	final String jobName2 = "anotherJob";

	JobManagerJobMetricGroup jmJobGroup11 = group.addJob(new JobGraph(jid1, jobName1));
	JobManagerJobMetricGroup jmJobGroup21 = group.addJob(new JobGraph(jid2, jobName2));

	group.close();

	assertTrue(jmJobGroup11.isClosed());
	assertTrue(jmJobGroup21.isClosed());

	registry.shutdown().get();
}
 
Example 2
Source File: JobManagerJobGroupTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateScopeDefault() throws Exception {
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.defaultMetricRegistryConfiguration());

	JobManagerMetricGroup tmGroup = new JobManagerMetricGroup(registry, "theHostName");
	JobMetricGroup jmGroup = new JobManagerJobMetricGroup(registry, tmGroup, new JobID(), "myJobName");

	assertArrayEquals(
			new String[] { "theHostName", "jobmanager", "myJobName"},
			jmGroup.getScopeComponents());

	assertEquals(
			"theHostName.jobmanager.myJobName.name",
			jmGroup.getMetricIdentifier("name"));

	registry.shutdown().get();
}
 
Example 3
Source File: JobManagerGroupTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCloseClosesAll() throws Exception {
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.defaultMetricRegistryConfiguration());
	final JobManagerMetricGroup group = new JobManagerMetricGroup(registry, "localhost");

	final JobID jid1 = new JobID();
	final JobID jid2 = new JobID();

	final String jobName1 = "testjob";
	final String jobName2 = "anotherJob";

	JobManagerJobMetricGroup jmJobGroup11 = group.addJob(new JobGraph(jid1, jobName1));
	JobManagerJobMetricGroup jmJobGroup21 = group.addJob(new JobGraph(jid2, jobName2));

	group.close();

	assertTrue(jmJobGroup11.isClosed());
	assertTrue(jmJobGroup21.isClosed());

	registry.shutdown().get();
}
 
Example 4
Source File: JobManagerJobGroupTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateScopeDefault() throws Exception {
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.defaultMetricRegistryConfiguration());

	JobManagerMetricGroup tmGroup = new JobManagerMetricGroup(registry, "theHostName");
	JobMetricGroup jmGroup = new JobManagerJobMetricGroup(registry, tmGroup, new JobID(), "myJobName");

	assertArrayEquals(
			new String[] { "theHostName", "jobmanager", "myJobName"},
			jmGroup.getScopeComponents());

	assertEquals(
			"theHostName.jobmanager.myJobName.name",
			jmGroup.getMetricIdentifier("name"));

	registry.shutdown().get();
}
 
Example 5
Source File: JobManagerJobGroupTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateQueryServiceMetricInfo() {
	JobID jid = new JobID();
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.defaultMetricRegistryConfiguration());
	JobManagerMetricGroup jm = new JobManagerMetricGroup(registry, "host");
	JobManagerJobMetricGroup jmj = new JobManagerJobMetricGroup(registry, jm, jid, "jobname");

	QueryScopeInfo.JobQueryScopeInfo info = jmj.createQueryServiceMetricInfo(new DummyCharacterFilter());
	assertEquals("", info.scope);
	assertEquals(jid.toString(), info.jobID);
}
 
Example 6
Source File: PrometheusReporterTaskScopeTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Before
public void setupReporter() {
	registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Collections.singletonList(createReporterSetup("test1", "9400-9500")));
	reporter = (PrometheusReporter) registry.getReporters().get(0);

	TaskManagerMetricGroup tmMetricGroup = new TaskManagerMetricGroup(registry, TASK_MANAGER_HOST, TASK_MANAGER_ID);
	TaskManagerJobMetricGroup tmJobMetricGroup = new TaskManagerJobMetricGroup(registry, tmMetricGroup, jobId, JOB_NAME);
	taskMetricGroup1 = new TaskMetricGroup(registry, tmJobMetricGroup, taskId1, taskAttemptId1, TASK_NAME, SUBTASK_INDEX_1, ATTEMPT_NUMBER);
	taskMetricGroup2 = new TaskMetricGroup(registry, tmJobMetricGroup, taskId2, taskAttemptId2, TASK_NAME, SUBTASK_INDEX_2, ATTEMPT_NUMBER);
}
 
Example 7
Source File: JobManagerGroupTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenerateScopeDefault() throws Exception {
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.defaultMetricRegistryConfiguration());
	JobManagerMetricGroup group = new JobManagerMetricGroup(registry, "localhost");

	assertArrayEquals(new String[]{"localhost", "jobmanager"}, group.getScopeComponents());
	assertEquals("localhost.jobmanager.name", group.getMetricIdentifier("name"));

	registry.shutdown().get();
}
 
Example 8
Source File: PrometheusReporterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Before
public void setupReporter() {
	registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Collections.singletonList(createReporterSetup("test1", portRangeProvider.next())));
	metricGroup = new FrontMetricGroup<>(0, new TaskManagerMetricGroup(registry, HOST_NAME, TASK_MANAGER));
	reporter = (PrometheusReporter) registry.getReporters().get(0);
}
 
Example 9
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 10
Source File: JMXReporterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Verifies that multiple JMXReporters can be started on the same machine and register metrics at the MBeanServer.
 *
 * @throws Exception if the attribute/mbean could not be found or the test is broken
 */
@Test
public void testPortConflictHandling() throws Exception {
	ReporterSetup reporterSetup1 = ReporterSetup.forReporter("test1", new JMXReporter("9020-9035"));
	ReporterSetup reporterSetup2 = ReporterSetup.forReporter("test2", new JMXReporter("9020-9035"));

	MetricRegistryImpl reg = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Arrays.asList(reporterSetup1, reporterSetup2));

	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<>(createReporterScopedSettings(0), mg));
	rep2.notifyOfAddedMetric(g2, "rep2", new FrontMetricGroup<>(createReporterScopedSettings(0), mg));

	MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

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

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

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

	mg.close();
	reg.shutdown().get();
}
 
Example 11
Source File: OperatorGroupTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	registry = new MetricRegistryImpl(MetricRegistryConfiguration.defaultMetricRegistryConfiguration());
}
 
Example 12
Source File: TaskMetricGroupTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	registry = new MetricRegistryImpl(MetricRegistryConfiguration.defaultMetricRegistryConfiguration());
}
 
Example 13
Source File: JMXReporterTest.java    From flink 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 {
	ReporterSetup reporterSetup1 = ReporterSetup.forReporter("test1", new JMXReporter("9040-9055"));
	ReporterSetup reporterSetup2 = ReporterSetup.forReporter("test2", new JMXReporter("9040-9055"));

	MetricRegistryImpl reg = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Arrays.asList(reporterSetup1, reporterSetup2));

	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().get() + "/jndi/rmi://localhost:" + ((JMXReporter) rep1).getPort().get() + "/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().get() + "/jndi/rmi://localhost:" + ((JMXReporter) rep2).getPort().get() + "/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 14
Source File: TaskExecutorOperatorEventHandlingTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	rpcService = new TestingRpcService();
	metricRegistry = new MetricRegistryImpl(MetricRegistryConfiguration.defaultMetricRegistryConfiguration());
	metricRegistry.startQueryService(rpcService, new ResourceID("mqs"));
}
 
Example 15
Source File: TaskMetricGroupTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	registry = new MetricRegistryImpl(MetricRegistryConfiguration.defaultMetricRegistryConfiguration());
}
 
Example 16
Source File: TaskMetricGroupTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	registry = new MetricRegistryImpl(MetricRegistryConfiguration.defaultMetricRegistryConfiguration());
}
 
Example 17
Source File: TaskManagerJobGroupTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	registry = new MetricRegistryImpl(MetricRegistryConfiguration.defaultMetricRegistryConfiguration());
}
 
Example 18
Source File: MetricGroupRegistrationTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Verifies that group methods instantiate the correct metric with the given name.
 */
@Test
public void testMetricInstantiation() throws Exception {
	MetricRegistryImpl registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Collections.singletonList(ReporterSetup.forReporter("test", new TestReporter1())));

	MetricGroup root = new TaskManagerMetricGroup(registry, "host", "id");

	Counter counter = root.counter("counter");
	assertEquals(counter, TestReporter1.lastPassedMetric);
	assertEquals("counter", TestReporter1.lastPassedName);

	Gauge<Object> gauge = root.gauge("gauge", new Gauge<Object>() {
		@Override
		public Object getValue() {
			return null;
		}
	});

	Assert.assertEquals(gauge, TestReporter1.lastPassedMetric);
	assertEquals("gauge", TestReporter1.lastPassedName);

	Histogram histogram = root.histogram("histogram", new Histogram() {
		@Override
		public void update(long value) {

		}

		@Override
		public long getCount() {
			return 0;
		}

		@Override
		public HistogramStatistics getStatistics() {
			return null;
		}
	});

	Assert.assertEquals(histogram, TestReporter1.lastPassedMetric);
	assertEquals("histogram", TestReporter1.lastPassedName);
	registry.shutdown().get();
}
 
Example 19
Source File: JobManagerGroupTest.java    From flink with Apache License 2.0 3 votes vote down vote up
@Test
public void addAndRemoveJobs() throws Exception {
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.defaultMetricRegistryConfiguration());
	final JobManagerMetricGroup group = new JobManagerMetricGroup(registry, "localhost");

	final JobID jid1 = new JobID();
	final JobID jid2 = new JobID();

	final String jobName1 = "testjob";
	final String jobName2 = "anotherJob";

	JobManagerJobMetricGroup jmJobGroup11 = group.addJob(new JobGraph(jid1, jobName1));
	JobManagerJobMetricGroup jmJobGroup12 = group.addJob(new JobGraph(jid1, jobName1));
	JobManagerJobMetricGroup jmJobGroup21 = group.addJob(new JobGraph(jid2, jobName2));

	assertEquals(jmJobGroup11, jmJobGroup12);

	assertEquals(2, group.numRegisteredJobMetricGroups());

	group.removeJob(jid1);

	assertTrue(jmJobGroup11.isClosed());
	assertEquals(1, group.numRegisteredJobMetricGroups());

	group.removeJob(jid2);

	assertTrue(jmJobGroup21.isClosed());
	assertEquals(0, group.numRegisteredJobMetricGroups());

	registry.shutdown().get();
}
 
Example 20
Source File: JobManagerGroupTest.java    From Flink-CEPplus with Apache License 2.0 3 votes vote down vote up
@Test
public void addAndRemoveJobs() throws Exception {
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.defaultMetricRegistryConfiguration());
	final JobManagerMetricGroup group = new JobManagerMetricGroup(registry, "localhost");

	final JobID jid1 = new JobID();
	final JobID jid2 = new JobID();

	final String jobName1 = "testjob";
	final String jobName2 = "anotherJob";

	JobManagerJobMetricGroup jmJobGroup11 = group.addJob(new JobGraph(jid1, jobName1));
	JobManagerJobMetricGroup jmJobGroup12 = group.addJob(new JobGraph(jid1, jobName1));
	JobManagerJobMetricGroup jmJobGroup21 = group.addJob(new JobGraph(jid2, jobName2));

	assertEquals(jmJobGroup11, jmJobGroup12);

	assertEquals(2, group.numRegisteredJobMetricGroups());

	group.removeJob(jid1);

	assertTrue(jmJobGroup11.isClosed());
	assertEquals(1, group.numRegisteredJobMetricGroups());

	group.removeJob(jid2);

	assertTrue(jmJobGroup21.isClosed());
	assertEquals(0, group.numRegisteredJobMetricGroups());

	registry.shutdown().get();
}