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);
}
Aggregations