org.apache.flink.runtime.rest.messages.job.metrics.MetricCollectionResponseBody Java Examples

The following examples show how to use org.apache.flink.runtime.rest.messages.job.metrics.MetricCollectionResponseBody. 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: AbstractMetricsHandlerTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testListMetrics() throws Exception {
	final CompletableFuture<MetricCollectionResponseBody> completableFuture =
		testMetricsHandler.handleRequest(
			new HandlerRequest<>(
				EmptyRequestBody.getInstance(),
				new TestMessageParameters(),
				Collections.emptyMap(),
				Collections.emptyMap()),
			mockDispatcherGateway);

	assertTrue(completableFuture.isDone());

	final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get();
	assertThat(metricCollectionResponseBody.getMetrics(), hasSize(1));

	final Metric metric = metricCollectionResponseBody.getMetrics().iterator().next();
	assertThat(metric.getId(), equalTo(TEST_METRIC_NAME));
	assertThat(metric.getValue(), equalTo(null));
}
 
Example #2
Source File: MetricsHandlerTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the metric with name defined under {@link #TEST_METRIC_NAME} can be retrieved
 * from the {@link MetricStore.ComponentMetricStore} returned from
 * {@link AbstractMetricsHandler#getComponentMetricStore(HandlerRequest, MetricStore)}.
 */
@Test
public void testGetMetric() throws Exception {
	@SuppressWarnings("unchecked") final CompletableFuture<MetricCollectionResponseBody> completableFuture =
		metricsHandler.handleRequest(
			new HandlerRequest<>(
				EmptyRequestBody.getInstance(),
				metricsHandler.getMessageHeaders().getUnresolvedMessageParameters(),
				pathParameters,
				Collections.emptyMap()),
			mockDispatcherGateway);

	assertTrue(completableFuture.isDone());

	final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get();
	assertThat(metricCollectionResponseBody.getMetrics(), hasSize(1));

	final Metric metric = metricCollectionResponseBody.getMetrics().iterator().next();
	assertThat(metric.getId(), equalTo(getExpectedIdForMetricName(TEST_METRIC_NAME)));
}
 
Example #3
Source File: AbstractMetricsHandlerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testReturnEmptyListIfRequestedMetricIsUnknown() throws Exception {
	final CompletableFuture<MetricCollectionResponseBody> completableFuture =
		testMetricsHandler.handleRequest(
			new HandlerRequest<>(
				EmptyRequestBody.getInstance(),
				new TestMessageParameters(),
				Collections.emptyMap(),
				Collections.singletonMap(METRICS_FILTER_QUERY_PARAM, Collections.singletonList("unknown_metric"))),
			mockDispatcherGateway);

	assertTrue(completableFuture.isDone());

	final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get();
	assertThat(metricCollectionResponseBody.getMetrics(), empty());
}
 
Example #4
Source File: AbstractMetricsHandlerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetMetrics() throws Exception {
	final CompletableFuture<MetricCollectionResponseBody> completableFuture =
		testMetricsHandler.handleRequest(
			new HandlerRequest<>(
				EmptyRequestBody.getInstance(),
				new TestMessageParameters(),
				Collections.emptyMap(),
				Collections.singletonMap(METRICS_FILTER_QUERY_PARAM, Collections.singletonList(TEST_METRIC_NAME))),
			mockDispatcherGateway);

	assertTrue(completableFuture.isDone());

	final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get();
	assertThat(metricCollectionResponseBody.getMetrics(), hasSize(1));

	final Metric metric = metricCollectionResponseBody.getMetrics().iterator().next();
	assertThat(metric.getId(), equalTo(TEST_METRIC_NAME));
	assertThat(metric.getValue(), equalTo(Integer.toString(TEST_METRIC_VALUE)));
}
 
Example #5
Source File: AbstractMetricsHandlerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testReturnEmptyListIfNoComponentMetricStore() throws Exception {
	testMetricsHandler.returnComponentMetricStore = false;

	final CompletableFuture<MetricCollectionResponseBody> completableFuture =
		testMetricsHandler.handleRequest(
			new HandlerRequest<>(
				EmptyRequestBody.getInstance(),
				new TestMessageParameters(),
				Collections.emptyMap(),
				Collections.emptyMap()),
			mockDispatcherGateway);

	assertTrue(completableFuture.isDone());

	final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get();
	assertThat(metricCollectionResponseBody.getMetrics(), empty());
}
 
Example #6
Source File: AbstractMetricsHandlerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testListMetrics() throws Exception {
	final CompletableFuture<MetricCollectionResponseBody> completableFuture =
		testMetricsHandler.handleRequest(
			new HandlerRequest<>(
				EmptyRequestBody.getInstance(),
				new TestMessageParameters(),
				Collections.emptyMap(),
				Collections.emptyMap()),
			mockDispatcherGateway);

	assertTrue(completableFuture.isDone());

	final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get();
	assertThat(metricCollectionResponseBody.getMetrics(), hasSize(1));

	final Metric metric = metricCollectionResponseBody.getMetrics().iterator().next();
	assertThat(metric.getId(), equalTo(TEST_METRIC_NAME));
	assertThat(metric.getValue(), equalTo(null));
}
 
Example #7
Source File: MetricsHandlerTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the metric with name defined under {@link #TEST_METRIC_NAME} can be retrieved
 * from the {@link MetricStore.ComponentMetricStore} returned from
 * {@link AbstractMetricsHandler#getComponentMetricStore(HandlerRequest, MetricStore)}.
 */
@Test
public void testGetMetric() throws Exception {
	@SuppressWarnings("unchecked") final CompletableFuture<MetricCollectionResponseBody> completableFuture =
		metricsHandler.handleRequest(
			new HandlerRequest<>(
				EmptyRequestBody.getInstance(),
				metricsHandler.getMessageHeaders().getUnresolvedMessageParameters(),
				pathParameters,
				Collections.emptyMap()),
			mockDispatcherGateway);

	assertTrue(completableFuture.isDone());

	final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get();
	assertThat(metricCollectionResponseBody.getMetrics(), hasSize(1));

	final Metric metric = metricCollectionResponseBody.getMetrics().iterator().next();
	assertThat(metric.getId(), equalTo(getExpectedIdForMetricName(TEST_METRIC_NAME)));
}
 
Example #8
Source File: AbstractMetricsHandlerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testReturnEmptyListIfRequestedMetricIsUnknown() throws Exception {
	final CompletableFuture<MetricCollectionResponseBody> completableFuture =
		testMetricsHandler.handleRequest(
			new HandlerRequest<>(
				EmptyRequestBody.getInstance(),
				new TestMessageParameters(),
				Collections.emptyMap(),
				Collections.singletonMap(METRICS_FILTER_QUERY_PARAM, Collections.singletonList("unknown_metric"))),
			mockDispatcherGateway);

	assertTrue(completableFuture.isDone());

	final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get();
	assertThat(metricCollectionResponseBody.getMetrics(), empty());
}
 
Example #9
Source File: AbstractMetricsHandlerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetMetrics() throws Exception {
	final CompletableFuture<MetricCollectionResponseBody> completableFuture =
		testMetricsHandler.handleRequest(
			new HandlerRequest<>(
				EmptyRequestBody.getInstance(),
				new TestMessageParameters(),
				Collections.emptyMap(),
				Collections.singletonMap(METRICS_FILTER_QUERY_PARAM, Collections.singletonList(TEST_METRIC_NAME))),
			mockDispatcherGateway);

	assertTrue(completableFuture.isDone());

	final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get();
	assertThat(metricCollectionResponseBody.getMetrics(), hasSize(1));

	final Metric metric = metricCollectionResponseBody.getMetrics().iterator().next();
	assertThat(metric.getId(), equalTo(TEST_METRIC_NAME));
	assertThat(metric.getValue(), equalTo(Integer.toString(TEST_METRIC_VALUE)));
}
 
Example #10
Source File: AbstractMetricsHandlerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testReturnEmptyListIfNoComponentMetricStore() throws Exception {
	testMetricsHandler.returnComponentMetricStore = false;

	final CompletableFuture<MetricCollectionResponseBody> completableFuture =
		testMetricsHandler.handleRequest(
			new HandlerRequest<>(
				EmptyRequestBody.getInstance(),
				new TestMessageParameters(),
				Collections.emptyMap(),
				Collections.emptyMap()),
			mockDispatcherGateway);

	assertTrue(completableFuture.isDone());

	final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get();
	assertThat(metricCollectionResponseBody.getMetrics(), empty());
}
 
Example #11
Source File: AbstractMetricsHandlerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testListMetrics() throws Exception {
	final CompletableFuture<MetricCollectionResponseBody> completableFuture =
		testMetricsHandler.handleRequest(
			new HandlerRequest<>(
				EmptyRequestBody.getInstance(),
				new TestMessageParameters(),
				Collections.emptyMap(),
				Collections.emptyMap()),
			mockDispatcherGateway);

	assertTrue(completableFuture.isDone());

	final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get();
	assertThat(metricCollectionResponseBody.getMetrics(), hasSize(1));

	final Metric metric = metricCollectionResponseBody.getMetrics().iterator().next();
	assertThat(metric.getId(), equalTo(TEST_METRIC_NAME));
	assertThat(metric.getValue(), equalTo(null));
}
 
Example #12
Source File: MetricsHandlerTestBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the metric with name defined under {@link #TEST_METRIC_NAME} can be retrieved
 * from the {@link MetricStore.ComponentMetricStore} returned from
 * {@link AbstractMetricsHandler#getComponentMetricStore(HandlerRequest, MetricStore)}.
 */
@Test
public void testGetMetric() throws Exception {
	@SuppressWarnings("unchecked") final CompletableFuture<MetricCollectionResponseBody> completableFuture =
		metricsHandler.handleRequest(
			new HandlerRequest<>(
				EmptyRequestBody.getInstance(),
				metricsHandler.getMessageHeaders().getUnresolvedMessageParameters(),
				pathParameters,
				Collections.emptyMap()),
			mockDispatcherGateway);

	assertTrue(completableFuture.isDone());

	final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get();
	assertThat(metricCollectionResponseBody.getMetrics(), hasSize(1));

	final Metric metric = metricCollectionResponseBody.getMetrics().iterator().next();
	assertThat(metric.getId(), equalTo(getExpectedIdForMetricName(TEST_METRIC_NAME)));
}
 
Example #13
Source File: AbstractMetricsHandlerTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testReturnEmptyListIfNoComponentMetricStore() throws Exception {
	testMetricsHandler.returnComponentMetricStore = false;

	final CompletableFuture<MetricCollectionResponseBody> completableFuture =
		testMetricsHandler.handleRequest(
			new HandlerRequest<>(
				EmptyRequestBody.getInstance(),
				new TestMessageParameters(),
				Collections.emptyMap(),
				Collections.emptyMap()),
			mockDispatcherGateway);

	assertTrue(completableFuture.isDone());

	final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get();
	assertThat(metricCollectionResponseBody.getMetrics(), empty());
}
 
Example #14
Source File: AbstractMetricsHandlerTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetMetrics() throws Exception {
	final CompletableFuture<MetricCollectionResponseBody> completableFuture =
		testMetricsHandler.handleRequest(
			new HandlerRequest<>(
				EmptyRequestBody.getInstance(),
				new TestMessageParameters(),
				Collections.emptyMap(),
				Collections.singletonMap(METRICS_FILTER_QUERY_PARAM, Collections.singletonList(TEST_METRIC_NAME))),
			mockDispatcherGateway);

	assertTrue(completableFuture.isDone());

	final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get();
	assertThat(metricCollectionResponseBody.getMetrics(), hasSize(1));

	final Metric metric = metricCollectionResponseBody.getMetrics().iterator().next();
	assertThat(metric.getId(), equalTo(TEST_METRIC_NAME));
	assertThat(metric.getValue(), equalTo(Integer.toString(TEST_METRIC_VALUE)));
}
 
Example #15
Source File: AbstractMetricsHandlerTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testReturnEmptyListIfRequestedMetricIsUnknown() throws Exception {
	final CompletableFuture<MetricCollectionResponseBody> completableFuture =
		testMetricsHandler.handleRequest(
			new HandlerRequest<>(
				EmptyRequestBody.getInstance(),
				new TestMessageParameters(),
				Collections.emptyMap(),
				Collections.singletonMap(METRICS_FILTER_QUERY_PARAM, Collections.singletonList("unknown_metric"))),
			mockDispatcherGateway);

	assertTrue(completableFuture.isDone());

	final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get();
	assertThat(metricCollectionResponseBody.getMetrics(), empty());
}
 
Example #16
Source File: AbstractMetricsHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
public AbstractMetricsHandler(
		GatewayRetriever<? extends RestfulGateway> leaderRetriever,
		Time timeout,
		Map<String, String> headers,
		MessageHeaders<EmptyRequestBody, MetricCollectionResponseBody, M> messageHeaders,
		MetricFetcher metricFetcher) {
	super(leaderRetriever, timeout, headers, messageHeaders);
	this.metricFetcher = requireNonNull(metricFetcher, "metricFetcher must not be null");
}
 
Example #17
Source File: AbstractMetricsHandler.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public AbstractMetricsHandler(
		GatewayRetriever<? extends RestfulGateway> leaderRetriever,
		Time timeout,
		Map<String, String> headers,
		MessageHeaders<EmptyRequestBody, MetricCollectionResponseBody, M> messageHeaders,
		MetricFetcher metricFetcher) {
	super(leaderRetriever, timeout, headers, messageHeaders);
	this.metricFetcher = requireNonNull(metricFetcher, "metricFetcher must not be null");
}
 
Example #18
Source File: AbstractMetricsHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private TestMetricsHandler(
	GatewayRetriever<DispatcherGateway> leaderRetriever,
	Time timeout,
	Map<String, String> headers,
	MessageHeaders<EmptyRequestBody,
		MetricCollectionResponseBody,
		TestMessageParameters> messageHeaders,
	MetricFetcher metricFetcher) {

	super(leaderRetriever, timeout, headers, messageHeaders, metricFetcher);
}
 
Example #19
Source File: AbstractMetricsHandlerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private TestMetricsHandler(
	GatewayRetriever<DispatcherGateway> leaderRetriever,
	Time timeout,
	Map<String, String> headers,
	MessageHeaders<EmptyRequestBody,
		MetricCollectionResponseBody,
		TestMessageParameters> messageHeaders,
	MetricFetcher metricFetcher) {

	super(leaderRetriever, timeout, headers, messageHeaders, metricFetcher);
}
 
Example #20
Source File: JobVertexWatermarksHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoWatermarksAvailable() throws Exception {
	Mockito.when(taskMetricStore.getMetric("0.currentInputWatermark")).thenReturn(null);
	Mockito.when(taskMetricStore.getMetric("1.currentInputWatermark")).thenReturn(null);

	MetricCollectionResponseBody response = watermarkHandler.handleRequest(request, vertex);

	assertThat(response.getMetrics(), is(empty()));
}
 
Example #21
Source File: JobVertexWatermarksHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testPartialWatermarksAvailable() throws Exception {
	Mockito.when(taskMetricStore.getMetric("0.currentInputWatermark")).thenReturn("23");
	Mockito.when(taskMetricStore.getMetric("1.currentInputWatermark")).thenReturn(null);

	MetricCollectionResponseBody response = watermarkHandler.handleRequest(request, vertex);

	assertThat(response.getMetrics(),
		contains(
			new MetricMatcher("0.currentInputWatermark", "23")));
}
 
Example #22
Source File: JobVertexWatermarksHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testWatermarksRetrieval() throws Exception {
	Mockito.when(taskMetricStore.getMetric("0.currentInputWatermark")).thenReturn("23");
	Mockito.when(taskMetricStore.getMetric("1.currentInputWatermark")).thenReturn("42");

	MetricCollectionResponseBody response = watermarkHandler.handleRequest(request, vertex);

	assertThat(response.getMetrics(),
		containsInAnyOrder(
			new MetricMatcher("0.currentInputWatermark", "23"),
			new MetricMatcher("1.currentInputWatermark", "42")));
}
 
Example #23
Source File: AbstractMetricsHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
public AbstractMetricsHandler(
		GatewayRetriever<? extends RestfulGateway> leaderRetriever,
		Time timeout,
		Map<String, String> headers,
		MessageHeaders<EmptyRequestBody, MetricCollectionResponseBody, M> messageHeaders,
		MetricFetcher metricFetcher) {
	super(leaderRetriever, timeout, headers, messageHeaders);
	this.metricFetcher = requireNonNull(metricFetcher, "metricFetcher must not be null");
}
 
Example #24
Source File: JobVertexWatermarksHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected MetricCollectionResponseBody handleRequest(
		HandlerRequest<EmptyRequestBody, JobVertexMessageParameters> request,
		AccessExecutionJobVertex jobVertex) throws RestHandlerException {

	String jobID = request.getPathParameter(JobIDPathParameter.class).toString();
	String taskID = jobVertex.getJobVertexId().toString();

	metricFetcher.update();
	MetricStore.TaskMetricStore taskMetricStore = metricFetcher.getMetricStore().getTaskMetricStore(jobID, taskID);
	if (taskMetricStore == null) {
		return new MetricCollectionResponseBody(Collections.emptyList());
	}

	AccessExecutionVertex[] taskVertices = jobVertex.getTaskVertices();
	List<Metric> metrics = new ArrayList<>(taskVertices.length);

	for (AccessExecutionVertex taskVertex : taskVertices) {
		String id = taskVertex.getParallelSubtaskIndex() + "." + MetricNames.IO_CURRENT_INPUT_WATERMARK;
		String watermarkValue = taskMetricStore.getMetric(id);
		if (watermarkValue != null) {
			metrics.add(new Metric(id, watermarkValue));
		}
	}

	return new MetricCollectionResponseBody(metrics);
}
 
Example #25
Source File: AbstractMetricsHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private TestMetricsHandler(
	GatewayRetriever<DispatcherGateway> leaderRetriever,
	Time timeout,
	Map<String, String> headers,
	MessageHeaders<EmptyRequestBody,
		MetricCollectionResponseBody,
		TestMessageParameters> messageHeaders,
	MetricFetcher metricFetcher) {

	super(leaderRetriever, timeout, headers, messageHeaders, metricFetcher);
}
 
Example #26
Source File: MetricsAvailabilityITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
private static Predicate<MetricCollectionResponseBody> getMetricNamePredicate(final String metricName) {
	return response -> response.getMetrics().stream().anyMatch(metric -> metric.getId().equals(metricName));
}
 
Example #27
Source File: MetricsAvailabilityITCase.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private static Predicate<MetricCollectionResponseBody> getMetricNamePredicate(final String metricName) {
	return response -> response.getMetrics().stream().anyMatch(metric -> metric.getId().equals(metricName));
}
 
Example #28
Source File: MetricsAvailabilityITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
private static Predicate<MetricCollectionResponseBody> getMetricNamePredicate(final String metricName) {
	return response -> response.getMetrics().stream().anyMatch(metric -> metric.getId().equals(metricName));
}