org.apache.flink.configuration.MetricOptions Java Examples

The following examples show how to use org.apache.flink.configuration.MetricOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #2
Source File: AggregatingMetricsHandlerTestBase.java    From Flink-CEPplus with 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 #3
Source File: MetricRegistryImplTest.java    From Flink-CEPplus with 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 #4
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 #5
Source File: MetricRegistryImplTest.java    From flink with 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 #6
Source File: Slf4jReporterTest.java    From Flink-CEPplus with 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 #7
Source File: TaskMetricGroupTest.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, "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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
Source File: ReporterSetupTest.java    From flink with 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 #15
Source File: MetricUtilsTest.java    From flink with 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 #16
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 #17
Source File: AggregatingMetricsHandlerTestBase.java    From flink with 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 #18
Source File: StreamSourceOperatorLatencyMetricsTest.java    From flink with 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 #19
Source File: StreamSourceOperatorLatencyMetricsTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that latency metrics can be disabled via the {@link ExecutionConfig} even if they are enabled via
 * the configuration.
 */
@Test
public void testLatencyMarkEmissionDisabledOverrideViaExecutionConfig() throws Exception {
	testLatencyMarkEmission(0, (operator, timeProvider) -> {
		Configuration tmConfig = new Configuration();
		tmConfig.setLong(MetricOptions.LATENCY_INTERVAL, latencyMarkInterval);

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

		ExecutionConfig executionConfig = new ExecutionConfig();
		executionConfig.setLatencyTrackingInterval(0);

		setupSourceOperator(operator, executionConfig, env, timeProvider);
	});
}
 
Example #20
Source File: LatencyStatsTest.java    From flink with 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 #21
Source File: Slf4jReporterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() {
	TestUtils.addTestAppenderForRootLogger();

	Configuration configuration = new Configuration();
	configuration.setString(MetricOptions.SCOPE_NAMING_TASK, "<host>.<tm_id>.<job_name>");

	registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.fromConfiguration(configuration),
		Collections.singletonList(ReporterSetup.forReporter("slf4j", new Slf4jReporter())));
	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 #22
Source File: StreamSourceOperatorLatencyMetricsTest.java    From flink with 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 #23
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 #24
Source File: MetricRegistryImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
private static Duration getConfiguredIntervalOrDefault(ReporterSetup reporterSetup) {
	final Optional<String> configuredPeriod = reporterSetup.getIntervalSettings();
	Duration period = MetricOptions.REPORTER_INTERVAL.defaultValue();

	if (configuredPeriod.isPresent()) {
		try {
			period = TimeUtils.parseDuration(configuredPeriod.get());
		}
		catch (Exception e) {
			LOG.error("Cannot parse report interval from config: " + configuredPeriod +
				" - please use values like '10 SECONDS' or '500 MILLISECONDS'. " +
				"Using default reporting interval.");
		}
	}
	return period;
}
 
Example #25
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 #26
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testReporterIntervalParsingErrorFallsBackToDefaultValue() throws Exception {
	MetricConfig config = new MetricConfig();
	// in a prior implementation the time amount was applied even if the time unit was invalid
	// in this case this would imply using 1 SECOND as the interval (seconds is the default)
	config.setProperty(ConfigConstants.METRICS_REPORTER_INTERVAL_SUFFIX, "1 UNICORN");

	final ManuallyTriggeredScheduledExecutorService manuallyTriggeredScheduledExecutorService = new ManuallyTriggeredScheduledExecutorService();

	MetricRegistryImpl registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Collections.singletonList(ReporterSetup.forReporter("test", config, new TestReporter3())),
		manuallyTriggeredScheduledExecutorService);
	try {
		Collection<ScheduledFuture<?>> scheduledTasks = manuallyTriggeredScheduledExecutorService.getScheduledTasks();
		ScheduledFuture<?> reportTask = Iterators.getOnlyElement(scheduledTasks.iterator());
		Assert.assertEquals(MetricOptions.REPORTER_INTERVAL.defaultValue().getSeconds(), reportTask.getDelay(TimeUnit.SECONDS));
	} finally {
		registry.shutdown().get();
	}
}
 
Example #27
Source File: TaskMetricGroupTest.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, "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 #28
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 #29
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 #30
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();
}