You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GJL <gi...@git.apache.org> on 2017/11/22 18:15:50 UTC
[GitHub] flink pull request #5055: [FLINK-7718] [flip6] Add JobVertexMetricsHandler t...
GitHub user GJL opened a pull request:
https://github.com/apache/flink/pull/5055
[FLINK-7718] [flip6] Add JobVertexMetricsHandler to DispatcherRestEndpoint
## Brief change log
- *Migrate logic in `org.apache.flink.runtime.rest.handler.legacy.metrics.JobVertexMetricsHandler` to new handler and add new handler to DispatcherRestEndpoint.*
- *Add common classes for remaining implementations of
`org.apache.flink.runtime.rest.handler.legacy.metrics.AbstractMetricsHandler`,
which require migration as well*
## Verifying this change
This change added tests and can be verified as follows:
- *Added tests for all new classes and old classes except for `DispatcherRestEndpoint`*
- *Manually deployed a job locally and verified with `curl` that JobVertexMetrics can be queried in FLIP-6.*
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): (yes / **no**)
- The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (yes / **no**)
- The serializers: (yes / **no** / don't know)
- The runtime per-record code paths (performance sensitive): (yes / **no** / don't know)
- Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Yarn/Mesos, ZooKeeper: (yes / **no** / don't know)
- The S3 file system connector: (yes / **no** / don't know)
## Documentation
- Does this pull request introduce a new feature? (yes / **no**)
- If yes, how is the feature documented? (**not applicable** / docs / JavaDocs / not documented)
CC: @tillrohrmann
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/GJL/flink FLINK-7718
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/flink/pull/5055.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #5055
----
commit b888c876131fa3744baff7393bb75025ccb4b61f
Author: gyao <ga...@data-artisans.com>
Date: 2017-11-22T17:58:03Z
[FLINK-7718] [flip6] Add JobVertexMetricsHandler to DispatcherRestEndpoint
Migrate logic in
org.apache.flink.runtime.rest.handler.legacy.metrics.JobVertexMetricsHandler to
new handler and add new handler to DispatcherRestEndpoint. Add common classes
for remaining implementations of
org.apache.flink.runtime.rest.handler.legacy.metrics.AbstractMetricsHandler,
which require migration as well.
----
---
[GitHub] flink pull request #5055: [FLINK-7718] [flip6] Add JobVertexMetricsHandler t...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/flink/pull/5055
---
[GitHub] flink pull request #5055: [FLINK-7718] [flip6] Add JobVertexMetricsHandler t...
Posted by GJL <gi...@git.apache.org>.
Github user GJL commented on a diff in the pull request:
https://github.com/apache/flink/pull/5055#discussion_r152837007
--- Diff: flink-runtime/src/test/java/org/apache/flink/runtime/rest/messages/job/metrics/MetricsFilterParameterTest.java ---
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.rest.messages.job.metrics;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Tests for {@link MetricsFilterParameter}.
+ */
+public class MetricsFilterParameterTest {
--- End diff --
Done
---
[GitHub] flink pull request #5055: [FLINK-7718] [flip6] Add JobVertexMetricsHandler t...
Posted by GJL <gi...@git.apache.org>.
Github user GJL commented on a diff in the pull request:
https://github.com/apache/flink/pull/5055#discussion_r152804507
--- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/rest/handler/job/metrics/AbstractMetricsHandler.java ---
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.rest.handler.job.metrics;
+
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.runtime.dispatcher.DispatcherGateway;
+import org.apache.flink.runtime.rest.handler.AbstractRestHandler;
+import org.apache.flink.runtime.rest.handler.HandlerRequest;
+import org.apache.flink.runtime.rest.handler.RestHandlerException;
+import org.apache.flink.runtime.rest.handler.legacy.metrics.MetricFetcher;
+import org.apache.flink.runtime.rest.handler.legacy.metrics.MetricStore;
+import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
+import org.apache.flink.runtime.rest.messages.MessageHeaders;
+import org.apache.flink.runtime.rest.messages.MessageParameters;
+import org.apache.flink.runtime.rest.messages.job.metrics.Metric;
+import org.apache.flink.runtime.rest.messages.job.metrics.MetricCollectionResponseBody;
+import org.apache.flink.runtime.rest.messages.job.metrics.MetricsFilterParameter;
+import org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever;
+
+import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Request handler that returns for a given task a list of all available metrics or the values for a set of metrics.
+ *
+ * <p>If the query parameters do not contain a "get" parameter the list of all metrics is returned.
+ * {@code {"available": [ { "name" : "X", "id" : "X" } ] } }
+ *
+ * <p>If the query parameters do contain a "get" parameter, a comma-separated list of metric names is expected as a value.
+ * {@code /metrics?get=X,Y}
+ * The handler will then return a list containing the values of the requested metrics.
+ * {@code [ { "id" : "X", "value" : "S" }, { "id" : "Y", "value" : "T" } ] }
+ *
+ * @param <M> Type of the concrete MessageParameters
+ */
+public abstract class AbstractMetricsHandler<M extends MessageParameters> extends
+ AbstractRestHandler<DispatcherGateway, EmptyRequestBody, MetricCollectionResponseBody, M> {
+
+ private final MetricFetcher metricFetcher;
+
+ public AbstractMetricsHandler(
+ CompletableFuture<String> localRestAddress,
+ GatewayRetriever<DispatcherGateway> leaderRetriever,
+ Time timeout,
+ Map<String, String> headers,
+ MessageHeaders<EmptyRequestBody, MetricCollectionResponseBody, M> messageHeaders,
+ MetricFetcher metricFetcher) {
+ super(localRestAddress, leaderRetriever, timeout, headers, messageHeaders);
+ this.metricFetcher = requireNonNull(metricFetcher, "metricFetcher must not be null");
+ }
+
+ @Override
+ protected CompletableFuture<MetricCollectionResponseBody> handleRequest(
+ @Nonnull HandlerRequest<EmptyRequestBody, M> request,
+ @Nonnull DispatcherGateway gateway) throws RestHandlerException {
+ metricFetcher.update();
+
+ final MetricStore.ComponentMetricStore componentMetricStore = getComponentMetricStore(
+ request,
+ metricFetcher.getMetricStore());
+
+ if (componentMetricStore == null || componentMetricStore.metrics == null) {
+ return CompletableFuture.completedFuture(
+ new MetricCollectionResponseBody(Collections.emptyList()));
+ }
+
+ final Set<String> requestedMetrics = new HashSet<>(request.getQueryParameter(
+ MetricsFilterParameter.class));
+
+ if (requestedMetrics.isEmpty()) {
+ return CompletableFuture.completedFuture(
+ new MetricCollectionResponseBody(getAvailableMetrics(componentMetricStore)));
+ } else {
+ final List<Metric> metrics = getRequestedMetrics(componentMetricStore, requestedMetrics);
+ return CompletableFuture.completedFuture(new MetricCollectionResponseBody(metrics));
+ }
+ }
+
+ /**
+ * Returns the {@link MetricStore.ComponentMetricStore} that should be queried for metrics.
+ */
+ @Nullable
+ protected abstract MetricStore.ComponentMetricStore getComponentMetricStore(
+ HandlerRequest<EmptyRequestBody, M> request,
+ MetricStore metricStore);
+
+ private static List<Metric> getAvailableMetrics(MetricStore.ComponentMetricStore componentMetricStore) {
+ return componentMetricStore.metrics
+ .keySet()
+ .stream()
+ .map(Metric::new)
+ .collect(Collectors.toList());
+ }
+
+ private static List<Metric> getRequestedMetrics(
+ MetricStore.ComponentMetricStore componentMetricStore,
+ Set<String> requestedMetrics) throws RestHandlerException {
+
+ final List<Metric> metrics = new ArrayList<>(requestedMetrics.size());
+ for (final String requestedMetric : requestedMetrics) {
+ final String value = componentMetricStore.getMetric(requestedMetric, null);
--- End diff --
If `requestedMetric` is an empty string, we will return HTTP code 404. This is different compared to the legacy handler. If this is a problem, I can change it to the old behavior.
---
[GitHub] flink pull request #5055: [FLINK-7718] [flip6] Add JobVertexMetricsHandler t...
Posted by GJL <gi...@git.apache.org>.
Github user GJL commented on a diff in the pull request:
https://github.com/apache/flink/pull/5055#discussion_r152817079
--- Diff: flink-runtime/src/test/java/org/apache/flink/runtime/rest/messages/job/metrics/MetricsFilterParameterTest.java ---
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.rest.messages.job.metrics;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Tests for {@link MetricsFilterParameter}.
+ */
+public class MetricsFilterParameterTest {
--- End diff --
Inherit from `TestLogger`
---
[GitHub] flink pull request #5055: [FLINK-7718] [flip6] Add JobVertexMetricsHandler t...
Posted by tillrohrmann <gi...@git.apache.org>.
Github user tillrohrmann commented on a diff in the pull request:
https://github.com/apache/flink/pull/5055#discussion_r152917601
--- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/rest/handler/job/metrics/AbstractMetricsHandler.java ---
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.rest.handler.job.metrics;
+
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.runtime.dispatcher.DispatcherGateway;
+import org.apache.flink.runtime.rest.handler.AbstractRestHandler;
+import org.apache.flink.runtime.rest.handler.HandlerRequest;
+import org.apache.flink.runtime.rest.handler.RestHandlerException;
+import org.apache.flink.runtime.rest.handler.legacy.metrics.MetricFetcher;
+import org.apache.flink.runtime.rest.handler.legacy.metrics.MetricStore;
+import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
+import org.apache.flink.runtime.rest.messages.MessageHeaders;
+import org.apache.flink.runtime.rest.messages.MessageParameters;
+import org.apache.flink.runtime.rest.messages.job.metrics.Metric;
+import org.apache.flink.runtime.rest.messages.job.metrics.MetricCollectionResponseBody;
+import org.apache.flink.runtime.rest.messages.job.metrics.MetricsFilterParameter;
+import org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever;
+
+import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Request handler that returns for a given task a list of all available metrics or the values for a set of metrics.
+ *
+ * <p>If the query parameters do not contain a "get" parameter the list of all metrics is returned.
+ * {@code {"available": [ { "name" : "X", "id" : "X" } ] } }
+ *
+ * <p>If the query parameters do contain a "get" parameter, a comma-separated list of metric names is expected as a value.
+ * {@code /metrics?get=X,Y}
+ * The handler will then return a list containing the values of the requested metrics.
+ * {@code [ { "id" : "X", "value" : "S" }, { "id" : "Y", "value" : "T" } ] }
+ *
+ * @param <M> Type of the concrete MessageParameters
+ */
+public abstract class AbstractMetricsHandler<M extends MessageParameters> extends
+ AbstractRestHandler<DispatcherGateway, EmptyRequestBody, MetricCollectionResponseBody, M> {
+
+ private final MetricFetcher metricFetcher;
+
+ public AbstractMetricsHandler(
+ CompletableFuture<String> localRestAddress,
+ GatewayRetriever<DispatcherGateway> leaderRetriever,
+ Time timeout,
+ Map<String, String> headers,
+ MessageHeaders<EmptyRequestBody, MetricCollectionResponseBody, M> messageHeaders,
+ MetricFetcher metricFetcher) {
+ super(localRestAddress, leaderRetriever, timeout, headers, messageHeaders);
+ this.metricFetcher = requireNonNull(metricFetcher, "metricFetcher must not be null");
+ }
+
+ @Override
+ protected CompletableFuture<MetricCollectionResponseBody> handleRequest(
+ @Nonnull HandlerRequest<EmptyRequestBody, M> request,
+ @Nonnull DispatcherGateway gateway) throws RestHandlerException {
+ metricFetcher.update();
+
+ final MetricStore.ComponentMetricStore componentMetricStore = getComponentMetricStore(
+ request,
+ metricFetcher.getMetricStore());
+
+ if (componentMetricStore == null || componentMetricStore.metrics == null) {
+ return CompletableFuture.completedFuture(
+ new MetricCollectionResponseBody(Collections.emptyList()));
+ }
+
+ final Set<String> requestedMetrics = new HashSet<>(request.getQueryParameter(
+ MetricsFilterParameter.class));
+
+ if (requestedMetrics.isEmpty()) {
+ return CompletableFuture.completedFuture(
+ new MetricCollectionResponseBody(getAvailableMetrics(componentMetricStore)));
+ } else {
+ final List<Metric> metrics = getRequestedMetrics(componentMetricStore, requestedMetrics);
+ return CompletableFuture.completedFuture(new MetricCollectionResponseBody(metrics));
+ }
+ }
+
+ /**
+ * Returns the {@link MetricStore.ComponentMetricStore} that should be queried for metrics.
+ */
+ @Nullable
+ protected abstract MetricStore.ComponentMetricStore getComponentMetricStore(
+ HandlerRequest<EmptyRequestBody, M> request,
+ MetricStore metricStore);
+
+ private static List<Metric> getAvailableMetrics(MetricStore.ComponentMetricStore componentMetricStore) {
+ return componentMetricStore.metrics
+ .keySet()
+ .stream()
+ .map(Metric::new)
+ .collect(Collectors.toList());
+ }
+
+ private static List<Metric> getRequestedMetrics(
+ MetricStore.ComponentMetricStore componentMetricStore,
+ Set<String> requestedMetrics) throws RestHandlerException {
+
+ final List<Metric> metrics = new ArrayList<>(requestedMetrics.size());
+ for (final String requestedMetric : requestedMetrics) {
+ final String value = componentMetricStore.getMetric(requestedMetric, null);
--- End diff --
I think we actually have a slightly inconsistent behaviour here. In case that `componentMetricStore` or `componentMetricStore.metrics` is `null` we return an empty metrics object. But in case that a requested metric is not there (might not be registered or transferred yet) we fail with a 404. With the current way we handle a non-existent metric store, it would be more consistent to simply not report metrics which are not there.
Furthermore, it could also be the case that only a subset of the requested metrics is not yet registered.
---
[GitHub] flink pull request #5055: [FLINK-7718] [flip6] Add JobVertexMetricsHandler t...
Posted by GJL <gi...@git.apache.org>.
Github user GJL commented on a diff in the pull request:
https://github.com/apache/flink/pull/5055#discussion_r152951899
--- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/rest/handler/job/metrics/AbstractMetricsHandler.java ---
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.rest.handler.job.metrics;
+
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.runtime.dispatcher.DispatcherGateway;
+import org.apache.flink.runtime.rest.handler.AbstractRestHandler;
+import org.apache.flink.runtime.rest.handler.HandlerRequest;
+import org.apache.flink.runtime.rest.handler.RestHandlerException;
+import org.apache.flink.runtime.rest.handler.legacy.metrics.MetricFetcher;
+import org.apache.flink.runtime.rest.handler.legacy.metrics.MetricStore;
+import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
+import org.apache.flink.runtime.rest.messages.MessageHeaders;
+import org.apache.flink.runtime.rest.messages.MessageParameters;
+import org.apache.flink.runtime.rest.messages.job.metrics.Metric;
+import org.apache.flink.runtime.rest.messages.job.metrics.MetricCollectionResponseBody;
+import org.apache.flink.runtime.rest.messages.job.metrics.MetricsFilterParameter;
+import org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever;
+
+import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Request handler that returns for a given task a list of all available metrics or the values for a set of metrics.
+ *
+ * <p>If the query parameters do not contain a "get" parameter the list of all metrics is returned.
+ * {@code {"available": [ { "name" : "X", "id" : "X" } ] } }
+ *
+ * <p>If the query parameters do contain a "get" parameter, a comma-separated list of metric names is expected as a value.
+ * {@code /metrics?get=X,Y}
+ * The handler will then return a list containing the values of the requested metrics.
+ * {@code [ { "id" : "X", "value" : "S" }, { "id" : "Y", "value" : "T" } ] }
+ *
+ * @param <M> Type of the concrete MessageParameters
+ */
+public abstract class AbstractMetricsHandler<M extends MessageParameters> extends
+ AbstractRestHandler<DispatcherGateway, EmptyRequestBody, MetricCollectionResponseBody, M> {
+
+ private final MetricFetcher metricFetcher;
+
+ public AbstractMetricsHandler(
+ CompletableFuture<String> localRestAddress,
+ GatewayRetriever<DispatcherGateway> leaderRetriever,
+ Time timeout,
+ Map<String, String> headers,
+ MessageHeaders<EmptyRequestBody, MetricCollectionResponseBody, M> messageHeaders,
+ MetricFetcher metricFetcher) {
+ super(localRestAddress, leaderRetriever, timeout, headers, messageHeaders);
+ this.metricFetcher = requireNonNull(metricFetcher, "metricFetcher must not be null");
+ }
+
+ @Override
+ protected CompletableFuture<MetricCollectionResponseBody> handleRequest(
+ @Nonnull HandlerRequest<EmptyRequestBody, M> request,
+ @Nonnull DispatcherGateway gateway) throws RestHandlerException {
+ metricFetcher.update();
+
+ final MetricStore.ComponentMetricStore componentMetricStore = getComponentMetricStore(
+ request,
+ metricFetcher.getMetricStore());
+
+ if (componentMetricStore == null || componentMetricStore.metrics == null) {
+ return CompletableFuture.completedFuture(
+ new MetricCollectionResponseBody(Collections.emptyList()));
+ }
+
+ final Set<String> requestedMetrics = new HashSet<>(request.getQueryParameter(
+ MetricsFilterParameter.class));
+
+ if (requestedMetrics.isEmpty()) {
+ return CompletableFuture.completedFuture(
+ new MetricCollectionResponseBody(getAvailableMetrics(componentMetricStore)));
+ } else {
+ final List<Metric> metrics = getRequestedMetrics(componentMetricStore, requestedMetrics);
+ return CompletableFuture.completedFuture(new MetricCollectionResponseBody(metrics));
+ }
+ }
+
+ /**
+ * Returns the {@link MetricStore.ComponentMetricStore} that should be queried for metrics.
+ */
+ @Nullable
+ protected abstract MetricStore.ComponentMetricStore getComponentMetricStore(
+ HandlerRequest<EmptyRequestBody, M> request,
+ MetricStore metricStore);
+
+ private static List<Metric> getAvailableMetrics(MetricStore.ComponentMetricStore componentMetricStore) {
+ return componentMetricStore.metrics
+ .keySet()
+ .stream()
+ .map(Metric::new)
+ .collect(Collectors.toList());
+ }
+
+ private static List<Metric> getRequestedMetrics(
+ MetricStore.ComponentMetricStore componentMetricStore,
+ Set<String> requestedMetrics) throws RestHandlerException {
+
+ final List<Metric> metrics = new ArrayList<>(requestedMetrics.size());
+ for (final String requestedMetric : requestedMetrics) {
+ final String value = componentMetricStore.getMetric(requestedMetric, null);
--- End diff --
Changed the behavior:
* Unknown metrics are not included.
* If all metrics are unknown, an empty list is returned.
---