org.apache.flink.runtime.metrics.MetricRegistryImpl Java Examples

The following examples show how to use org.apache.flink.runtime.metrics.MetricRegistryImpl. 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: JobManagerJobGroupTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateScopeCustom() throws Exception {
	Configuration cfg = new Configuration();
	cfg.setString(MetricOptions.SCOPE_NAMING_JM, "abc");
	cfg.setString(MetricOptions.SCOPE_NAMING_JM_JOB, "some-constant.<job_name>");
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(cfg));

	JobID jid = new JobID();

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

	assertArrayEquals(
			new String[] { "some-constant", "myJobName" },
			jmGroup.getScopeComponents());

	assertEquals(
			"some-constant.myJobName.name",
			jmGroup.getMetricIdentifier("name"));

	registry.shutdown().get();
}
 
Example #2
Source File: TaskMetricGroupTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateScopeWilcard() throws Exception {
	Configuration cfg = new Configuration();
	cfg.setString(MetricOptions.SCOPE_NAMING_TASK, "*.<task_attempt_id>.<subtask_index>");
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(cfg));

	AbstractID executionId = new AbstractID();

	TaskManagerMetricGroup tmGroup = new TaskManagerMetricGroup(registry, "theHostName", "test-tm-id");
	TaskManagerJobMetricGroup jmGroup = new TaskManagerJobMetricGroup(registry, tmGroup, new JobID(), "myJobName");

	TaskMetricGroup taskGroup = new TaskMetricGroup(
			registry, jmGroup, new JobVertexID(), executionId, "aTaskName", 13, 1);

	assertArrayEquals(
			new String[]{"theHostName", "taskmanager", "test-tm-id", "myJobName", executionId.toString(), "13"},
			taskGroup.getScopeComponents());

	assertEquals(
			"theHostName.taskmanager.test-tm-id.myJobName." + executionId + ".13.name",
			taskGroup.getMetricIdentifier("name"));
	registry.shutdown().get();
}
 
Example #3
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 #4
Source File: TaskMetricGroupTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testOperatorNameTruncation() throws Exception {
	Configuration cfg = new Configuration();
	cfg.setString(MetricOptions.SCOPE_NAMING_OPERATOR, ScopeFormat.SCOPE_OPERATOR_NAME);
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(cfg));
	TaskManagerMetricGroup tm = new TaskManagerMetricGroup(registry, "host", "id");
	TaskManagerJobMetricGroup job = new TaskManagerJobMetricGroup(registry, tm, new JobID(), "jobname");
	TaskMetricGroup taskMetricGroup = new TaskMetricGroup(registry, job, new JobVertexID(), new AbstractID(), "task", 0, 0);

	String originalName = new String(new char[100]).replace("\0", "-");
	OperatorMetricGroup operatorMetricGroup = taskMetricGroup.getOrAddOperator(originalName);

	String storedName = operatorMetricGroup.getScopeComponents()[0];
	Assert.assertEquals(TaskMetricGroup.METRICS_OPERATOR_NAME_MAX_LENGTH, storedName.length());
	Assert.assertEquals(originalName.substring(0, TaskMetricGroup.METRICS_OPERATOR_NAME_MAX_LENGTH), storedName);
	registry.shutdown().get();
}
 
Example #5
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 #6
Source File: TaskManagerJobGroupTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateScopeCustomWildcard() throws Exception {
	Configuration cfg = new Configuration();
	cfg.setString(MetricOptions.SCOPE_NAMING_TM, "peter.<tm_id>");
	cfg.setString(MetricOptions.SCOPE_NAMING_TM_JOB, "*.some-constant.<job_id>");
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(cfg));

	JobID jid = new JobID();

	TaskManagerMetricGroup tmGroup = new TaskManagerMetricGroup(registry, "theHostName", "test-tm-id");
	JobMetricGroup jmGroup = new TaskManagerJobMetricGroup(registry, tmGroup, jid, "myJobName");

	assertArrayEquals(
			new String[] { "peter", "test-tm-id", "some-constant", jid.toString() },
			jmGroup.getScopeComponents());

	assertEquals(
			"peter.test-tm-id.some-constant." + jid + ".name",
			jmGroup.getMetricIdentifier("name"));
	registry.shutdown().get();
}
 
Example #7
Source File: TaskManagerJobGroupTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateScopeCustom() throws Exception {
	Configuration cfg = new Configuration();
	cfg.setString(MetricOptions.SCOPE_NAMING_TM, "abc");
	cfg.setString(MetricOptions.SCOPE_NAMING_TM_JOB, "some-constant.<job_name>");
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(cfg));

	JobID jid = new JobID();

	TaskManagerMetricGroup tmGroup = new TaskManagerMetricGroup(registry, "theHostName", "test-tm-id");
	JobMetricGroup jmGroup = new TaskManagerJobMetricGroup(registry, tmGroup, jid, "myJobName");

	assertArrayEquals(
			new String[] { "some-constant", "myJobName" },
			jmGroup.getScopeComponents());

	assertEquals(
			"some-constant.myJobName.name",
			jmGroup.getMetricIdentifier("name"));
	registry.shutdown().get();
}
 
Example #8
Source File: JobManagerJobGroupTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateScopeCustomWildcard() throws Exception {
	Configuration cfg = new Configuration();
	cfg.setString(MetricOptions.SCOPE_NAMING_JM, "peter");
	cfg.setString(MetricOptions.SCOPE_NAMING_JM_JOB, "*.some-constant.<job_id>");
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(cfg));

	JobID jid = new JobID();

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

	assertArrayEquals(
			new String[] { "peter", "some-constant", jid.toString() },
			jmGroup.getScopeComponents());

	assertEquals(
			"peter.some-constant." + jid + ".name",
			jmGroup.getMetricIdentifier("name"));

	registry.shutdown().get();
}
 
Example #9
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 #10
Source File: AbstractMetricGroupTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testScopeGenerationWithoutReporters() throws Exception {
	Configuration config = new Configuration();
	config.setString(MetricOptions.SCOPE_NAMING_TM, "A.B.C.D");
	MetricRegistryImpl testRegistry = new MetricRegistryImpl(
		MetricRegistryConfiguration.fromConfiguration(config));

	try {
		TaskManagerMetricGroup group = new TaskManagerMetricGroup(testRegistry, "host", "id");
		assertEquals("MetricReporters list should be empty", 0, testRegistry.getReporters().size());

		// default delimiter should be used
		assertEquals("A.B.X.D.1", group.getMetricIdentifier("1", FILTER_C));
		// no caching should occur
		assertEquals("A.X.C.D.1", group.getMetricIdentifier("1", FILTER_B));
		// invalid reporter indices do not throw errors
		assertEquals("A.X.C.D.1", group.getMetricIdentifier("1", FILTER_B, -1));
		assertEquals("A.X.C.D.1", group.getMetricIdentifier("1", FILTER_B, 2));
	} finally {
		testRegistry.shutdown().get();
	}
}
 
Example #11
Source File: MetricGroupRegistrationTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that when attempting to create a group with the name of an existing one the existing one will be returned instead.
 */
@Test
public void testDuplicateGroupName() throws Exception {
	Configuration config = new Configuration();

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

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

	MetricGroup group1 = root.addGroup("group");
	MetricGroup group2 = root.addGroup("group");
	MetricGroup group3 = root.addGroup("group");
	Assert.assertTrue(group1 == group2 && group2 == group3);

	registry.shutdown().get();
}
 
Example #12
Source File: JobManagerJobGroupTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateScopeCustom() throws Exception {
	Configuration cfg = new Configuration();
	cfg.setString(MetricOptions.SCOPE_NAMING_JM, "abc");
	cfg.setString(MetricOptions.SCOPE_NAMING_JM_JOB, "some-constant.<job_name>");
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(cfg));

	JobID jid = new JobID();

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

	assertArrayEquals(
			new String[] { "some-constant", "myJobName" },
			jmGroup.getScopeComponents());

	assertEquals(
			"some-constant.myJobName.name",
			jmGroup.getMetricIdentifier("name"));

	registry.shutdown().get();
}
 
Example #13
Source File: TaskManagerJobGroupTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateScopeCustomWildcard() throws Exception {
	Configuration cfg = new Configuration();
	cfg.setString(MetricOptions.SCOPE_NAMING_TM, "peter.<tm_id>");
	cfg.setString(MetricOptions.SCOPE_NAMING_TM_JOB, "*.some-constant.<job_id>");
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(cfg));

	JobID jid = new JobID();

	TaskManagerMetricGroup tmGroup = new TaskManagerMetricGroup(registry, "theHostName", "test-tm-id");
	JobMetricGroup jmGroup = new TaskManagerJobMetricGroup(registry, tmGroup, jid, "myJobName");

	assertArrayEquals(
			new String[] { "peter", "test-tm-id", "some-constant", jid.toString() },
			jmGroup.getScopeComponents());

	assertEquals(
			"peter.test-tm-id.some-constant." + jid + ".name",
			jmGroup.getMetricIdentifier("name"));
	registry.shutdown().get();
}
 
Example #14
Source File: TaskMetricGroupTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testOperatorNameTruncation() throws Exception {
	Configuration cfg = new Configuration();
	cfg.setString(MetricOptions.SCOPE_NAMING_OPERATOR, ScopeFormat.SCOPE_OPERATOR_NAME);
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(cfg));
	TaskManagerMetricGroup tm = new TaskManagerMetricGroup(registry, "host", "id");
	TaskManagerJobMetricGroup job = new TaskManagerJobMetricGroup(registry, tm, new JobID(), "jobname");
	TaskMetricGroup taskMetricGroup = new TaskMetricGroup(registry, job, new JobVertexID(), new AbstractID(), "task", 0, 0);

	String originalName = new String(new char[100]).replace("\0", "-");
	OperatorMetricGroup operatorMetricGroup = taskMetricGroup.getOrAddOperator(originalName);

	String storedName = operatorMetricGroup.getScopeComponents()[0];
	Assert.assertEquals(TaskMetricGroup.METRICS_OPERATOR_NAME_MAX_LENGTH, storedName.length());
	Assert.assertEquals(originalName.substring(0, TaskMetricGroup.METRICS_OPERATOR_NAME_MAX_LENGTH), storedName);
	registry.shutdown().get();
}
 
Example #15
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 #16
Source File: MetricGroupRegistrationTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that when attempting to create a group with the name of an existing one the existing one will be returned instead.
 */
@Test
public void testDuplicateGroupName() throws Exception {
	Configuration config = new Configuration();

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

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

	MetricGroup group1 = root.addGroup("group");
	MetricGroup group2 = root.addGroup("group");
	MetricGroup group3 = root.addGroup("group");
	Assert.assertTrue(group1 == group2 && group2 == group3);

	registry.shutdown().get();
}
 
Example #17
Source File: JobManagerJobGroupTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateScopeCustomWildcard() throws Exception {
	Configuration cfg = new Configuration();
	cfg.setString(MetricOptions.SCOPE_NAMING_JM, "peter");
	cfg.setString(MetricOptions.SCOPE_NAMING_JM_JOB, "*.some-constant.<job_id>");
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(cfg));

	JobID jid = new JobID();

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

	assertArrayEquals(
			new String[] { "peter", "some-constant", jid.toString() },
			jmGroup.getScopeComponents());

	assertEquals(
			"peter.some-constant." + jid + ".name",
			jmGroup.getMetricIdentifier("name"));

	registry.shutdown().get();
}
 
Example #18
Source File: TaskMetricGroupTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateScopeWilcard() throws Exception {
	Configuration cfg = new Configuration();
	cfg.setString(MetricOptions.SCOPE_NAMING_TASK, "*.<task_attempt_id>.<subtask_index>");
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(cfg));

	AbstractID executionId = new AbstractID();

	TaskManagerMetricGroup tmGroup = new TaskManagerMetricGroup(registry, "theHostName", "test-tm-id");
	TaskManagerJobMetricGroup jmGroup = new TaskManagerJobMetricGroup(registry, tmGroup, new JobID(), "myJobName");

	TaskMetricGroup taskGroup = new TaskMetricGroup(
			registry, jmGroup, new JobVertexID(), executionId, "aTaskName", 13, 1);

	assertArrayEquals(
			new String[]{"theHostName", "taskmanager", "test-tm-id", "myJobName", executionId.toString(), "13"},
			taskGroup.getScopeComponents());

	assertEquals(
			"theHostName.taskmanager.test-tm-id.myJobName." + executionId + ".13.name",
			taskGroup.getMetricIdentifier("name"));
	registry.shutdown().get();
}
 
Example #19
Source File: AbstractMetricGroupTest.java    From Flink-CEPplus with Apache License 2.0 6 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");
	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));
	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 #20
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 #21
Source File: AbstractMetricGroupTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testScopeGenerationWithoutReporters() throws Exception {
	Configuration config = new Configuration();
	config.setString(MetricOptions.SCOPE_NAMING_TM, "A.B.C.D");
	MetricRegistryImpl testRegistry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(config));

	try {
		TaskManagerMetricGroup group = new TaskManagerMetricGroup(testRegistry, "host", "id");
		assertEquals("MetricReporters list should be empty", 0, testRegistry.getReporters().size());

		// default delimiter should be used
		assertEquals("A.B.X.D.1", group.getMetricIdentifier("1", FILTER_C));
		// no caching should occur
		assertEquals("A.X.C.D.1", group.getMetricIdentifier("1", FILTER_B));
		// invalid reporter indices do not throw errors
		assertEquals("A.X.C.D.1", group.getMetricIdentifier("1", FILTER_B, -1));
		assertEquals("A.X.C.D.1", group.getMetricIdentifier("1", FILTER_B, 2));
	} finally {
		testRegistry.shutdown().get();
	}
}
 
Example #22
Source File: TaskManagerJobGroupTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateScopeCustom() throws Exception {
	Configuration cfg = new Configuration();
	cfg.setString(MetricOptions.SCOPE_NAMING_TM, "abc");
	cfg.setString(MetricOptions.SCOPE_NAMING_TM_JOB, "some-constant.<job_name>");
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(cfg));

	JobID jid = new JobID();

	TaskManagerMetricGroup tmGroup = new TaskManagerMetricGroup(registry, "theHostName", "test-tm-id");
	JobMetricGroup jmGroup = new TaskManagerJobMetricGroup(registry, tmGroup, jid, "myJobName");

	assertArrayEquals(
			new String[] { "some-constant", "myJobName" },
			jmGroup.getScopeComponents());

	assertEquals(
			"some-constant.myJobName.name",
			jmGroup.getMetricIdentifier("name"));
	registry.shutdown().get();
}
 
Example #23
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 #24
Source File: AbstractMetricGroupTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testLogicalScopeCachingForMultipleReporters() throws Exception {
	MetricRegistryImpl testRegistry = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Arrays.asList(
			ReporterSetup.forReporter("test1", new LogicalScopeReporter1()),
			ReporterSetup.forReporter("test2", new LogicalScopeReporter2())));
	try {
		MetricGroup tmGroup = new TaskManagerMetricGroup(testRegistry, "host", "id")
			.addGroup("B")
			.addGroup("C");
		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 #25
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 #26
Source File: TaskMetricGroupTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testOperatorNameTruncation() throws Exception {
	Configuration cfg = new Configuration();
	cfg.setString(MetricOptions.SCOPE_NAMING_OPERATOR, ScopeFormat.SCOPE_OPERATOR_NAME);
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(cfg));
	TaskManagerMetricGroup tm = new TaskManagerMetricGroup(registry, "host", "id");
	TaskManagerJobMetricGroup job = new TaskManagerJobMetricGroup(registry, tm, new JobID(), "jobname");
	TaskMetricGroup taskMetricGroup = new TaskMetricGroup(registry, job, new JobVertexID(), new AbstractID(), "task", 0, 0);

	String originalName = new String(new char[100]).replace("\0", "-");
	OperatorMetricGroup operatorMetricGroup = taskMetricGroup.getOrAddOperator(originalName);

	String storedName = operatorMetricGroup.getScopeComponents()[0];
	Assert.assertEquals(TaskMetricGroup.METRICS_OPERATOR_NAME_MAX_LENGTH, storedName.length());
	Assert.assertEquals(originalName.substring(0, TaskMetricGroup.METRICS_OPERATOR_NAME_MAX_LENGTH), storedName);
	registry.shutdown().get();
}
 
Example #27
Source File: MetricGroupTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateQueryServiceMetricInfo() {
	JobID jid = new JobID();
	JobVertexID vid = new JobVertexID();
	AbstractID eid = new AbstractID();
	MetricRegistryImpl registry = new MetricRegistryImpl(defaultMetricRegistryConfiguration);
	TaskManagerMetricGroup tm = new TaskManagerMetricGroup(registry, "host", "id");
	TaskManagerJobMetricGroup job = new TaskManagerJobMetricGroup(registry, tm, jid, "jobname");
	TaskMetricGroup task = new TaskMetricGroup(registry, job, vid, eid, "taskName", 4, 5);
	GenericMetricGroup userGroup1 = new GenericMetricGroup(registry, task, "hello");
	GenericMetricGroup userGroup2 = new GenericMetricGroup(registry, userGroup1, "world");

	QueryScopeInfo.TaskQueryScopeInfo info1 = (QueryScopeInfo.TaskQueryScopeInfo) userGroup1.createQueryServiceMetricInfo(new DummyCharacterFilter());
	assertEquals("hello", info1.scope);
	assertEquals(jid.toString(), info1.jobID);
	assertEquals(vid.toString(), info1.vertexID);
	assertEquals(4, info1.subtaskIndex);

	QueryScopeInfo.TaskQueryScopeInfo info2 = (QueryScopeInfo.TaskQueryScopeInfo) userGroup2.createQueryServiceMetricInfo(new DummyCharacterFilter());
	assertEquals("hello.world", info2.scope);
	assertEquals(jid.toString(), info2.jobID);
	assertEquals(vid.toString(), info2.vertexID);
	assertEquals(4, info2.subtaskIndex);
}
 
Example #28
Source File: MesosResourceManagerTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
MockResourceManagerRuntimeServices() throws Exception {
	highAvailabilityServices = new TestingHighAvailabilityServices();
	rmLeaderElectionService = new TestingLeaderElectionService();
	highAvailabilityServices.setResourceManagerLeaderElectionService(rmLeaderElectionService);
	heartbeatServices = new HeartbeatServices(5L, 5L);
	metricRegistry = mock(MetricRegistryImpl.class);
	slotManager = mock(SlotManager.class);
	slotManagerStarted = new CompletableFuture<>();
	jobLeaderIdService = new JobLeaderIdService(
		highAvailabilityServices,
		rpcService.getScheduledExecutor(),
		Time.minutes(5L));

	doAnswer(new Answer<Object>() {
		@Override
		public Object answer(InvocationOnMock invocation) throws Throwable {
			rmActions = invocation.getArgument(2);
			slotManagerStarted.complete(true);
			return null;
		}
	}).when(slotManager).start(any(ResourceManagerId.class), any(Executor.class), any(ResourceActions.class));

	when(slotManager.registerSlotRequest(any(SlotRequest.class))).thenReturn(true);
}
 
Example #29
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 #30
Source File: MesosResourceManagerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
MockResourceManagerRuntimeServices() throws Exception {
	highAvailabilityServices = new TestingHighAvailabilityServices();
	rmLeaderElectionService = new TestingLeaderElectionService();
	highAvailabilityServices.setResourceManagerLeaderElectionService(rmLeaderElectionService);
	heartbeatServices = new HeartbeatServices(5L, 5L);
	metricRegistry = mock(MetricRegistryImpl.class);
	slotManager = mock(SlotManager.class);
	slotManagerStarted = new CompletableFuture<>();
	jobLeaderIdService = new JobLeaderIdService(
		highAvailabilityServices,
		rpcService.getScheduledExecutor(),
		Time.minutes(5L));

	doAnswer(new Answer<Object>() {
		@Override
		public Object answer(InvocationOnMock invocation) throws Throwable {
			rmActions = invocation.getArgument(2);
			slotManagerStarted.complete(true);
			return null;
		}
	}).when(slotManager).start(any(ResourceManagerId.class), any(Executor.class), any(ResourceActions.class));

	when(slotManager.registerSlotRequest(any(SlotRequest.class))).thenReturn(true);
}