You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "sadanand48 (via GitHub)" <gi...@apache.org> on 2025/12/02 10:29:08 UTC
[PR] HDDS-14061. Log the command type if command response size exceeds threshold. [ozone]
sadanand48 opened a new pull request, #9417:
URL: https://github.com/apache/ozone/pull/9417
## What changes were proposed in this pull request?
Currently if a command is returning large reponses there is no way to know the command type but only speculate based on previous logs or audit logs at the similar time.
```
/var/log/hadoop-ozone/ozone-om.log.1:2025-11-26 06:57:03,200 WARN [IPC Server handler 66 on default port 9862]-org.apache.hadoop.ipc.Server: Large response size 1115400 for call Call#46379 Retry#0 org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol.submitRequest from 10.17.213.18:34123
```
Add logging to identify the exact command
## What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-14061
## How was this patch tested?
Unit test
--
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-14061. Log OM request type if response size exceeds threshold [ozone]
Posted by "sadanand48 (via GitHub)" <gi...@apache.org>.
sadanand48 merged PR #9417:
URL: https://github.com/apache/ozone/pull/9417
--
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-14061. Log the command type if command response size exceeds threshold. [ozone]
Posted by "sadanand48 (via GitHub)" <gi...@apache.org>.
sadanand48 commented on code in PR #9417:
URL: https://github.com/apache/ozone/pull/9417#discussion_r2601093425
##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/response/TestOMResponse.java:
##########
@@ -0,0 +1,154 @@
+/*
+ * 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.om.response;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.google.protobuf.ProtocolMessageEnum;
+import java.nio.file.Path;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.hdds.utils.ProtocolMessageMetrics;
+import org.apache.hadoop.ozone.om.OMConfigKeys;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OmConfig;
+import org.apache.hadoop.ozone.om.OmMetadataManagerImpl;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.execution.OMExecutionFlow;
+import org.apache.hadoop.ozone.om.ratis.OzoneManagerRatisServer;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse;
+import org.apache.hadoop.ozone.protocolPB.OzoneManagerProtocolServerSideTranslatorPB;
+import org.apache.ozone.test.GenericTestUtils;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * Test class for OMResponse related methods.
+ */
+public class TestOMResponse {
+ @TempDir
+ private Path folder;
+
+ private OzoneManagerProtocolServerSideTranslatorPB translator;
+ private GenericTestUtils.LogCapturer logCapturer;
+ private static final long IPC_MAX_LEN = 1024 * 1024; // 1MB
+ private static final long WARN_THRESHOLD = IPC_MAX_LEN / 2; // 512KB
+
+ @BeforeEach
+ public void setup() throws Exception {
+ OzoneConfiguration configuration = new OzoneConfiguration();
+ configuration.set(OMConfigKeys.OZONE_OM_DB_DIRS,
+ folder.toAbsolutePath().toString());
+ configuration.setLong(
+ "ipc.maximum.response.length", IPC_MAX_LEN);
+
+ OzoneManager ozoneManager = mock(OzoneManager.class);
+ OMMetadataManager omMetadataManager = new OmMetadataManagerImpl(
+ configuration, ozoneManager);
+ when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
+ when(ozoneManager.getConfiguration()).thenReturn(configuration);
+
+ final OmConfig omConfig = configuration.getObject(OmConfig.class);
+ when(ozoneManager.getConfig()).thenReturn(omConfig);
+
+ OMExecutionFlow omExecutionFlow = new OMExecutionFlow(ozoneManager);
+ when(ozoneManager.getOmExecutionFlow()).thenReturn(omExecutionFlow);
+
+ OzoneManagerRatisServer ratisServer = mock(OzoneManagerRatisServer.class);
+ when(ratisServer.checkRetryCache()).thenReturn(null);
+
+ ProtocolMessageMetrics<ProtocolMessageEnum> protocolMessageMetrics =
+ mock(ProtocolMessageMetrics.class);
+
+ translator = new OzoneManagerProtocolServerSideTranslatorPB(
+ ozoneManager, ratisServer, protocolMessageMetrics);
+
+ // Capture logs from OzoneManagerProtocolServerSideTranslatorPB
+ logCapturer = GenericTestUtils.LogCapturer.captureLogs(
+ OzoneManagerProtocolServerSideTranslatorPB.class);
+ }
+
+ @AfterEach
+ public void tearDown() {
+ if (logCapturer != null) {
+ logCapturer.stopCapturing();
+ }
+ }
+
+ @Test
+ public void testLargeResponseLogging() {
+ // Create a large response that exceeds the threshold
+ // Use ListKeysResponse with many keys to create a large response
+ OzoneManagerProtocolProtos.ListKeysResponse.Builder listKeysBuilder =
+ OzoneManagerProtocolProtos.ListKeysResponse.newBuilder();
+ for (int i = 0; i < 12000; i++) {
+ listKeysBuilder.addKeyInfo(OzoneManagerProtocolProtos.KeyInfo.newBuilder()
+ .setKeyName("key" + i)
+ .setVolumeName("vol1")
+ .setBucketName("bucket1")
+ .setDataSize(1024)
+ .setCreationTime(System.currentTimeMillis())
+ .setType(HddsProtos.ReplicationType.RATIS)
+ .setModificationTime(System.currentTimeMillis())
+ .build());
+ }
+
+ OMResponse largeResponse = OMResponse.newBuilder()
+ .setCmdType(OzoneManagerProtocolProtos.Type.ListKeys)
+ .setStatus(OzoneManagerProtocolProtos.Status.OK)
+ .setSuccess(true)
+ .setListKeysResponse(listKeysBuilder.build())
+ .build();
+
+ long responseSize = largeResponse.getSerializedSize();
+
+ // Clear previous logs
+ logCapturer.clearOutput();
+ translator.logLargeResponseIfNeeded(largeResponse);
+
+ // Verify logging occurred
+ String logOutput = logCapturer.getOutput();
+ assertTrue(logOutput.contains("Large OMResponse detected"),
+ "Log should contain 'Large OMResponse detected'. Actual log: " + logOutput);
+ assertTrue(logOutput.contains("cmd=ListKeys"), "Log should contain command type. Actual log: " + logOutput);
+ // Verify the size in log matches our response size
+ assertTrue(logOutput.contains("size=" + responseSize + "B"),
+ "Log should contain actual response size. Actual log: " + logOutput);
+ }
+
+ @Test
+ public void testSmallResponseNoLogging() {
+ // Create a small response
+ OMResponse smallResponse = OMResponse.newBuilder()
+ .setCmdType(OzoneManagerProtocolProtos.Type.InfoVolume)
+ .setStatus(OzoneManagerProtocolProtos.Status.OK)
+ .setSuccess(true)
+ .setMessage("Small response")
+ .build();
+
+ long responseSize = smallResponse.getSerializedSize();
+ assertTrue(responseSize < WARN_THRESHOLD,
Review Comment:
Done.
--
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-14061. Log OM request type if response size exceeds threshold [ozone]
Posted by "sadanand48 (via GitHub)" <gi...@apache.org>.
sadanand48 commented on PR #9417:
URL: https://github.com/apache/ozone/pull/9417#issuecomment-3631032728
Thanks @adoroszlai for the review.
--
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-14061. Log the command type if command response size exceeds threshold. [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #9417:
URL: https://github.com/apache/ozone/pull/9417#discussion_r2584202895
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/protocolPB/OzoneManagerProtocolServerSideTranslatorPB.java:
##########
@@ -138,6 +144,30 @@ public OMResponse processRequest(OMRequest request) throws ServiceException {
return response;
}
+ /**
+ * Logs a warning if the OMResponse size exceeds half of the IPC maximum
+ * response size threshold.
+ *
+ * @param response The OMResponse to check
+ */
+ @VisibleForTesting
+ public void logLargeResponseIfNeeded(OMResponse response) {
+ try {
+ Configuration conf = ozoneManager.getConfiguration();
Review Comment:
nit: declare as `ConfigurationSource`
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/protocolPB/OzoneManagerProtocolServerSideTranslatorPB.java:
##########
@@ -138,6 +144,30 @@ public OMResponse processRequest(OMRequest request) throws ServiceException {
return response;
}
+ /**
+ * Logs a warning if the OMResponse size exceeds half of the IPC maximum
+ * response size threshold.
+ *
+ * @param response The OMResponse to check
+ */
+ @VisibleForTesting
+ public void logLargeResponseIfNeeded(OMResponse response) {
+ try {
+ Configuration conf = ozoneManager.getConfiguration();
+ long maxSize = conf.getLong(MAXIMUM_RESPONSE_LENGTH, MAXIMUM_RESPONSE_LENGTH_DEFAULT);
+ long warnThreshold = maxSize / 2;
+
+ long respSize = response.getSerializedSize();
+ if (respSize > warnThreshold) {
+ LOG.warn("Large OMResponse detected: cmd={} size={}B threshold={}B ",
+ response.getCmdType(), respSize, warnThreshold);
+ }
+ } catch (Exception e) {
+ // Don't let logging errors disrupt response generation
+ LOG.debug("Failed to log response size", e);
Review Comment:
Should this be `info`?
##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/response/TestOMResponse.java:
##########
@@ -0,0 +1,154 @@
+/*
+ * 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.om.response;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.google.protobuf.ProtocolMessageEnum;
+import java.nio.file.Path;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.hdds.utils.ProtocolMessageMetrics;
+import org.apache.hadoop.ozone.om.OMConfigKeys;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OmConfig;
+import org.apache.hadoop.ozone.om.OmMetadataManagerImpl;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.execution.OMExecutionFlow;
+import org.apache.hadoop.ozone.om.ratis.OzoneManagerRatisServer;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse;
+import org.apache.hadoop.ozone.protocolPB.OzoneManagerProtocolServerSideTranslatorPB;
+import org.apache.ozone.test.GenericTestUtils;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * Test class for OMResponse related methods.
+ */
+public class TestOMResponse {
+ @TempDir
+ private Path folder;
+
+ private OzoneManagerProtocolServerSideTranslatorPB translator;
+ private GenericTestUtils.LogCapturer logCapturer;
+ private static final long IPC_MAX_LEN = 1024 * 1024; // 1MB
+ private static final long WARN_THRESHOLD = IPC_MAX_LEN / 2; // 512KB
+
+ @BeforeEach
+ public void setup() throws Exception {
+ OzoneConfiguration configuration = new OzoneConfiguration();
+ configuration.set(OMConfigKeys.OZONE_OM_DB_DIRS,
+ folder.toAbsolutePath().toString());
+ configuration.setLong(
+ "ipc.maximum.response.length", IPC_MAX_LEN);
+
+ OzoneManager ozoneManager = mock(OzoneManager.class);
+ OMMetadataManager omMetadataManager = new OmMetadataManagerImpl(
+ configuration, ozoneManager);
+ when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
+ when(ozoneManager.getConfiguration()).thenReturn(configuration);
+
+ final OmConfig omConfig = configuration.getObject(OmConfig.class);
+ when(ozoneManager.getConfig()).thenReturn(omConfig);
+
+ OMExecutionFlow omExecutionFlow = new OMExecutionFlow(ozoneManager);
+ when(ozoneManager.getOmExecutionFlow()).thenReturn(omExecutionFlow);
+
+ OzoneManagerRatisServer ratisServer = mock(OzoneManagerRatisServer.class);
+ when(ratisServer.checkRetryCache()).thenReturn(null);
+
+ ProtocolMessageMetrics<ProtocolMessageEnum> protocolMessageMetrics =
+ mock(ProtocolMessageMetrics.class);
+
+ translator = new OzoneManagerProtocolServerSideTranslatorPB(
+ ozoneManager, ratisServer, protocolMessageMetrics);
+
+ // Capture logs from OzoneManagerProtocolServerSideTranslatorPB
+ logCapturer = GenericTestUtils.LogCapturer.captureLogs(
+ OzoneManagerProtocolServerSideTranslatorPB.class);
+ }
+
+ @AfterEach
+ public void tearDown() {
+ if (logCapturer != null) {
+ logCapturer.stopCapturing();
+ }
+ }
+
+ @Test
+ public void testLargeResponseLogging() {
+ // Create a large response that exceeds the threshold
+ // Use ListKeysResponse with many keys to create a large response
+ OzoneManagerProtocolProtos.ListKeysResponse.Builder listKeysBuilder =
+ OzoneManagerProtocolProtos.ListKeysResponse.newBuilder();
+ for (int i = 0; i < 12000; i++) {
+ listKeysBuilder.addKeyInfo(OzoneManagerProtocolProtos.KeyInfo.newBuilder()
+ .setKeyName("key" + i)
+ .setVolumeName("vol1")
+ .setBucketName("bucket1")
+ .setDataSize(1024)
+ .setCreationTime(System.currentTimeMillis())
+ .setType(HddsProtos.ReplicationType.RATIS)
+ .setModificationTime(System.currentTimeMillis())
+ .build());
+ }
+
+ OMResponse largeResponse = OMResponse.newBuilder()
+ .setCmdType(OzoneManagerProtocolProtos.Type.ListKeys)
+ .setStatus(OzoneManagerProtocolProtos.Status.OK)
+ .setSuccess(true)
+ .setListKeysResponse(listKeysBuilder.build())
+ .build();
+
+ long responseSize = largeResponse.getSerializedSize();
+
+ // Clear previous logs
+ logCapturer.clearOutput();
+ translator.logLargeResponseIfNeeded(largeResponse);
+
+ // Verify logging occurred
+ String logOutput = logCapturer.getOutput();
+ assertTrue(logOutput.contains("Large OMResponse detected"),
Review Comment:
Please use `assertThat(logOutput).contains(...)`, which provides better message including actual value if the assertion fails.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/protocolPB/OzoneManagerProtocolServerSideTranslatorPB.java:
##########
@@ -138,6 +144,30 @@ public OMResponse processRequest(OMRequest request) throws ServiceException {
return response;
}
+ /**
+ * Logs a warning if the OMResponse size exceeds half of the IPC maximum
+ * response size threshold.
+ *
+ * @param response The OMResponse to check
+ */
+ @VisibleForTesting
+ public void logLargeResponseIfNeeded(OMResponse response) {
+ try {
+ Configuration conf = ozoneManager.getConfiguration();
+ long maxSize = conf.getLong(MAXIMUM_RESPONSE_LENGTH, MAXIMUM_RESPONSE_LENGTH_DEFAULT);
+ long warnThreshold = maxSize / 2;
Review Comment:
Can be calculated in the constructor?
##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/response/TestOMResponse.java:
##########
@@ -0,0 +1,154 @@
+/*
+ * 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.om.response;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.google.protobuf.ProtocolMessageEnum;
+import java.nio.file.Path;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.hdds.utils.ProtocolMessageMetrics;
+import org.apache.hadoop.ozone.om.OMConfigKeys;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OmConfig;
+import org.apache.hadoop.ozone.om.OmMetadataManagerImpl;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.execution.OMExecutionFlow;
+import org.apache.hadoop.ozone.om.ratis.OzoneManagerRatisServer;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse;
+import org.apache.hadoop.ozone.protocolPB.OzoneManagerProtocolServerSideTranslatorPB;
+import org.apache.ozone.test.GenericTestUtils;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * Test class for OMResponse related methods.
+ */
+public class TestOMResponse {
+ @TempDir
+ private Path folder;
+
+ private OzoneManagerProtocolServerSideTranslatorPB translator;
+ private GenericTestUtils.LogCapturer logCapturer;
+ private static final long IPC_MAX_LEN = 1024 * 1024; // 1MB
+ private static final long WARN_THRESHOLD = IPC_MAX_LEN / 2; // 512KB
+
+ @BeforeEach
+ public void setup() throws Exception {
+ OzoneConfiguration configuration = new OzoneConfiguration();
+ configuration.set(OMConfigKeys.OZONE_OM_DB_DIRS,
+ folder.toAbsolutePath().toString());
+ configuration.setLong(
+ "ipc.maximum.response.length", IPC_MAX_LEN);
+
+ OzoneManager ozoneManager = mock(OzoneManager.class);
+ OMMetadataManager omMetadataManager = new OmMetadataManagerImpl(
+ configuration, ozoneManager);
+ when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
+ when(ozoneManager.getConfiguration()).thenReturn(configuration);
+
+ final OmConfig omConfig = configuration.getObject(OmConfig.class);
+ when(ozoneManager.getConfig()).thenReturn(omConfig);
+
+ OMExecutionFlow omExecutionFlow = new OMExecutionFlow(ozoneManager);
+ when(ozoneManager.getOmExecutionFlow()).thenReturn(omExecutionFlow);
+
+ OzoneManagerRatisServer ratisServer = mock(OzoneManagerRatisServer.class);
+ when(ratisServer.checkRetryCache()).thenReturn(null);
+
+ ProtocolMessageMetrics<ProtocolMessageEnum> protocolMessageMetrics =
+ mock(ProtocolMessageMetrics.class);
+
+ translator = new OzoneManagerProtocolServerSideTranslatorPB(
+ ozoneManager, ratisServer, protocolMessageMetrics);
+
+ // Capture logs from OzoneManagerProtocolServerSideTranslatorPB
+ logCapturer = GenericTestUtils.LogCapturer.captureLogs(
+ OzoneManagerProtocolServerSideTranslatorPB.class);
+ }
+
+ @AfterEach
+ public void tearDown() {
+ if (logCapturer != null) {
+ logCapturer.stopCapturing();
+ }
+ }
+
+ @Test
+ public void testLargeResponseLogging() {
+ // Create a large response that exceeds the threshold
+ // Use ListKeysResponse with many keys to create a large response
+ OzoneManagerProtocolProtos.ListKeysResponse.Builder listKeysBuilder =
+ OzoneManagerProtocolProtos.ListKeysResponse.newBuilder();
+ for (int i = 0; i < 12000; i++) {
+ listKeysBuilder.addKeyInfo(OzoneManagerProtocolProtos.KeyInfo.newBuilder()
+ .setKeyName("key" + i)
+ .setVolumeName("vol1")
+ .setBucketName("bucket1")
+ .setDataSize(1024)
+ .setCreationTime(System.currentTimeMillis())
+ .setType(HddsProtos.ReplicationType.RATIS)
+ .setModificationTime(System.currentTimeMillis())
+ .build());
+ }
+
+ OMResponse largeResponse = OMResponse.newBuilder()
+ .setCmdType(OzoneManagerProtocolProtos.Type.ListKeys)
+ .setStatus(OzoneManagerProtocolProtos.Status.OK)
+ .setSuccess(true)
+ .setListKeysResponse(listKeysBuilder.build())
+ .build();
+
+ long responseSize = largeResponse.getSerializedSize();
+
+ // Clear previous logs
+ logCapturer.clearOutput();
+ translator.logLargeResponseIfNeeded(largeResponse);
+
+ // Verify logging occurred
+ String logOutput = logCapturer.getOutput();
+ assertTrue(logOutput.contains("Large OMResponse detected"),
+ "Log should contain 'Large OMResponse detected'. Actual log: " + logOutput);
+ assertTrue(logOutput.contains("cmd=ListKeys"), "Log should contain command type. Actual log: " + logOutput);
+ // Verify the size in log matches our response size
+ assertTrue(logOutput.contains("size=" + responseSize + "B"),
+ "Log should contain actual response size. Actual log: " + logOutput);
+ }
+
+ @Test
+ public void testSmallResponseNoLogging() {
+ // Create a small response
+ OMResponse smallResponse = OMResponse.newBuilder()
+ .setCmdType(OzoneManagerProtocolProtos.Type.InfoVolume)
+ .setStatus(OzoneManagerProtocolProtos.Status.OK)
+ .setSuccess(true)
+ .setMessage("Small response")
+ .build();
+
+ long responseSize = smallResponse.getSerializedSize();
+ assertTrue(responseSize < WARN_THRESHOLD,
Review Comment:
Please use `assertThat(responseSize).isLessThan(WARN_THRESHOLD)`
--
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-14061. Log the command type if command response size exceeds threshold. [ozone]
Posted by "sadanand48 (via GitHub)" <gi...@apache.org>.
sadanand48 commented on code in PR #9417:
URL: https://github.com/apache/ozone/pull/9417#discussion_r2601092828
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/protocolPB/OzoneManagerProtocolServerSideTranslatorPB.java:
##########
@@ -138,6 +144,30 @@ public OMResponse processRequest(OMRequest request) throws ServiceException {
return response;
}
+ /**
+ * Logs a warning if the OMResponse size exceeds half of the IPC maximum
+ * response size threshold.
+ *
+ * @param response The OMResponse to check
+ */
+ @VisibleForTesting
+ public void logLargeResponseIfNeeded(OMResponse response) {
+ try {
+ Configuration conf = ozoneManager.getConfiguration();
+ long maxSize = conf.getLong(MAXIMUM_RESPONSE_LENGTH, MAXIMUM_RESPONSE_LENGTH_DEFAULT);
+ long warnThreshold = maxSize / 2;
Review Comment:
Done.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/protocolPB/OzoneManagerProtocolServerSideTranslatorPB.java:
##########
@@ -138,6 +144,30 @@ public OMResponse processRequest(OMRequest request) throws ServiceException {
return response;
}
+ /**
+ * Logs a warning if the OMResponse size exceeds half of the IPC maximum
+ * response size threshold.
+ *
+ * @param response The OMResponse to check
+ */
+ @VisibleForTesting
+ public void logLargeResponseIfNeeded(OMResponse response) {
+ try {
+ Configuration conf = ozoneManager.getConfiguration();
Review Comment:
Done.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/protocolPB/OzoneManagerProtocolServerSideTranslatorPB.java:
##########
@@ -138,6 +144,30 @@ public OMResponse processRequest(OMRequest request) throws ServiceException {
return response;
}
+ /**
+ * Logs a warning if the OMResponse size exceeds half of the IPC maximum
+ * response size threshold.
+ *
+ * @param response The OMResponse to check
+ */
+ @VisibleForTesting
+ public void logLargeResponseIfNeeded(OMResponse response) {
+ try {
+ Configuration conf = ozoneManager.getConfiguration();
+ long maxSize = conf.getLong(MAXIMUM_RESPONSE_LENGTH, MAXIMUM_RESPONSE_LENGTH_DEFAULT);
+ long warnThreshold = maxSize / 2;
+
+ long respSize = response.getSerializedSize();
+ if (respSize > warnThreshold) {
+ LOG.warn("Large OMResponse detected: cmd={} size={}B threshold={}B ",
+ response.getCmdType(), respSize, warnThreshold);
+ }
+ } catch (Exception e) {
+ // Don't let logging errors disrupt response generation
+ LOG.debug("Failed to log response size", e);
Review Comment:
Done.
--
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