You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "rich7420 (via GitHub)" <gi...@apache.org> on 2026/08/11 12:39:47 UTC
[PR] HDDS-10362. Add S3 Gateway metric for pending operations [ozone]
rich7420 opened a new pull request, #10990:
URL: https://github.com/apache/ozone/pull/10990
## What changes were proposed in this pull request?
Adds a gateway-wide `pendingOperations` metric to `S3GatewayMetrics` that tracks
the number of S3 operations currently in flight — received and being processed
but not yet fully replied to. This mirrors the intent of the xceiver client
`pendingOps` metric (increment when an operation starts, decrement when its
response is complete), as requested in the Jira.
Details:
- **Metric type.** `pendingOperations` is a `MutableGaugeLong`, not a counter.
A live in-flight value rises and falls, so a gauge is the correct type for
Prometheus/JMX consumers (`rate()`/`increase()` over a decreasing counter is
meaningless). This matches the existing Ozone convention for point-in-time
"pending/current" values (for example `SCMNodeMetrics.totalPendingContainerSlots`,
`BlockDeletingServiceMetrics.totalPendingBlockCount`). The xceiver metric the
Jira references models the *concept*; the idiomatic type here is a gauge.
- **Instrumentation.** A new `PendingOperationsFilter` (JAX-RS `@Provider`,
auto-registered via `GatewayApplication`'s package scan) increments on the
request side and decrements on the response side. It remembers the metrics
instance on the request and decrements only that same instance, so a request
rejected before the filter runs can never drive the gauge negative.
- **Scope.** The filter is post-matching, so it counts operations that reached
an endpoint. Requests rejected earlier (for example by the `@PreMatching`
`AuthorizationFilter`) are not counted, since they are not operations the
gateway performs.
- **Streaming GetObject.** For a streaming `GetObject` the JAX-RS response
filter runs before the body is written, so the decrement is deferred until the
response stream is closed (mirroring `TracingFilter`, HDDS-7064), with a
one-shot guard against double-decrement. The operation stays pending until the
object body has finished streaming to the client.
## What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-10362
## How was this patch tested?
- New unit test `TestPendingOperationsFilter` — normal request/response returns
to baseline, a response without a matching request is a no-op, and a streaming
`GetObject` stays pending until stream close (and a second close does not go
negative).
- `mvn -pl :ozone-s3gateway test -Dtest=TestPendingOperationsFilter,TestS3GatewayMetrics`
— `TestPendingOperationsFilter` 3/3, `TestS3GatewayMetrics` 44/44.
- `checkstyle` and `rat` clean.
- Full CI on the fork: all static gates, compile (8/17/21/25), unit, and all S3
acceptance groups (including `s3a`, which exercises `GetObject` heavily) pass.
Two jobs were flaky/unrelated and pass on re-run:
`integration (om)` (`TestKeyLifecycleService.testPrefixDirectoryNotExpired`,
an OM lifecycle test) and `acceptance (tools)` (a CI cache digest mismatch).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-10362. Add S3 Gateway metric for pending operations [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #10990:
URL: https://github.com/apache/ozone/pull/10990#issuecomment-6383966717
Thanks for the patch. I would like to defer merging this after #11735, which will (hopefully) allow skipping most integration tests for S3-only changes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-10362. Add S3 Gateway metric for pending operations [ozone]
Posted by "chihsuan (via GitHub)" <gi...@apache.org>.
chihsuan commented on code in PR #10990:
URL: https://github.com/apache/ozone/pull/10990#discussion_r3766860237
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/PendingOperationsFilter.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.hadoop.ozone.s3;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.container.ResourceInfo;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.ext.Provider;
+import org.apache.hadoop.ozone.client.io.WrappedOutputStream;
+import org.apache.hadoop.ozone.s3.metrics.S3GatewayMetrics;
+
+/**
+ * Tracks the number of S3 operations being processed but not yet fully replied
+ * to (in-flight), exposed as the {@code pendingOperations} gauge in
+ * {@link S3GatewayMetrics}. Modeled after the xceiver client {@code pendingOps}
+ * metric (HDDS-10362): increment when the operation starts, decrement when its
+ * response is complete.
+ *
+ * <p>The filter is post-matching, so it counts requests that reached an
+ * endpoint; requests rejected earlier (for example by the {@code @PreMatching}
+ * {@link AuthorizationFilter}) are not counted, since they are not operations
+ * the gateway performs. The request side increments and remembers the metrics
+ * instance on the request; the response side decrements only that same
+ * instance, so a request that never incremented can never drive the gauge
+ * negative.
+ *
+ * <p>For a streaming {@code GetObject}, the JAX-RS response filter runs before
+ * the body is written, so the decrement is deferred to the point where the
+ * response stream is closed (mirroring {@link TracingFilter}); the operation
+ * stays "pending" until the object body has finished streaming to the client.
+ */
+@Provider
+public class PendingOperationsFilter implements ContainerRequestFilter,
+ ContainerResponseFilter {
+
+ private static final String COUNTED_METRICS = "PENDING_OPERATION_METRICS";
+ private static final String HTTP_GET_METHOD = "GET";
+ private static final String OBJECT_ENDPOINT_CLASS_NAME = "ObjectEndpoint";
+ private static final String OBJECT_GET_METHOD_NAME = "get";
+
+ @Context
+ private ResourceInfo resourceInfo;
+
+ @Override
+ public void filter(ContainerRequestContext requestContext) {
+ S3GatewayMetrics metrics = S3GatewayMetrics.getMetrics();
+ if (metrics != null) {
+ metrics.incrPendingOperations();
+ requestContext.setProperty(COUNTED_METRICS, metrics);
+ }
+ }
+
+ @Override
+ public void filter(ContainerRequestContext requestContext,
+ ContainerResponseContext responseContext) {
+ Object counted = requestContext.getProperty(COUNTED_METRICS);
+ if (!(counted instanceof S3GatewayMetrics)) {
+ return;
+ }
+ requestContext.removeProperty(COUNTED_METRICS);
+ final S3GatewayMetrics metrics = (S3GatewayMetrics) counted;
+
+ if (isStreamingGetObject(requestContext)) {
+ OutputStream out = responseContext.getEntityStream();
+ if (out != null) {
+ // Decrement only once the body has been fully streamed to the client.
+ final AtomicBoolean decremented = new AtomicBoolean();
+ responseContext.setEntityStream(new WrappedOutputStream(out) {
+ @Override
+ public void close() throws IOException {
+ super.close();
Review Comment:
If `super.close()` throws, the decrement is skipped, and the gauge remains permanently inflated. Should the decrement run in a finally block?
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/PendingOperationsFilter.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.hadoop.ozone.s3;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.container.ResourceInfo;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.ext.Provider;
+import org.apache.hadoop.ozone.client.io.WrappedOutputStream;
+import org.apache.hadoop.ozone.s3.metrics.S3GatewayMetrics;
+
+/**
+ * Tracks the number of S3 operations being processed but not yet fully replied
+ * to (in-flight), exposed as the {@code pendingOperations} gauge in
+ * {@link S3GatewayMetrics}. Modeled after the xceiver client {@code pendingOps}
+ * metric (HDDS-10362): increment when the operation starts, decrement when its
+ * response is complete.
+ *
+ * <p>The filter is post-matching, so it counts requests that reached an
+ * endpoint; requests rejected earlier (for example by the {@code @PreMatching}
+ * {@link AuthorizationFilter}) are not counted, since they are not operations
+ * the gateway performs. The request side increments and remembers the metrics
+ * instance on the request; the response side decrements only that same
+ * instance, so a request that never incremented can never drive the gauge
+ * negative.
+ *
+ * <p>For a streaming {@code GetObject}, the JAX-RS response filter runs before
+ * the body is written, so the decrement is deferred to the point where the
+ * response stream is closed (mirroring {@link TracingFilter}); the operation
+ * stays "pending" until the object body has finished streaming to the client.
+ */
+@Provider
+public class PendingOperationsFilter implements ContainerRequestFilter,
+ ContainerResponseFilter {
+
+ private static final String COUNTED_METRICS = "PENDING_OPERATION_METRICS";
+ private static final String HTTP_GET_METHOD = "GET";
+ private static final String OBJECT_ENDPOINT_CLASS_NAME = "ObjectEndpoint";
+ private static final String OBJECT_GET_METHOD_NAME = "get";
+
+ @Context
+ private ResourceInfo resourceInfo;
+
+ @Override
+ public void filter(ContainerRequestContext requestContext) {
+ S3GatewayMetrics metrics = S3GatewayMetrics.getMetrics();
+ if (metrics != null) {
+ metrics.incrPendingOperations();
+ requestContext.setProperty(COUNTED_METRICS, metrics);
+ }
+ }
+
+ @Override
+ public void filter(ContainerRequestContext requestContext,
+ ContainerResponseContext responseContext) {
+ Object counted = requestContext.getProperty(COUNTED_METRICS);
+ if (!(counted instanceof S3GatewayMetrics)) {
+ return;
+ }
+ requestContext.removeProperty(COUNTED_METRICS);
+ final S3GatewayMetrics metrics = (S3GatewayMetrics) counted;
+
+ if (isStreamingGetObject(requestContext)) {
Review Comment:
I think some `GetObject` responses, such as 304 Not Modified, have no response body. Since there is no body to stream, Jersey does not close this wrapped stream, and the pending count is never decremented.
Would it make sense to decrement immediately when the response has no entity?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-10362. Add S3 Gateway metric for pending operations [ozone]
Posted by "rich7420 (via GitHub) via issues" <is...@ozone.apache.org>.
rich7420 commented on PR #10990:
URL: https://github.com/apache/ozone/pull/10990#issuecomment-6744584746
Reworked this to use a per-request Jersey event listener instead of the filter plus request property, so there's less plumbing and no casts. The existing lifecycle tests all pass against it. One small difference: a request rejected by a post-matching filter is now always counted until it finishes, whatever the filter's priority.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-10362. Add S3 Gateway metric for pending operations [ozone]
Posted by "rich7420 (via GitHub)" <gi...@apache.org>.
rich7420 commented on PR #10990:
URL: https://github.com/apache/ozone/pull/10990#issuecomment-6384858098
@adoroszlai sure, thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-10362. Add S3 Gateway metric for pending operations [ozone]
Posted by "github-actions[bot] (via GitHub) via issues" <is...@ozone.apache.org>.
github-actions[bot] commented on PR #10990:
URL: https://github.com/apache/ozone/pull/10990#issuecomment-7330116829
This PR has been marked as stale due to 21 days of inactivity. Please comment or remove the stale label to keep it open. Otherwise, it will be automatically closed in 7 days.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org