org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup Java Examples

The following examples show how to use org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup. 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: MetricUtils.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public static TaskManagerMetricGroup instantiateTaskManagerMetricGroup(
		MetricRegistry metricRegistry,
		TaskManagerLocation taskManagerLocation,
		NetworkEnvironment network,
		Optional<Time> systemResourceProbeInterval) {
	final TaskManagerMetricGroup taskManagerMetricGroup = new TaskManagerMetricGroup(
		metricRegistry,
		taskManagerLocation.getHostname(),
		taskManagerLocation.getResourceID().toString());

	MetricGroup statusGroup = taskManagerMetricGroup.addGroup(METRIC_GROUP_STATUS_NAME);

	// Initialize the TM metrics
	instantiateStatusMetrics(statusGroup);

	MetricGroup networkGroup = statusGroup
		.addGroup("Network");
	instantiateNetworkMetrics(networkGroup, network);

	if (systemResourceProbeInterval.isPresent()) {
		instantiateSystemMetrics(taskManagerMetricGroup, systemResourceProbeInterval.get());
	}
	return taskManagerMetricGroup;
}
 
Example #2
Source File: PrometheusReporterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void metricIsRemovedWhenCollectorIsNotUnregisteredYet() throws UnirestException {
	TaskManagerMetricGroup tmMetricGroup = new TaskManagerMetricGroup(registry, HOST_NAME, TASK_MANAGER);

	String metricName = "metric";

	Counter metric1 = new SimpleCounter();
	FrontMetricGroup<TaskManagerJobMetricGroup> metricGroup1 = new FrontMetricGroup<>(
		createReporterScopedSettings(),
		new TaskManagerJobMetricGroup(registry, tmMetricGroup, JobID.generate(), "job_1"));
	reporter.notifyOfAddedMetric(metric1, metricName, metricGroup1);

	Counter metric2 = new SimpleCounter();
	FrontMetricGroup<TaskManagerJobMetricGroup> metricGroup2 = new FrontMetricGroup<>(
		createReporterScopedSettings(),
		new TaskManagerJobMetricGroup(registry, tmMetricGroup, JobID.generate(), "job_2"));
	reporter.notifyOfAddedMetric(metric2, metricName, metricGroup2);

	reporter.notifyOfRemovedMetric(metric1, metricName, metricGroup1);

	String response = pollMetrics(reporter.getPort()).getBody();

	assertThat(response, not(containsString("job_1")));
}
 
Example #3
Source File: MetricUtils.java    From flink with Apache License 2.0 6 votes vote down vote up
public static Tuple2<TaskManagerMetricGroup, MetricGroup> instantiateTaskManagerMetricGroup(
		MetricRegistry metricRegistry,
		String hostName,
		ResourceID resourceID,
		Optional<Time> systemResourceProbeInterval) {
	final TaskManagerMetricGroup taskManagerMetricGroup = new TaskManagerMetricGroup(
		metricRegistry,
		hostName,
		resourceID.toString());

	MetricGroup statusGroup = createAndInitializeStatusMetricGroup(taskManagerMetricGroup);

	if (systemResourceProbeInterval.isPresent()) {
		instantiateSystemMetrics(taskManagerMetricGroup, systemResourceProbeInterval.get());
	}
	return Tuple2.of(taskManagerMetricGroup, statusGroup);
}
 
Example #4
Source File: PrometheusReporterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void metricIsRemovedWhenCollectorIsNotUnregisteredYet() throws UnirestException {
	TaskManagerMetricGroup tmMetricGroup = new TaskManagerMetricGroup(registry, HOST_NAME, TASK_MANAGER);

	String metricName = "metric";

	Counter metric1 = new SimpleCounter();
	FrontMetricGroup<TaskManagerJobMetricGroup> metricGroup1 = new FrontMetricGroup<>(0, new TaskManagerJobMetricGroup(registry, tmMetricGroup, JobID.generate(), "job_1"));
	reporter.notifyOfAddedMetric(metric1, metricName, metricGroup1);

	Counter metric2 = new SimpleCounter();
	FrontMetricGroup<TaskManagerJobMetricGroup> metricGroup2 = new FrontMetricGroup<>(0, new TaskManagerJobMetricGroup(registry, tmMetricGroup, JobID.generate(), "job_2"));
	reporter.notifyOfAddedMetric(metric2, metricName, metricGroup2);

	reporter.notifyOfRemovedMetric(metric1, metricName, metricGroup1);

	String response = pollMetrics(reporter.getPort()).getBody();

	assertThat(response, not(containsString("job_1")));
}
 
Example #5
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 #6
Source File: TestingTaskExecutor.java    From flink with Apache License 2.0 6 votes vote down vote up
public TestingTaskExecutor(
		RpcService rpcService,
		TaskManagerConfiguration taskManagerConfiguration,
		HighAvailabilityServices haServices,
		TaskManagerServices taskExecutorServices,
		HeartbeatServices heartbeatServices,
		TaskManagerMetricGroup taskManagerMetricGroup,
		@Nullable String metricQueryServiceAddress,
		BlobCacheService blobCacheService,
		FatalErrorHandler fatalErrorHandler,
		PartitionTable<JobID> partitionTable) {
	super(
		rpcService,
		taskManagerConfiguration,
		haServices,
		taskExecutorServices,
		heartbeatServices,
		taskManagerMetricGroup,
		metricQueryServiceAddress,
		blobCacheService,
		fatalErrorHandler,
		partitionTable);
}
 
Example #7
Source File: MetricUtils.java    From flink with Apache License 2.0 6 votes vote down vote up
public static Tuple2<TaskManagerMetricGroup, MetricGroup> instantiateTaskManagerMetricGroup(
		MetricRegistry metricRegistry,
		String hostName,
		ResourceID resourceID,
		Optional<Time> systemResourceProbeInterval) {
	final TaskManagerMetricGroup taskManagerMetricGroup = new TaskManagerMetricGroup(
		metricRegistry,
		hostName,
		resourceID.toString());

	MetricGroup statusGroup = taskManagerMetricGroup.addGroup(METRIC_GROUP_STATUS_NAME);

	// Initialize the TM metrics
	instantiateStatusMetrics(statusGroup);

	if (systemResourceProbeInterval.isPresent()) {
		instantiateSystemMetrics(taskManagerMetricGroup, systemResourceProbeInterval.get());
	}
	return Tuple2.of(taskManagerMetricGroup, statusGroup);
}
 
Example #8
Source File: PrometheusReporterTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void metricIsRemovedWhenCollectorIsNotUnregisteredYet() throws UnirestException {
	TaskManagerMetricGroup tmMetricGroup = new TaskManagerMetricGroup(registry, HOST_NAME, TASK_MANAGER);

	String metricName = "metric";

	Counter metric1 = new SimpleCounter();
	FrontMetricGroup<TaskManagerJobMetricGroup> metricGroup1 = new FrontMetricGroup<>(0, new TaskManagerJobMetricGroup(registry, tmMetricGroup, JobID.generate(), "job_1"));
	reporter.notifyOfAddedMetric(metric1, metricName, metricGroup1);

	Counter metric2 = new SimpleCounter();
	FrontMetricGroup<TaskManagerJobMetricGroup> metricGroup2 = new FrontMetricGroup<>(0, new TaskManagerJobMetricGroup(registry, tmMetricGroup, JobID.generate(), "job_2"));
	reporter.notifyOfAddedMetric(metric2, metricName, metricGroup2);

	reporter.notifyOfRemovedMetric(metric1, metricName, metricGroup1);

	String response = pollMetrics(reporter.getPort()).getBody();

	assertThat(response, not(containsString("job_1")));
}
 
Example #9
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 #10
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 #11
Source File: TestingTaskExecutor.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public TestingTaskExecutor(
		RpcService rpcService,
		TaskManagerConfiguration taskManagerConfiguration,
		HighAvailabilityServices haServices,
		TaskManagerServices taskExecutorServices,
		HeartbeatServices heartbeatServices,
		TaskManagerMetricGroup taskManagerMetricGroup,
		@Nullable String metricQueryServicePath,
		BlobCacheService blobCacheService,
		FatalErrorHandler fatalErrorHandler) {
	super(
		rpcService,
		taskManagerConfiguration,
		haServices,
		taskExecutorServices,
		heartbeatServices,
		taskManagerMetricGroup,
		metricQueryServicePath,
		blobCacheService,
		fatalErrorHandler);
}
 
Example #12
Source File: MetricRegistryImplTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that reporters are notified of added/removed metrics.
 */
@Test
public void testReporterNotifications() throws Exception {
	Configuration config = new Configuration();
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter6.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter7.class.getName());

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

	TaskManagerMetricGroup root = new TaskManagerMetricGroup(registry, "host", "id");
	root.counter("rootCounter");

	assertTrue(TestReporter6.addedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter6.addedMetricName);

	assertTrue(TestReporter7.addedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter7.addedMetricName);

	root.close();

	assertTrue(TestReporter6.removedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter6.removedMetricName);

	assertTrue(TestReporter7.removedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter7.removedMetricName);

	registry.shutdown().get();
}
 
Example #13
Source File: MetricQueryServiceTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateDump() throws Exception {
	MetricQueryService queryService = MetricQueryService.createMetricQueryService(rpcService, ResourceID.generate(), Long.MAX_VALUE);
	queryService.start();

	final Counter c = new SimpleCounter();
	final Gauge<String> g = () -> "Hello";
	final Histogram h = new TestHistogram();
	final Meter m = new TestMeter();

	final TaskManagerMetricGroup tm = UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup();

	queryService.addMetric("counter", c, tm);
	queryService.addMetric("gauge", g, tm);
	queryService.addMetric("histogram", h, tm);
	queryService.addMetric("meter", m, tm);

	MetricDumpSerialization.MetricSerializationResult dump = queryService.queryMetrics(TIMEOUT).get();

	assertTrue(dump.serializedCounters.length > 0);
	assertTrue(dump.serializedGauges.length > 0);
	assertTrue(dump.serializedHistograms.length > 0);
	assertTrue(dump.serializedMeters.length > 0);

	queryService.removeMetric(c);
	queryService.removeMetric(g);
	queryService.removeMetric(h);
	queryService.removeMetric(m);

	MetricDumpSerialization.MetricSerializationResult emptyDump = queryService.queryMetrics(TIMEOUT).get();

	assertEquals(0, emptyDump.serializedCounters.length);
	assertEquals(0, emptyDump.serializedGauges.length);
	assertEquals(0, emptyDump.serializedHistograms.length);
	assertEquals(0, emptyDump.serializedMeters.length);
}
 
Example #14
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that reporters are notified of added/removed metrics.
 */
@Test
public void testReporterNotifications() throws Exception {
	Configuration config = new Configuration();
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter6.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter7.class.getName());

	MetricRegistryImpl registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Arrays.asList(
			ReporterSetup.forReporter("test1", new TestReporter6()),
			ReporterSetup.forReporter("test2", new TestReporter7())));

	TaskManagerMetricGroup root = new TaskManagerMetricGroup(registry, "host", "id");
	root.counter("rootCounter");

	assertTrue(TestReporter6.addedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter6.addedMetricName);

	assertTrue(TestReporter7.addedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter7.addedMetricName);

	root.close();

	assertTrue(TestReporter6.removedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter6.removedMetricName);

	assertTrue(TestReporter7.removedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter7.removedMetricName);

	registry.shutdown().get();
}
 
Example #15
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigurableDelimiter() throws Exception {
	Configuration config = new Configuration();
	config.setString(MetricOptions.SCOPE_DELIMITER, "_");
	config.setString(MetricOptions.SCOPE_NAMING_TM, "A.B.C.D.E");

	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(config), ReporterSetup.fromConfiguration(config, null));

	TaskManagerMetricGroup tmGroup = new TaskManagerMetricGroup(registry, "host", "id");
	assertEquals("A_B_C_D_E_name", tmGroup.getMetricIdentifier("name"));

	registry.shutdown().get();
}
 
Example #16
Source File: TestingTaskExecutor.java    From flink with Apache License 2.0 5 votes vote down vote up
public TestingTaskExecutor(
		RpcService rpcService,
		TaskManagerConfiguration taskManagerConfiguration,
		HighAvailabilityServices haServices,
		TaskManagerServices taskExecutorServices,
		ExternalResourceInfoProvider externalResourceInfoProvider,
		HeartbeatServices heartbeatServices,
		TaskManagerMetricGroup taskManagerMetricGroup,
		@Nullable String metricQueryServiceAddress,
		BlobCacheService blobCacheService,
		FatalErrorHandler fatalErrorHandler,
		TaskExecutorPartitionTracker partitionTracker,
		BackPressureSampleService backPressureSampleService) {
	super(
		rpcService,
		taskManagerConfiguration,
		haServices,
		taskExecutorServices,
		externalResourceInfoProvider,
		heartbeatServices,
		taskManagerMetricGroup,
		metricQueryServiceAddress,
		blobCacheService,
		fatalErrorHandler,
		partitionTracker,
		backPressureSampleService);
}
 
Example #17
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigurableDelimiter() throws Exception {
	Configuration config = new Configuration();
	config.setString(MetricOptions.SCOPE_DELIMITER, "_");
	config.setString(MetricOptions.SCOPE_NAMING_TM, "A.B.C.D.E");

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

	TaskManagerMetricGroup tmGroup = new TaskManagerMetricGroup(registry, "host", "id");
	assertEquals("A_B_C_D_E_name", tmGroup.getMetricIdentifier("name"));

	registry.shutdown().get();
}
 
Example #18
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that reporters are notified of added/removed metrics.
 */
@Test
public void testReporterNotifications() throws Exception {
	Configuration config = new Configuration();
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter6.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter7.class.getName());

	MetricRegistryImpl registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Arrays.asList(
			ReporterSetup.forReporter("test1", new TestReporter6()),
			ReporterSetup.forReporter("test2", new TestReporter7())));

	TaskManagerMetricGroup root = new TaskManagerMetricGroup(registry, "host", "id");
	root.counter("rootCounter");

	assertTrue(TestReporter6.addedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter6.addedMetricName);

	assertTrue(TestReporter7.addedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter7.addedMetricName);

	root.close();

	assertTrue(TestReporter6.removedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter6.removedMetricName);

	assertTrue(TestReporter7.removedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter7.removedMetricName);

	registry.shutdown().get();
}
 
Example #19
Source File: PrometheusReporterTaskScopeTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Before
public void setupReporter() {
	registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Collections.singletonList(createReporterSetup("test1", "9400-9500")));
	reporter = (PrometheusReporter) registry.getReporters().get(0);

	TaskManagerMetricGroup tmMetricGroup = new TaskManagerMetricGroup(registry, TASK_MANAGER_HOST, TASK_MANAGER_ID);
	TaskManagerJobMetricGroup tmJobMetricGroup = new TaskManagerJobMetricGroup(registry, tmMetricGroup, jobId, JOB_NAME);
	taskMetricGroup1 = new TaskMetricGroup(registry, tmJobMetricGroup, taskId1, taskAttemptId1, TASK_NAME, SUBTASK_INDEX_1, ATTEMPT_NUMBER);
	taskMetricGroup2 = new TaskMetricGroup(registry, tmJobMetricGroup, taskId2, taskAttemptId2, TASK_NAME, SUBTASK_INDEX_2, ATTEMPT_NUMBER);
}
 
Example #20
Source File: MetricQueryServiceTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateDump() throws Exception {
	MetricQueryService queryService = MetricQueryService.createMetricQueryService(rpcService, ResourceID.generate(), Long.MAX_VALUE);
	queryService.start();

	final Counter c = new SimpleCounter();
	final Gauge<String> g = () -> "Hello";
	final Histogram h = new TestHistogram();
	final Meter m = new TestMeter();

	final TaskManagerMetricGroup tm = UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup();

	queryService.addMetric("counter", c, tm);
	queryService.addMetric("gauge", g, tm);
	queryService.addMetric("histogram", h, tm);
	queryService.addMetric("meter", m, tm);

	MetricDumpSerialization.MetricSerializationResult dump = queryService.queryMetrics(TIMEOUT).get();

	assertTrue(dump.serializedCounters.length > 0);
	assertTrue(dump.serializedGauges.length > 0);
	assertTrue(dump.serializedHistograms.length > 0);
	assertTrue(dump.serializedMeters.length > 0);

	queryService.removeMetric(c);
	queryService.removeMetric(g);
	queryService.removeMetric(h);
	queryService.removeMetric(m);

	MetricDumpSerialization.MetricSerializationResult emptyDump = queryService.queryMetrics(TIMEOUT).get();

	assertEquals(0, emptyDump.serializedCounters.length);
	assertEquals(0, emptyDump.serializedGauges.length);
	assertEquals(0, emptyDump.serializedHistograms.length);
	assertEquals(0, emptyDump.serializedMeters.length);
}
 
Example #21
Source File: PrometheusReporterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Before
public void setupReporter() {
	registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Collections.singletonList(createReporterSetup("test1", portRangeProvider.next())));
	metricGroup = new FrontMetricGroup<>(0, new TaskManagerMetricGroup(registry, HOST_NAME, TASK_MANAGER));
	reporter = (PrometheusReporter) registry.getReporters().get(0);
}
 
Example #22
Source File: Slf4jReporterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() {
	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 #23
Source File: TaskManagerJobScopeFormat.java    From flink with Apache License 2.0 5 votes vote down vote up
public String[] formatScope(TaskManagerMetricGroup parent, JobID jid, String jobName) {
	final String[] template = copyTemplate();
	final String[] values = {
			parent.hostname(),
			parent.taskManagerId(),
			valueOrNull(jid),
			valueOrNull(jobName)
	};
	return bindVariables(template, values);
}
 
Example #24
Source File: MetricRegistryImplTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigurableDelimiter() throws Exception {
	Configuration config = new Configuration();
	config.setString(MetricOptions.SCOPE_DELIMITER, "_");
	config.setString(MetricOptions.SCOPE_NAMING_TM, "A.B.C.D.E");

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

	TaskManagerMetricGroup tmGroup = new TaskManagerMetricGroup(registry, "host", "id");
	assertEquals("A_B_C_D_E_name", tmGroup.getMetricIdentifier("name"));

	registry.shutdown().get();
}
 
Example #25
Source File: PrometheusReporterTaskScopeTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Before
public void setupReporter() {
	registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(createConfigWithOneReporter("test1", "9400-9500")));
	reporter = (PrometheusReporter) registry.getReporters().get(0);

	TaskManagerMetricGroup tmMetricGroup = new TaskManagerMetricGroup(registry, TASK_MANAGER_HOST, TASK_MANAGER_ID);
	TaskManagerJobMetricGroup tmJobMetricGroup = new TaskManagerJobMetricGroup(registry, tmMetricGroup, jobId, JOB_NAME);
	taskMetricGroup1 = new TaskMetricGroup(registry, tmJobMetricGroup, taskId1, taskAttemptId1, TASK_NAME, SUBTASK_INDEX_1, ATTEMPT_NUMBER);
	taskMetricGroup2 = new TaskMetricGroup(registry, tmJobMetricGroup, taskId2, taskAttemptId2, TASK_NAME, SUBTASK_INDEX_2, ATTEMPT_NUMBER);
}
 
Example #26
Source File: PrometheusReporterTaskScopeTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Before
public void setupReporter() {
	registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Collections.singletonList(createReporterSetup("test1", "9400-9500")));
	reporter = (PrometheusReporter) registry.getReporters().get(0);

	TaskManagerMetricGroup tmMetricGroup = new TaskManagerMetricGroup(registry, TASK_MANAGER_HOST, TASK_MANAGER_ID);
	TaskManagerJobMetricGroup tmJobMetricGroup = new TaskManagerJobMetricGroup(registry, tmMetricGroup, jobId, JOB_NAME);
	taskMetricGroup1 = new TaskMetricGroup(registry, tmJobMetricGroup, taskId1, taskAttemptId1, TASK_NAME, SUBTASK_INDEX_1, ATTEMPT_NUMBER);
	taskMetricGroup2 = new TaskMetricGroup(registry, tmJobMetricGroup, taskId2, taskAttemptId2, TASK_NAME, SUBTASK_INDEX_2, ATTEMPT_NUMBER);
}
 
Example #27
Source File: PrometheusReporterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Before
public void setupReporter() {
	registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Collections.singletonList(createReporterSetup("test1", portRangeProvider.next())));
	metricGroup = new FrontMetricGroup<>(
		createReporterScopedSettings(),
		new TaskManagerMetricGroup(registry, HOST_NAME, TASK_MANAGER));
	reporter = (PrometheusReporter) registry.getReporters().get(0);
}
 
Example #28
Source File: TaskManagerJobScopeFormat.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public String[] formatScope(TaskManagerMetricGroup parent, JobID jid, String jobName) {
	final String[] template = copyTemplate();
	final String[] values = {
			parent.hostname(),
			parent.taskManagerId(),
			valueOrNull(jid),
			valueOrNull(jobName)
	};
	return bindVariables(template, values);
}
 
Example #29
Source File: TaskManagerJobScopeFormat.java    From flink with Apache License 2.0 5 votes vote down vote up
public String[] formatScope(TaskManagerMetricGroup parent, JobID jid, String jobName) {
	final String[] template = copyTemplate();
	final String[] values = {
			parent.hostname(),
			parent.taskManagerId(),
			valueOrNull(jid),
			valueOrNull(jobName)
	};
	return bindVariables(template, values);
}
 
Example #30
Source File: ScheduledDropwizardReporterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that the registered metrics' names don't contain invalid characters.
 */
@Test
public void testAddingMetrics() throws Exception {
	Configuration configuration = new Configuration();
	String taskName = "test\"Ta\"..sk";
	String jobName = "testJ\"ob:-!ax..?";
	String hostname = "loc<>al\"::host\".:";
	String taskManagerId = "tas:kMana::ger";
	String counterName = "testCounter";

	configuration.setString(MetricOptions.SCOPE_NAMING_TASK, "<host>.<tm_id>.<job_name>");
	configuration.setString(MetricOptions.SCOPE_DELIMITER, "_");

	MetricRegistryConfiguration metricRegistryConfiguration = MetricRegistryConfiguration.fromConfiguration(configuration);

	MetricRegistryImpl metricRegistry = new MetricRegistryImpl(
		metricRegistryConfiguration,
		Collections.singletonList(ReporterSetup.forReporter("test", new TestingScheduledDropwizardReporter())));

	char delimiter = metricRegistry.getDelimiter();

	TaskManagerMetricGroup tmMetricGroup = new TaskManagerMetricGroup(metricRegistry, hostname, taskManagerId);
	TaskManagerJobMetricGroup tmJobMetricGroup = new TaskManagerJobMetricGroup(metricRegistry, tmMetricGroup, new JobID(), jobName);
	TaskMetricGroup taskMetricGroup = new TaskMetricGroup(metricRegistry, tmJobMetricGroup, new JobVertexID(), new AbstractID(), taskName, 0, 0);

	SimpleCounter myCounter = new SimpleCounter();
	com.codahale.metrics.Meter dropwizardMeter = new com.codahale.metrics.Meter();
	DropwizardMeterWrapper meterWrapper = new DropwizardMeterWrapper(dropwizardMeter);

	taskMetricGroup.counter(counterName, myCounter);
	taskMetricGroup.meter("meter", meterWrapper);

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

	assertTrue(reporters.size() == 1);
	MetricReporter metricReporter = reporters.get(0);

	assertTrue("Reporter should be of type ScheduledDropwizardReporter", metricReporter instanceof ScheduledDropwizardReporter);

	TestingScheduledDropwizardReporter reporter = (TestingScheduledDropwizardReporter) metricReporter;

	Map<Counter, String> counters = reporter.getCounters();
	assertTrue(counters.containsKey(myCounter));

	Map<Meter, String> meters = reporter.getMeters();
	assertTrue(meters.containsKey(meterWrapper));

	String expectedCounterName = reporter.filterCharacters(hostname)
		+ delimiter
		+ reporter.filterCharacters(taskManagerId)
		+ delimiter
		+ reporter.filterCharacters(jobName)
		+ delimiter
		+ reporter.filterCharacters(counterName);

	assertEquals(expectedCounterName, counters.get(myCounter));

	metricRegistry.shutdown().get();
}