This is an automated email from the ASF dual-hosted git repository.
jackie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new 205a75debb API to expose gauge metric values on minion (#13550)
205a75debb is described below
commit 205a75debbdd2c161f6f830a71e467605fac6ec4
Author: Shounak kulkarni <[email protected]>
AuthorDate: Fri Jul 19 10:32:22 2024 +0500
API to expose gauge metric values on minion (#13550)
---
.../pinot/common/metrics/AbstractMetrics.java | 12 ++++
.../api/resources/PinotMinionMetricsResource.java | 68 ++++++++++++++++++++++
2 files changed, 80 insertions(+)
diff --git
a/pinot-common/src/main/java/org/apache/pinot/common/metrics/AbstractMetrics.java
b/pinot-common/src/main/java/org/apache/pinot/common/metrics/AbstractMetrics.java
index dfdc2abb0f..66d191503f 100644
---
a/pinot-common/src/main/java/org/apache/pinot/common/metrics/AbstractMetrics.java
+++
b/pinot-common/src/main/java/org/apache/pinot/common/metrics/AbstractMetrics.java
@@ -31,6 +31,7 @@ import java.util.concurrent.atomic.AtomicLong;
import java.util.function.LongSupplier;
import java.util.function.Supplier;
import java.util.stream.Collectors;
+import javax.annotation.Nullable;
import org.apache.pinot.common.Utils;
import org.apache.pinot.spi.metrics.PinotGauge;
import org.apache.pinot.spi.metrics.PinotMeter;
@@ -494,6 +495,17 @@ public abstract class AbstractMetrics<QP extends
AbstractMetrics.QueryPhase, M e
}
}
+ /**
+ * Get the gauge metric value for the provided gauge name
+ * @param gaugeName gauge name
+ * @return gauge value. If gauge is not present return null.
+ */
+ @Nullable
+ public Long getGaugeValue(final String gaugeName) {
+ AtomicLong value = _gaugeValues.get(gaugeName);
+ return value != null ? value.get() : null;
+ }
+
/**
* Initializes all global meters (such as exceptions count) to zero.
*/
diff --git
a/pinot-minion/src/main/java/org/apache/pinot/minion/api/resources/PinotMinionMetricsResource.java
b/pinot-minion/src/main/java/org/apache/pinot/minion/api/resources/PinotMinionMetricsResource.java
new file mode 100644
index 0000000000..040d6f526b
--- /dev/null
+++
b/pinot-minion/src/main/java/org/apache/pinot/minion/api/resources/PinotMinionMetricsResource.java
@@ -0,0 +1,68 @@
+/**
+ * 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.pinot.minion.api.resources;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiKeyAuthDefinition;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.Authorization;
+import io.swagger.annotations.SecurityDefinition;
+import io.swagger.annotations.SwaggerDefinition;
+import java.util.HashMap;
+import java.util.Map;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import org.apache.pinot.common.metrics.MinionMetrics;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+import static
org.apache.pinot.spi.utils.CommonConstants.SWAGGER_AUTHORIZATION_KEY;
+
+
+@Api(tags = "Metrics", authorizations = {@Authorization(value =
SWAGGER_AUTHORIZATION_KEY)})
+@SwaggerDefinition(securityDefinition =
@SecurityDefinition(apiKeyAuthDefinitions = @ApiKeyAuthDefinition(name =
+ HttpHeaders.AUTHORIZATION, in =
ApiKeyAuthDefinition.ApiKeyLocation.HEADER, key = SWAGGER_AUTHORIZATION_KEY)))
+@Path("/metrics")
+public class PinotMinionMetricsResource {
+ public static final String METRIC_EXISTS = "metricExists";
+ public static final String GAUGE_VALUE = "gaugeValue";
+ private final MinionMetrics _minionMetrics = MinionMetrics.get();
+
+ @GET
+ @Path("/gauge/{gaugeName}")
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation("Get gauge value for the provided minion gauge name")
+ public String getMinionGaugeValue(@ApiParam(value = "Gauge name")
@PathParam("gaugeName") String gaugeName)
+ throws JsonProcessingException {
+ Long value = _minionMetrics.getGaugeValue(gaugeName);
+ Map<String, Object> response = new HashMap<>();
+ if (value != null) {
+ response.put(GAUGE_VALUE, value);
+ response.put(METRIC_EXISTS, true);
+ } else {
+ response.put(METRIC_EXISTS, false);
+ }
+ return JsonUtils.objectToString(response);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]