Search in sources :

Example 6 with MetricStore

use of org.apache.flink.runtime.rest.handler.legacy.metrics.MetricStore in project flink by apache.

the class AbstractAggregatingMetricsHandler method handleRequest.

@Override
protected CompletableFuture<AggregatedMetricsResponseBody> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody> request, @Nonnull RestfulGateway gateway) throws RestHandlerException {
    return CompletableFuture.supplyAsync(() -> {
        try {
            fetcher.update();
            List<String> requestedMetrics = request.getQueryParameter(MetricsFilterParameter.class);
            List<MetricsAggregationParameter.AggregationMode> requestedAggregations = request.getQueryParameter(MetricsAggregationParameter.class);
            MetricStore store = fetcher.getMetricStore();
            Collection<? extends MetricStore.ComponentMetricStore> stores = getStores(store, request);
            if (requestedMetrics.isEmpty()) {
                Collection<String> list = getAvailableMetrics(stores);
                return new AggregatedMetricsResponseBody(list.stream().map(AggregatedMetric::new).collect(Collectors.toList()));
            }
            DoubleAccumulator.DoubleMinimumFactory minimumFactory = null;
            DoubleAccumulator.DoubleMaximumFactory maximumFactory = null;
            DoubleAccumulator.DoubleAverageFactory averageFactory = null;
            DoubleAccumulator.DoubleSumFactory sumFactory = null;
            // by default we return all aggregations
            if (requestedAggregations.isEmpty()) {
                minimumFactory = DoubleAccumulator.DoubleMinimumFactory.get();
                maximumFactory = DoubleAccumulator.DoubleMaximumFactory.get();
                averageFactory = DoubleAccumulator.DoubleAverageFactory.get();
                sumFactory = DoubleAccumulator.DoubleSumFactory.get();
            } else {
                for (MetricsAggregationParameter.AggregationMode aggregation : requestedAggregations) {
                    switch(aggregation) {
                        case MIN:
                            minimumFactory = DoubleAccumulator.DoubleMinimumFactory.get();
                            break;
                        case MAX:
                            maximumFactory = DoubleAccumulator.DoubleMaximumFactory.get();
                            break;
                        case AVG:
                            averageFactory = DoubleAccumulator.DoubleAverageFactory.get();
                            break;
                        case SUM:
                            sumFactory = DoubleAccumulator.DoubleSumFactory.get();
                            break;
                        default:
                            log.warn("Unsupported aggregation specified: {}", aggregation);
                    }
                }
            }
            MetricAccumulatorFactory metricAccumulatorFactory = new MetricAccumulatorFactory(minimumFactory, maximumFactory, averageFactory, sumFactory);
            return getAggregatedMetricValues(stores, requestedMetrics, metricAccumulatorFactory);
        } catch (Exception e) {
            log.warn("Could not retrieve metrics.", e);
            throw new CompletionException(new RestHandlerException("Could not retrieve metrics.", HttpResponseStatus.INTERNAL_SERVER_ERROR));
        }
    }, executor);
}
Also used : MetricStore(org.apache.flink.runtime.rest.handler.legacy.metrics.MetricStore) CompletionException(java.util.concurrent.CompletionException) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) AggregatedMetricsResponseBody(org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetricsResponseBody) AggregatedMetric(org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetric) CompletionException(java.util.concurrent.CompletionException) MetricsAggregationParameter(org.apache.flink.runtime.rest.messages.job.metrics.MetricsAggregationParameter)

Aggregations

MetricStore (org.apache.flink.runtime.rest.handler.legacy.metrics.MetricStore)6 Before (org.junit.Before)4 MetricDump (org.apache.flink.runtime.metrics.dump.MetricDump)3 DispatcherGateway (org.apache.flink.runtime.dispatcher.DispatcherGateway)2 MetricFetcher (org.apache.flink.runtime.rest.handler.legacy.metrics.MetricFetcher)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionException (java.util.concurrent.CompletionException)1 Nonnull (javax.annotation.Nonnull)1 JobID (org.apache.flink.api.common.JobID)1 AccessExecutionJobVertex (org.apache.flink.runtime.executiongraph.AccessExecutionJobVertex)1 AccessExecutionVertex (org.apache.flink.runtime.executiongraph.AccessExecutionVertex)1 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)1 RestHandlerException (org.apache.flink.runtime.rest.handler.RestHandlerException)1 JobVertexMessageParameters (org.apache.flink.runtime.rest.messages.JobVertexMessageParameters)1 AggregatedMetric (org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetric)1 AggregatedMetricsResponseBody (org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetricsResponseBody)1 MetricsAggregationParameter (org.apache.flink.runtime.rest.messages.job.metrics.MetricsAggregationParameter)1 GatewayRetriever (org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever)1