Java Code Examples for org.apache.flink.configuration.MetricOptions

The following examples show how to use org.apache.flink.configuration.MetricOptions. These examples are extracted from open source projects. 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 Project: Flink-CEPplus   Author: ljygz   File: MetricFetcherImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
public static <T extends RestfulGateway> MetricFetcherImpl<T> fromConfiguration(
		final Configuration configuration,
		final MetricQueryServiceRetriever metricQueryServiceRetriever,
		final GatewayRetriever<T> dispatcherGatewayRetriever,
		final ExecutorService executor) {
	final Time timeout = Time.milliseconds(configuration.getLong(WebOptions.TIMEOUT));
	final long updateInterval = configuration.getLong(MetricOptions.METRIC_FETCHER_UPDATE_INTERVAL);

	return new MetricFetcherImpl<>(
		dispatcherGatewayRetriever,
		metricQueryServiceRetriever,
		executor,
		timeout,
		updateInterval);
}
 
Example #2
Source Project: Flink-CEPplus   Author: ljygz   File: MetricRegistryConfigurationTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that {@link MetricOptions#REPORTERS_LIST} is correctly used to filter configured reporters.
 */
@Test
public void testActivateOneReporterAmongTwoDeclared() {
	final Configuration config = new Configuration();

	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "reporter1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter1.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "reporter1.arg1", "value1");
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "reporter1.arg2", "value2");

	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "reporter2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter2.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "reporter2.arg1", "value1");
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "reporter2.arg3", "value3");

	config.setString(MetricOptions.REPORTERS_LIST, "reporter2");

	final MetricRegistryConfiguration metricRegistryConfiguration = MetricRegistryConfiguration.fromConfiguration(config);

	Assert.assertEquals(1, metricRegistryConfiguration.getReporterConfigurations().size());

	final Tuple2<String, Configuration> stringConfigurationTuple = metricRegistryConfiguration.getReporterConfigurations().get(0);
	Assert.assertEquals("reporter2", stringConfigurationTuple.f0);
	Assert.assertEquals("reporter2", stringConfigurationTuple.f0);
	Assert.assertEquals("value1", stringConfigurationTuple.f1.getString("arg1", null));
	Assert.assertEquals("value3", stringConfigurationTuple.f1.getString("arg3", null));
	Assert.assertEquals(TestReporter2.class.getName(), stringConfigurationTuple.f1.getString("class", null));
}
 
Example #3
Source Project: Flink-CEPplus   Author: ljygz   File: TaskMetricGroupTest.java    License: 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, "def");
	cfg.setString(MetricOptions.SCOPE_NAMING_TASK, "<tm_id>.<job_id>.<task_id>.<task_attempt_id>");
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(cfg));

	JobID jid = new JobID();
	JobVertexID vertexId = new JobVertexID();
	AbstractID executionId = new AbstractID();

	TaskManagerMetricGroup tmGroup = new TaskManagerMetricGroup(registry, "theHostName", "test-tm-id");
	TaskManagerJobMetricGroup jmGroup = new TaskManagerJobMetricGroup(registry, tmGroup, jid, "myJobName");
	TaskMetricGroup taskGroup = new TaskMetricGroup(
			registry, jmGroup, vertexId, executionId, "aTaskName", 13, 2);

	assertArrayEquals(
			new String[]{"test-tm-id", jid.toString(), vertexId.toString(), executionId.toString()},
			taskGroup.getScopeComponents());

	assertEquals(
			String.format("test-tm-id.%s.%s.%s.name", jid, vertexId, executionId),
			taskGroup.getMetricIdentifier("name"));
	registry.shutdown().get();
}
 
Example #4
Source Project: Flink-CEPplus   Author: ljygz   File: TaskMetricGroupTest.java    License: 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 #5
Source Project: Flink-CEPplus   Author: ljygz   File: TaskMetricGroupTest.java    License: 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 #6
Source Project: flink   Author: apache   File: MetricUtilsTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the {@link MetricUtils#startRemoteMetricsRpcService(Configuration, String)} respects
 * the given {@link MetricOptions#QUERY_SERVICE_THREAD_PRIORITY}.
 */
@Test
public void testStartMetricActorSystemRespectsThreadPriority() throws Exception {
	final Configuration configuration = new Configuration();
	final int expectedThreadPriority = 3;
	configuration.setInteger(MetricOptions.QUERY_SERVICE_THREAD_PRIORITY, expectedThreadPriority);

	final RpcService rpcService = MetricUtils.startRemoteMetricsRpcService(configuration, "localhost");
	assertThat(rpcService, instanceOf(AkkaRpcService.class));

	final ActorSystem actorSystem = ((AkkaRpcService) rpcService).getActorSystem();

	try {
		final int threadPriority = actorSystem.settings().config().getInt("akka.actor.default-dispatcher.thread-priority");

		assertThat(threadPriority, is(expectedThreadPriority));
	} finally {
		AkkaUtils.terminateActorSystem(actorSystem).get();
	}
}
 
Example #7
Source Project: Flink-CEPplus   Author: ljygz   File: TaskManagerJobGroupTest.java    License: 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 #8
Source Project: Flink-CEPplus   Author: ljygz   File: JobManagerJobGroupTest.java    License: 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 #9
Source Project: flink   Author: apache   File: JobManagerJobGroupTest.java    License: 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 #10
Source Project: Flink-CEPplus   Author: ljygz   File: AbstractMetricGroupTest.java    License: 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 #11
Source Project: Flink-CEPplus   Author: ljygz   File: AbstractMetricGroupTest.java    License: 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 #12
Source Project: Flink-CEPplus   Author: ljygz   File: MetricUtilsTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the {@link MetricUtils#startMetricsActorSystem(Configuration, String, Logger)} respects
 * the given {@link MetricOptions#QUERY_SERVICE_THREAD_PRIORITY}.
 */
@Test
public void testStartMetricActorSystemRespectsThreadPriority() throws Exception {
	final Configuration configuration = new Configuration();
	final int expectedThreadPriority = 3;
	configuration.setInteger(MetricOptions.QUERY_SERVICE_THREAD_PRIORITY, expectedThreadPriority);
	final ActorSystem actorSystem = MetricUtils.startMetricsActorSystem(configuration, "localhost", LOG);

	try {
		final int threadPriority = actorSystem.settings().config().getInt("akka.actor.default-dispatcher.thread-priority");

		assertThat(threadPriority, is(expectedThreadPriority));
	} finally {
		AkkaUtils.terminateActorSystem(actorSystem).get();
	}
}
 
Example #13
Source Project: Flink-CEPplus   Author: ljygz   File: MetricRegistryImplTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that the scope configuration is properly extracted.
 */
@Test
public void testScopeConfig() {
	Configuration config = new Configuration();

	config.setString(MetricOptions.SCOPE_NAMING_TM, "A");
	config.setString(MetricOptions.SCOPE_NAMING_TM_JOB, "B");
	config.setString(MetricOptions.SCOPE_NAMING_TASK, "C");
	config.setString(MetricOptions.SCOPE_NAMING_OPERATOR, "D");

	ScopeFormats scopeConfig = ScopeFormats.fromConfig(config);

	assertEquals("A", scopeConfig.getTaskManagerFormat().format());
	assertEquals("B", scopeConfig.getTaskManagerJobFormat().format());
	assertEquals("C", scopeConfig.getTaskFormat().format());
	assertEquals("D", scopeConfig.getOperatorFormat().format());
}
 
Example #14
Source Project: Flink-CEPplus   Author: ljygz   File: MetricRegistryImplTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigurableDelimiterForReportersInGroup() 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, 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());
	config.setString(MetricOptions.SCOPE_NAMING_TM, "A.B");

	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(config));
	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 #15
Source Project: Flink-CEPplus   Author: ljygz   File: AggregatingMetricsHandlerTestBase.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
	MetricFetcher fetcher = new MetricFetcherImpl<RestfulGateway>(
		mock(GatewayRetriever.class),
		mock(MetricQueryServiceRetriever.class),
		Executors.directExecutor(),
		TestingUtils.TIMEOUT(),
		MetricOptions.METRIC_FETCHER_UPDATE_INTERVAL.defaultValue());
	store = fetcher.getMetricStore();

	Collection<MetricDump> metricDumps = getMetricDumps();
	for (MetricDump dump : metricDumps) {
		store.add(dump);
	}

	handler = getHandler(
		LEADER_RETRIEVER,
		TIMEOUT,
		TEST_HEADERS,
		EXECUTOR,
		fetcher);
	pathParameters = getPathParameters();
}
 
Example #16
Source Project: Flink-CEPplus   Author: ljygz   File: StreamSourceOperatorLatencyMetricsTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that latency metrics can be enabled via the {@link ExecutionConfig} even if they are disabled via
 * the configuration.
 */
@Test
public void testLatencyMarkEmissionEnabledOverrideViaExecutionConfig() throws Exception {
	testLatencyMarkEmission((int) (maxProcessingTime / latencyMarkInterval) + 1, (operator, timeProvider) -> {
		ExecutionConfig executionConfig = new ExecutionConfig();
		executionConfig.setLatencyTrackingInterval(latencyMarkInterval);

		Configuration tmConfig = new Configuration();
		tmConfig.setLong(MetricOptions.LATENCY_INTERVAL, 0L);

		Environment env = MockEnvironment.builder()
			.setTaskManagerRuntimeInfo(new TestingTaskManagerRuntimeInfo(tmConfig))
			.build();

		setupSourceOperator(operator, executionConfig, env, timeProvider);
	});
}
 
Example #17
Source Project: Flink-CEPplus   Author: ljygz   File: LatencyStatsTest.java    License: Apache License 2.0 6 votes vote down vote up
private static void testLatencyStats(
	final LatencyStats.Granularity granularity,
	final Consumer<List<Tuple2<String, Histogram>>> verifier) {

	final AbstractMetricGroup<?> dummyGroup = UnregisteredMetricGroups.createUnregisteredOperatorMetricGroup();
	final TestMetricRegistry registry = new TestMetricRegistry();
	final MetricGroup parentGroup = new GenericMetricGroup(registry, dummyGroup, PARENT_GROUP_NAME);

	final LatencyStats latencyStats = new LatencyStats(
		parentGroup,
		MetricOptions.LATENCY_HISTORY_SIZE.defaultValue(),
		OPERATOR_SUBTASK_INDEX,
		OPERATOR_ID,
		granularity);

	latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_1, 0));
	latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_1, 0));
	latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_1, 1));
	latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_2, 2));
	latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_2, 3));

	verifier.accept(registry.latencyHistograms);
}
 
Example #18
Source Project: flink   Author: apache   File: MetricRegistryImplTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that the scope configuration is properly extracted.
 */
@Test
public void testScopeConfig() {
	Configuration config = new Configuration();

	config.setString(MetricOptions.SCOPE_NAMING_TM, "A");
	config.setString(MetricOptions.SCOPE_NAMING_TM_JOB, "B");
	config.setString(MetricOptions.SCOPE_NAMING_TASK, "C");
	config.setString(MetricOptions.SCOPE_NAMING_OPERATOR, "D");

	ScopeFormats scopeConfig = ScopeFormats.fromConfig(config);

	assertEquals("A", scopeConfig.getTaskManagerFormat().format());
	assertEquals("B", scopeConfig.getTaskManagerJobFormat().format());
	assertEquals("C", scopeConfig.getTaskFormat().format());
	assertEquals("D", scopeConfig.getOperatorFormat().format());
}
 
Example #19
Source Project: Flink-CEPplus   Author: ljygz   File: Slf4jReporterTest.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() {
	TestUtils.addTestAppenderForRootLogger();

	Configuration configuration = new Configuration();
	configuration.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "slf4j." +
		ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, Slf4jReporter.class.getName());
	configuration.setString(MetricOptions.SCOPE_NAMING_TASK, "<host>.<tm_id>.<job_name>");

	registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(configuration));
	delimiter = registry.getDelimiter();

	taskMetricGroup = new TaskManagerMetricGroup(registry, HOST_NAME, TASK_MANAGER_ID)
		.addTaskForJob(new JobID(), JOB_NAME, new JobVertexID(), new ExecutionAttemptID(), TASK_NAME, 0, 0);
	reporter = (Slf4jReporter) registry.getReporters().get(0);
}
 
Example #20
Source Project: flink   Author: flink-tpc-ds   File: TaskMetricGroupTest.java    License: 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, "def");
	cfg.setString(MetricOptions.SCOPE_NAMING_TASK, "<tm_id>.<job_id>.<task_id>.<task_attempt_id>");
	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(cfg));

	JobID jid = new JobID();
	JobVertexID vertexId = new JobVertexID();
	AbstractID executionId = new AbstractID();

	TaskManagerMetricGroup tmGroup = new TaskManagerMetricGroup(registry, "theHostName", "test-tm-id");
	TaskManagerJobMetricGroup jmGroup = new TaskManagerJobMetricGroup(registry, tmGroup, jid, "myJobName");
	TaskMetricGroup taskGroup = new TaskMetricGroup(
			registry, jmGroup, vertexId, executionId, "aTaskName", 13, 2);

	assertArrayEquals(
			new String[]{"test-tm-id", jid.toString(), vertexId.toString(), executionId.toString()},
			taskGroup.getScopeComponents());

	assertEquals(
			String.format("test-tm-id.%s.%s.%s.name", jid, vertexId, executionId),
			taskGroup.getMetricIdentifier("name"));
	registry.shutdown().get();
}
 
Example #21
Source Project: flink   Author: flink-tpc-ds   File: TaskMetricGroupTest.java    License: 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 #22
Source Project: flink   Author: flink-tpc-ds   File: TaskMetricGroupTest.java    License: 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 #23
Source Project: flink   Author: flink-tpc-ds   File: TaskManagerJobGroupTest.java    License: 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 #24
Source Project: flink   Author: flink-tpc-ds   File: TaskManagerJobGroupTest.java    License: 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 #25
Source Project: flink   Author: flink-tpc-ds   File: JobManagerJobGroupTest.java    License: 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 #26
Source Project: flink   Author: flink-tpc-ds   File: JobManagerJobGroupTest.java    License: 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 #27
Source Project: flink   Author: flink-tpc-ds   File: AbstractMetricGroupTest.java    License: 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 #28
Source Project: flink   Author: flink-tpc-ds   File: ReporterSetupTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that {@link MetricOptions#REPORTERS_LIST} is correctly used to filter configured reporters.
 */
@Test
public void testActivateOneReporterAmongTwoDeclared() {
	final Configuration config = new Configuration();

	configureReporter1(config);
	configureReporter2(config);

	config.setString(MetricOptions.REPORTERS_LIST, "reporter2");

	final List<ReporterSetup> reporterSetups = ReporterSetup.fromConfiguration(config);

	Assert.assertEquals(1, reporterSetups.size());

	final ReporterSetup setup = reporterSetups.get(0);
	assertReporter2Configured(setup);
}
 
Example #29
Source Project: flink   Author: flink-tpc-ds   File: MetricUtilsTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the {@link MetricUtils#startMetricsRpcService(Configuration, String)} respects
 * the given {@link MetricOptions#QUERY_SERVICE_THREAD_PRIORITY}.
 */
@Test
public void testStartMetricActorSystemRespectsThreadPriority() throws Exception {
	final Configuration configuration = new Configuration();
	final int expectedThreadPriority = 3;
	configuration.setInteger(MetricOptions.QUERY_SERVICE_THREAD_PRIORITY, expectedThreadPriority);

	final RpcService rpcService = MetricUtils.startMetricsRpcService(configuration, "localhost");
	assertThat(rpcService, instanceOf(AkkaRpcService.class));

	final ActorSystem actorSystem = ((AkkaRpcService) rpcService).getActorSystem();

	try {
		final int threadPriority = actorSystem.settings().config().getInt("akka.actor.default-dispatcher.thread-priority");

		assertThat(threadPriority, is(expectedThreadPriority));
	} finally {
		AkkaUtils.terminateActorSystem(actorSystem).get();
	}
}
 
Example #30
Source Project: flink   Author: flink-tpc-ds   File: MetricRegistryImplTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that the scope configuration is properly extracted.
 */
@Test
public void testScopeConfig() {
	Configuration config = new Configuration();

	config.setString(MetricOptions.SCOPE_NAMING_TM, "A");
	config.setString(MetricOptions.SCOPE_NAMING_TM_JOB, "B");
	config.setString(MetricOptions.SCOPE_NAMING_TASK, "C");
	config.setString(MetricOptions.SCOPE_NAMING_OPERATOR, "D");

	ScopeFormats scopeConfig = ScopeFormats.fromConfig(config);

	assertEquals("A", scopeConfig.getTaskManagerFormat().format());
	assertEquals("B", scopeConfig.getTaskManagerJobFormat().format());
	assertEquals("C", scopeConfig.getTaskFormat().format());
	assertEquals("D", scopeConfig.getOperatorFormat().format());
}