Search in sources :

Example 6 with RestfulGateway

use of org.apache.flink.runtime.webmonitor.RestfulGateway in project flink by apache.

the class MetricFetcherTest method testUpdate.

@Test
public void testUpdate() {
    final Time timeout = Time.seconds(10L);
    // ========= setup TaskManager
    // =================================================================================
    JobID jobID = new JobID();
    ResourceID tmRID = ResourceID.generate();
    // ========= setup QueryServices
    // ================================================================================
    final MetricQueryServiceGateway jmQueryService = new TestingMetricQueryServiceGateway.Builder().setQueryMetricsSupplier(() -> CompletableFuture.completedFuture(new MetricDumpSerialization.MetricSerializationResult(new byte[0], new byte[0], new byte[0], new byte[0], 0, 0, 0, 0))).build();
    MetricDumpSerialization.MetricSerializationResult requestMetricsAnswer = createRequestDumpAnswer(tmRID, jobID);
    final MetricQueryServiceGateway tmQueryService = new TestingMetricQueryServiceGateway.Builder().setQueryMetricsSupplier(() -> CompletableFuture.completedFuture(requestMetricsAnswer)).build();
    // ========= setup JobManager
    // ==================================================================================
    final TestingRestfulGateway restfulGateway = new TestingRestfulGateway.Builder().setRequestMultipleJobDetailsSupplier(() -> CompletableFuture.completedFuture(new MultipleJobsDetails(Collections.emptyList()))).setRequestMetricQueryServiceGatewaysSupplier(() -> CompletableFuture.completedFuture(Collections.singleton(jmQueryService.getAddress()))).setRequestTaskManagerMetricQueryServiceGatewaysSupplier(() -> CompletableFuture.completedFuture(Collections.singleton(Tuple2.of(tmRID, tmQueryService.getAddress())))).build();
    final GatewayRetriever<RestfulGateway> retriever = () -> CompletableFuture.completedFuture(restfulGateway);
    // ========= start MetricFetcher testing
    // =======================================================================
    MetricFetcher fetcher = new MetricFetcherImpl<>(retriever, address -> CompletableFuture.completedFuture(tmQueryService), Executors.directExecutor(), timeout, MetricOptions.METRIC_FETCHER_UPDATE_INTERVAL.defaultValue());
    // verify that update fetches metrics and updates the store
    fetcher.update();
    MetricStore store = fetcher.getMetricStore();
    synchronized (store) {
        assertEquals("7", store.getJobManagerMetricStore().getMetric("abc.hist_min"));
        assertEquals("6", store.getJobManagerMetricStore().getMetric("abc.hist_max"));
        assertEquals("4.0", store.getJobManagerMetricStore().getMetric("abc.hist_mean"));
        assertEquals("0.5", store.getJobManagerMetricStore().getMetric("abc.hist_median"));
        assertEquals("5.0", store.getJobManagerMetricStore().getMetric("abc.hist_stddev"));
        assertEquals("0.75", store.getJobManagerMetricStore().getMetric("abc.hist_p75"));
        assertEquals("0.9", store.getJobManagerMetricStore().getMetric("abc.hist_p90"));
        assertEquals("0.95", store.getJobManagerMetricStore().getMetric("abc.hist_p95"));
        assertEquals("0.98", store.getJobManagerMetricStore().getMetric("abc.hist_p98"));
        assertEquals("0.99", store.getJobManagerMetricStore().getMetric("abc.hist_p99"));
        assertEquals("0.999", store.getJobManagerMetricStore().getMetric("abc.hist_p999"));
        assertEquals("x", store.getTaskManagerMetricStore(tmRID.toString()).metrics.get("abc.gauge"));
        assertEquals("5.0", store.getJobMetricStore(jobID.toString()).metrics.get("abc.jc"));
        assertEquals("2", store.getTaskMetricStore(jobID.toString(), "taskid").metrics.get("2.abc.tc"));
        assertEquals("1", store.getTaskMetricStore(jobID.toString(), "taskid").metrics.get("2.opname.abc.oc"));
    }
}
Also used : MetricQueryServiceGateway(org.apache.flink.runtime.webmonitor.retriever.MetricQueryServiceGateway) TestingMetricQueryServiceGateway(org.apache.flink.runtime.metrics.dump.TestingMetricQueryServiceGateway) Time(org.apache.flink.api.common.time.Time) MultipleJobsDetails(org.apache.flink.runtime.messages.webmonitor.MultipleJobsDetails) MetricDumpSerialization(org.apache.flink.runtime.metrics.dump.MetricDumpSerialization) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) JobID(org.apache.flink.api.common.JobID) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) Test(org.junit.Test)

Example 7 with RestfulGateway

use of org.apache.flink.runtime.webmonitor.RestfulGateway in project flink by apache.

the class MetricFetcherTest method testShortUpdateInterval.

@Test
public void testShortUpdateInterval() throws InterruptedException {
    final long updateInterval = 1L;
    final AtomicInteger requestMetricQueryServiceGatewaysCounter = new AtomicInteger(0);
    final RestfulGateway restfulGateway = createRestfulGateway(requestMetricQueryServiceGatewaysCounter);
    final MetricFetcher fetcher = createMetricFetcher(updateInterval, restfulGateway);
    fetcher.update();
    final long start = System.currentTimeMillis();
    long difference = 0L;
    while (difference <= updateInterval) {
        Thread.sleep(2L * updateInterval);
        difference = System.currentTimeMillis() - start;
    }
    fetcher.update();
    assertThat(requestMetricQueryServiceGatewaysCounter.get(), is(2));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) Test(org.junit.Test)

Example 8 with RestfulGateway

use of org.apache.flink.runtime.webmonitor.RestfulGateway in project flink by apache.

the class DefaultExecutionGraphCacheTest method testCacheEntryCleanup.

/**
 * Tests that cache entries are cleaned up when their TTL has expired upon calling {@link
 * DefaultExecutionGraphCache#cleanup()}.
 */
@Test
public void testCacheEntryCleanup() throws Exception {
    final Time timeout = Time.milliseconds(100L);
    final Time timeToLive = Time.milliseconds(1L);
    final JobID expectedJobId2 = new JobID();
    final ExecutionGraphInfo expectedExecutionGraphInfo2 = new ExecutionGraphInfo(new ArchivedExecutionGraphBuilder().build());
    final AtomicInteger requestJobCalls = new AtomicInteger(0);
    final TestingRestfulGateway restfulGateway = new TestingRestfulGateway.Builder().setRequestExecutionGraphInfoFunction(jobId -> {
        requestJobCalls.incrementAndGet();
        if (jobId.equals(expectedJobId)) {
            return CompletableFuture.completedFuture(expectedExecutionGraphInfo);
        } else if (jobId.equals(expectedJobId2)) {
            return CompletableFuture.completedFuture(expectedExecutionGraphInfo2);
        } else {
            throw new AssertionError("Invalid job id received.");
        }
    }).build();
    try (ExecutionGraphCache executionGraphCache = new DefaultExecutionGraphCache(timeout, timeToLive)) {
        CompletableFuture<ExecutionGraphInfo> executionGraph1Future = executionGraphCache.getExecutionGraphInfo(expectedJobId, restfulGateway);
        CompletableFuture<ExecutionGraphInfo> executionGraph2Future = executionGraphCache.getExecutionGraphInfo(expectedJobId2, restfulGateway);
        assertEquals(expectedExecutionGraphInfo, executionGraph1Future.get());
        assertEquals(expectedExecutionGraphInfo2, executionGraph2Future.get());
        assertThat(requestJobCalls.get(), Matchers.equalTo(2));
        Thread.sleep(timeToLive.toMilliseconds());
        executionGraphCache.cleanup();
        assertTrue(executionGraphCache.size() == 0);
    }
}
Also used : FlinkException(org.apache.flink.util.FlinkException) Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) CompletableFuture(java.util.concurrent.CompletableFuture) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestLogger(org.apache.flink.util.TestLogger) Assert.fail(org.junit.Assert.fail) ExecutorService(java.util.concurrent.ExecutorService) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) Collection(java.util.Collection) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) Test(org.junit.Test) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) Preconditions(org.apache.flink.util.Preconditions) ExecutorUtils(org.apache.flink.util.ExecutorUtils) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) JobID(org.apache.flink.api.common.JobID) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Time(org.apache.flink.api.common.time.Time) Assert.assertEquals(org.junit.Assert.assertEquals) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) Time(org.apache.flink.api.common.time.Time) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) JobID(org.apache.flink.api.common.JobID) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) Test(org.junit.Test)

Example 9 with RestfulGateway

use of org.apache.flink.runtime.webmonitor.RestfulGateway 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 10 with RestfulGateway

use of org.apache.flink.runtime.webmonitor.RestfulGateway in project flink by apache.

the class AbstractExecutionGraphHandler method handleRequest.

@Override
protected CompletableFuture<R> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody> request, @Nonnull RestfulGateway gateway) throws RestHandlerException {
    JobID jobId = request.getPathParameter(JobIDPathParameter.class);
    CompletableFuture<ExecutionGraphInfo> executionGraphFuture = executionGraphCache.getExecutionGraphInfo(jobId, gateway);
    return executionGraphFuture.thenApplyAsync(executionGraph -> {
        try {
            return handleRequest(request, executionGraph);
        } catch (RestHandlerException rhe) {
            throw new CompletionException(rhe);
        }
    }, executor).exceptionally(throwable -> {
        throwable = ExceptionUtils.stripCompletionException(throwable);
        if (throwable instanceof FlinkJobNotFoundException) {
            throw new CompletionException(new NotFoundException(String.format("Job %s not found", jobId), throwable));
        } else {
            throw new CompletionException(throwable);
        }
    });
}
Also used : ExecutionGraphCache(org.apache.flink.runtime.rest.handler.legacy.ExecutionGraphCache) Executor(java.util.concurrent.Executor) GatewayRetriever(org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) MessageHeaders(org.apache.flink.runtime.rest.messages.MessageHeaders) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) Preconditions(org.apache.flink.util.Preconditions) NotFoundException(org.apache.flink.runtime.rest.NotFoundException) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) JobID(org.apache.flink.api.common.JobID) JobMessageParameters(org.apache.flink.runtime.rest.messages.JobMessageParameters) ResponseBody(org.apache.flink.runtime.rest.messages.ResponseBody) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Map(java.util.Map) HandlerRequest(org.apache.flink.runtime.rest.handler.HandlerRequest) Nonnull(javax.annotation.Nonnull) Time(org.apache.flink.api.common.time.Time) AbstractRestHandler(org.apache.flink.runtime.rest.handler.AbstractRestHandler) JobIDPathParameter(org.apache.flink.runtime.rest.messages.JobIDPathParameter) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) CompletionException(java.util.concurrent.CompletionException) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) NotFoundException(org.apache.flink.runtime.rest.NotFoundException) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) JobID(org.apache.flink.api.common.JobID) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException)

Aggregations

RestfulGateway (org.apache.flink.runtime.webmonitor.RestfulGateway)13 TestingRestfulGateway (org.apache.flink.runtime.webmonitor.TestingRestfulGateway)8 Test (org.junit.Test)7 CompletableFuture (java.util.concurrent.CompletableFuture)5 JobID (org.apache.flink.api.common.JobID)5 Time (org.apache.flink.api.common.time.Time)5 EmptyRequestBody (org.apache.flink.runtime.rest.messages.EmptyRequestBody)5 RestHandlerException (org.apache.flink.runtime.rest.handler.RestHandlerException)4 EmptyResponseBody (org.apache.flink.runtime.rest.messages.EmptyResponseBody)4 Map (java.util.Map)3 ExecutionException (java.util.concurrent.ExecutionException)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Nonnull (javax.annotation.Nonnull)3 FlinkJobNotFoundException (org.apache.flink.runtime.messages.FlinkJobNotFoundException)3 AbstractRestHandler (org.apache.flink.runtime.rest.handler.AbstractRestHandler)3 HandlerRequest (org.apache.flink.runtime.rest.handler.HandlerRequest)3 EmptyMessageParameters (org.apache.flink.runtime.rest.messages.EmptyMessageParameters)3 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2