Search in sources :

Example 21 with EmptyRequestBody

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());
}
Also used : AggregatedMetricsResponseBody(org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetricsResponseBody) AggregatedMetric(org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetric) HashMap(java.util.HashMap) List(java.util.List) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) Test(org.junit.Test)

Example 22 with EmptyRequestBody

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);
}
Also used : ExecutionState(org.apache.flink.runtime.execution.ExecutionState) ArchivedExecutionJobVertex(org.apache.flink.runtime.executiongraph.ArchivedExecutionJobVertex) Configuration(org.apache.flink.configuration.Configuration) RestHandlerConfiguration(org.apache.flink.runtime.rest.handler.RestHandlerConfiguration) HashMap(java.util.HashMap) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) ArchivedExecution(org.apache.flink.runtime.executiongraph.ArchivedExecution) IOMetrics(org.apache.flink.runtime.executiongraph.IOMetrics) DefaultExecutionGraphCache(org.apache.flink.runtime.rest.handler.legacy.DefaultExecutionGraphCache) IOMetricsInfo(org.apache.flink.runtime.rest.messages.job.metrics.IOMetricsInfo) MetricFetcherImpl(org.apache.flink.runtime.rest.handler.legacy.metrics.MetricFetcherImpl) SubtaskExecutionAttemptDetailsInfo(org.apache.flink.runtime.rest.messages.job.SubtaskExecutionAttemptDetailsInfo) RestHandlerConfiguration(org.apache.flink.runtime.rest.handler.RestHandlerConfiguration) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) SubtaskAttemptMessageParameters(org.apache.flink.runtime.rest.messages.job.SubtaskAttemptMessageParameters) ArchivedExecutionVertex(org.apache.flink.runtime.executiongraph.ArchivedExecutionVertex) StringifiedAccumulatorResult(org.apache.flink.runtime.accumulators.StringifiedAccumulatorResult) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) MetricFetcher(org.apache.flink.runtime.rest.handler.legacy.metrics.MetricFetcher) EvictingBoundedList(org.apache.flink.runtime.util.EvictingBoundedList) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 23 with EmptyRequestBody

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. "));
        }
    }
}
Also used : TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) RestClient(org.apache.flink.runtime.rest.RestClient) TestRestHandler(org.apache.flink.runtime.rest.util.TestRestHandler) EmptyResponseBody(org.apache.flink.runtime.rest.messages.EmptyResponseBody) ExecutionException(java.util.concurrent.ExecutionException) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) EmptyMessageParameters(org.apache.flink.runtime.rest.messages.EmptyMessageParameters) Test(org.junit.Test)

Example 24 with EmptyRequestBody

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());
}
Also used : AggregatedMetricsResponseBody(org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetricsResponseBody) AggregatedMetric(org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetric) HashMap(java.util.HashMap) List(java.util.List) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) Test(org.junit.Test)

Example 25 with EmptyRequestBody

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());
}
Also used : AggregatedMetricsResponseBody(org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetricsResponseBody) AggregatedMetric(org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetric) HashMap(java.util.HashMap) List(java.util.List) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) Test(org.junit.Test)

Aggregations

EmptyRequestBody (org.apache.flink.runtime.rest.messages.EmptyRequestBody)30 Test (org.junit.Test)23 HashMap (java.util.HashMap)12 List (java.util.List)8 RestHandlerException (org.apache.flink.runtime.rest.handler.RestHandlerException)7 AggregatedMetric (org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetric)7 AggregatedMetricsResponseBody (org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetricsResponseBody)7 RestfulGateway (org.apache.flink.runtime.webmonitor.RestfulGateway)6 JobExceptionsInfoWithHistory (org.apache.flink.runtime.rest.messages.JobExceptionsInfoWithHistory)5 ExecutionGraphInfo (org.apache.flink.runtime.scheduler.ExecutionGraphInfo)5 Map (java.util.Map)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Nonnull (javax.annotation.Nonnull)4 JobID (org.apache.flink.api.common.JobID)4 Time (org.apache.flink.api.common.time.Time)4 HandlerRequest (org.apache.flink.runtime.rest.handler.HandlerRequest)4 DefaultExecutionGraphCache (org.apache.flink.runtime.rest.handler.legacy.DefaultExecutionGraphCache)4 Path (java.nio.file.Path)3 CompletionException (java.util.concurrent.CompletionException)3 ExecutionException (java.util.concurrent.ExecutionException)3