use of org.apache.flink.runtime.rest.messages.EmptyRequestBody in project flink by apache.
the class AggregatingMetricsHandlerTestBase method testMaxAggregation.
@Test
public void testMaxAggregation() throws Exception {
Map<String, List<String>> queryParams = new HashMap<>(4);
queryParams.put("get", Collections.singletonList("abc.metric1"));
queryParams.put("agg", Collections.singletonList("max"));
HandlerRequest<EmptyRequestBody> request = HandlerRequest.resolveParametersAndCreate(EmptyRequestBody.getInstance(), handler.getMessageHeaders().getUnresolvedMessageParameters(), pathParameters, queryParams, Collections.emptyList());
AggregatedMetricsResponseBody response = handler.handleRequest(request, MOCK_DISPATCHER_GATEWAY).get();
Collection<AggregatedMetric> aggregatedMetrics = response.getMetrics();
assertEquals(1, aggregatedMetrics.size());
AggregatedMetric aggregatedMetric = aggregatedMetrics.iterator().next();
assertEquals("abc.metric1", aggregatedMetric.getId());
assertEquals(3.0, aggregatedMetric.getMax(), 0.1);
assertNull(aggregatedMetric.getMin());
assertNull(aggregatedMetric.getSum());
assertNull(aggregatedMetric.getAvg());
}
use of org.apache.flink.runtime.rest.messages.EmptyRequestBody in project flink by apache.
the class SubtaskExecutionAttemptDetailsHandlerTest method testHandleRequest.
@Test
public void testHandleRequest() throws Exception {
final JobID jobID = new JobID();
final JobVertexID jobVertexId = new JobVertexID();
// The testing subtask.
final int subtaskIndex = 1;
final ExecutionState expectedState = ExecutionState.FINISHED;
final int attempt = 0;
final StringifiedAccumulatorResult[] emptyAccumulators = new StringifiedAccumulatorResult[0];
final long bytesIn = 1L;
final long bytesOut = 10L;
final long recordsIn = 20L;
final long recordsOut = 30L;
final IOMetrics ioMetrics = new IOMetrics(bytesIn, bytesOut, recordsIn, recordsOut);
final ArchivedExecutionJobVertex archivedExecutionJobVertex = new ArchivedExecutionJobVertex(new ArchivedExecutionVertex[] { // the first subtask won't be queried
null, new ArchivedExecutionVertex(subtaskIndex, "test task", new ArchivedExecution(emptyAccumulators, ioMetrics, new ExecutionAttemptID(), attempt, expectedState, null, null, null, subtaskIndex, new long[ExecutionState.values().length]), new EvictingBoundedList<>(0)) }, jobVertexId, "test", 1, 1, ResourceProfile.UNKNOWN, emptyAccumulators);
// Change some fields so we can make it different from other sub tasks.
final MetricFetcher metricFetcher = new MetricFetcherImpl<>(() -> null, address -> null, TestingUtils.defaultExecutor(), Time.milliseconds(1000L), MetricOptions.METRIC_FETCHER_UPDATE_INTERVAL.defaultValue());
// Instance the handler.
final RestHandlerConfiguration restHandlerConfiguration = RestHandlerConfiguration.fromConfiguration(new Configuration());
final SubtaskExecutionAttemptDetailsHandler handler = new SubtaskExecutionAttemptDetailsHandler(() -> null, Time.milliseconds(100L), Collections.emptyMap(), SubtaskExecutionAttemptDetailsHeaders.getInstance(), new DefaultExecutionGraphCache(restHandlerConfiguration.getTimeout(), Time.milliseconds(restHandlerConfiguration.getRefreshInterval())), TestingUtils.defaultExecutor(), metricFetcher);
final HashMap<String, String> receivedPathParameters = new HashMap<>(4);
receivedPathParameters.put(JobIDPathParameter.KEY, jobID.toString());
receivedPathParameters.put(JobVertexIdPathParameter.KEY, jobVertexId.toString());
receivedPathParameters.put(SubtaskIndexPathParameter.KEY, Integer.toString(subtaskIndex));
receivedPathParameters.put(SubtaskAttemptPathParameter.KEY, Integer.toString(attempt));
final HandlerRequest<EmptyRequestBody> request = HandlerRequest.resolveParametersAndCreate(EmptyRequestBody.getInstance(), new SubtaskAttemptMessageParameters(), receivedPathParameters, Collections.emptyMap(), Collections.emptyList());
// Handle request.
final SubtaskExecutionAttemptDetailsInfo detailsInfo = handler.handleRequest(request, archivedExecutionJobVertex);
// Verify
final IOMetricsInfo ioMetricsInfo = new IOMetricsInfo(bytesIn, true, bytesOut, true, recordsIn, true, recordsOut, true);
final SubtaskExecutionAttemptDetailsInfo expectedDetailsInfo = new SubtaskExecutionAttemptDetailsInfo(subtaskIndex, expectedState, attempt, "(unassigned)", -1L, 0L, -1L, ioMetricsInfo, "(unassigned)");
assertEquals(expectedDetailsInfo, detailsInfo);
}
use of org.apache.flink.runtime.rest.messages.EmptyRequestBody in project flink by apache.
the class AbstractHandlerITCase method testOOMErrorMessageEnrichment.
@Test
public void testOOMErrorMessageEnrichment() throws Exception {
final TestMessageHeaders<EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters> messageHeaders = TestMessageHeaders.emptyBuilder().setTargetRestEndpointURL("/test-handler").build();
final TestRestHandler<RestfulGateway, EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters> testRestHandler = new TestRestHandler<>(mockGatewayRetriever, messageHeaders, FutureUtils.completedExceptionally(new OutOfMemoryError("Metaspace")));
try (final TestRestServerEndpoint server = TestRestServerEndpoint.builder(REST_BASE_CONFIG).withHandler(messageHeaders, testRestHandler).buildAndStart();
final RestClient restClient = createRestClient(server.getServerAddress().getPort())) {
CompletableFuture<EmptyResponseBody> response = restClient.sendRequest(server.getServerAddress().getHostName(), server.getServerAddress().getPort(), messageHeaders, EmptyMessageParameters.getInstance(), EmptyRequestBody.getInstance());
try {
response.get();
fail("An ExecutionException was expected here being caused by the OutOfMemoryError.");
} catch (ExecutionException e) {
assertThat(e.getMessage(), StringContains.containsString("Metaspace. The metaspace out-of-memory error has occurred. "));
}
}
}
use of org.apache.flink.runtime.rest.messages.EmptyRequestBody in project flink by apache.
the class AggregatingMetricsHandlerTestBase method testAvgAggregation.
@Test
public void testAvgAggregation() throws Exception {
Map<String, List<String>> queryParams = new HashMap<>(4);
queryParams.put("get", Collections.singletonList("abc.metric1"));
queryParams.put("agg", Collections.singletonList("avg"));
HandlerRequest<EmptyRequestBody> request = HandlerRequest.resolveParametersAndCreate(EmptyRequestBody.getInstance(), handler.getMessageHeaders().getUnresolvedMessageParameters(), pathParameters, queryParams, Collections.emptyList());
AggregatedMetricsResponseBody response = handler.handleRequest(request, MOCK_DISPATCHER_GATEWAY).get();
Collection<AggregatedMetric> aggregatedMetrics = response.getMetrics();
assertEquals(1, aggregatedMetrics.size());
AggregatedMetric aggregatedMetric = aggregatedMetrics.iterator().next();
assertEquals("abc.metric1", aggregatedMetric.getId());
assertEquals(2.0, aggregatedMetric.getAvg(), 0.1);
assertNull(aggregatedMetric.getMin());
assertNull(aggregatedMetric.getMax());
assertNull(aggregatedMetric.getSum());
}
use of org.apache.flink.runtime.rest.messages.EmptyRequestBody in project flink by apache.
the class AggregatingMetricsHandlerTestBase method testMinAggregation.
@Test
public void testMinAggregation() throws Exception {
Map<String, List<String>> queryParams = new HashMap<>(4);
queryParams.put("get", Collections.singletonList("abc.metric1"));
queryParams.put("agg", Collections.singletonList("min"));
HandlerRequest<EmptyRequestBody> request = HandlerRequest.resolveParametersAndCreate(EmptyRequestBody.getInstance(), handler.getMessageHeaders().getUnresolvedMessageParameters(), pathParameters, queryParams, Collections.emptyList());
AggregatedMetricsResponseBody response = handler.handleRequest(request, MOCK_DISPATCHER_GATEWAY).get();
Collection<AggregatedMetric> aggregatedMetrics = response.getMetrics();
assertEquals(1, aggregatedMetrics.size());
AggregatedMetric aggregatedMetric = aggregatedMetrics.iterator().next();
assertEquals("abc.metric1", aggregatedMetric.getId());
assertEquals(1.0, aggregatedMetric.getMin(), 0.1);
assertNull(aggregatedMetric.getMax());
assertNull(aggregatedMetric.getSum());
assertNull(aggregatedMetric.getAvg());
}
Aggregations