Skip to content

Conversation

@fdesu
Copy link
Contributor

@fdesu fdesu commented Oct 15, 2025

Description

This PR introduces:

  1. a new setting grpc.detailed_errors.enabled (much like the similar http flag.)
  2. handling of the globalParams#errorTrace request parameter

The grpc.detailed_errors.enabled has the same effect as its http counterpart http.detailed_errors.enabled:

  1. fail fast on error_trace=true and the setting turned off
  2. provide only a summary of an error in case error_trace=false
  3. provide full stack trace when error_trace=true

Some of the test evidences are listed in this comment.

Related Issues

Resolves #19639

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • [ ] Public documentation issue/PR created, if applicable.

Please note, that I haven't yet created the public documentation issue/PR for this setting as first I wanted to give this PR a go, get more feedback and then create the corresponding issue/PR.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Summary by CodeRabbit

  • New Features
    • Added a new server setting (grpc.detailed_errors.enabled) to control whether detailed error information is included in gRPC error responses.
    • Added support for global error trace parameter handling, allowing clients to request detailed stack traces and exception information based on server configuration.
    • Implemented validation to ensure consistency between client error trace requests and server settings.

✏️ Tip: You can customize this high-level summary in your review settings.

fdesu added 2 commits October 14, 2025 15:48
…andling

Signed-off-by: Sergei Ustimenko <fdesu@proton.me>
…setting for gRPC

Signed-off-by: Sergei Ustimenko <fdesu@proton.me>
@fdesu fdesu requested a review from a team as a code owner October 15, 2025 09:59
@github-actions github-actions bot added enhancement Enhancement or improvement to existing feature or request Other labels Oct 15, 2025
Signed-off-by: Sergei Ustimenko <fdesu@proton.me>
@github-actions
Copy link
Contributor

❌ Gradle check result for 702f7d9: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Signed-off-by: Sergei Ustimenko <fdesu@proton.me>
@github-actions
Copy link
Contributor

✅ Gradle check result for 6392849: SUCCESS

@codecov
Copy link

codecov bot commented Oct 15, 2025

Codecov Report

❌ Patch coverage is 89.10891% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.29%. Comparing base (a2e1fa2) to head (a5a64e3).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ensearch/transport/grpc/util/GrpcErrorHandler.java 84.61% 6 Missing ⚠️
...ailedexception/SnapshotShardFailureProtoUtils.java 60.00% 0 Missing and 2 partials ⚠️
...rt/grpc/listeners/SearchRequestActionListener.java 75.00% 1 Missing ⚠️
...searchexception/OpenSearchExceptionProtoUtils.java 87.50% 1 Missing ⚠️
...oto/response/search/ShardStatisticsProtoUtils.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #19644      +/-   ##
============================================
+ Coverage     73.27%   73.29%   +0.01%     
- Complexity    71553    71565      +12     
============================================
  Files          5789     5790       +1     
  Lines        327144   327187      +43     
  Branches      47156    47161       +5     
============================================
+ Hits         239715   239798      +83     
+ Misses        68235    68180      -55     
- Partials      19194    19209      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Sergei Ustimenko <fdesu@proton.me>
@github-actions
Copy link
Contributor

❌ Gradle check result for 9b42790: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@fdesu
Copy link
Contributor Author

fdesu commented Oct 21, 2025

Tests with failures:

  • org.opensearch.action.admin.indices.create.CreateIndexIT.testCreateAndDeleteIndexConcurrently
  • org.opensearch.action.admin.indices.create.CreateIndexIT.classMethod

5600 tests completed, 2 failed, 407 skipped

Looks like a failure due to a flaky test, more here: #14312

@fdesu
Copy link
Contributor Author

fdesu commented Oct 21, 2025

Hi folks, this PR is ready for review, could someone please take a look? Thanks a lot!

@karenyrx
Copy link
Contributor

Looks like a failure due to a flaky test

The CI can be rerun by closing/re-opening the PR, or pushing an empty commit. (Or by resolving conflicts which creates a merge commit)

fdesu added 3 commits October 25, 2025 13:52
Signed-off-by: Sergei Ustimenko <fdesu@proton.me>
Signed-off-by: Sergei Ustimenko <fdesu@proton.me>
@github-actions
Copy link
Contributor

✅ Gradle check result for bf4d92f: SUCCESS

fdesu added 4 commits November 4, 2025 12:48
Signed-off-by: Sergei Ustimenko <fdesu@proton.me>
Signed-off-by: Sergei Ustimenko <fdesu@proton.me>
Signed-off-by: Sergei Ustimenko <fdesu@proton.me>
@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2025

❌ Gradle check result for f6d8f9a: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

@karenyrx karenyrx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side question: Do we also eventually plan for support for REST_EXCEPTION_SKIP_STACK_TRACE as well?

@fdesu
Copy link
Contributor Author

fdesu commented Nov 4, 2025

Side question: Do we also eventually plan for support for REST_EXCEPTION_SKIP_STACK_TRACE as well?

@karenyrx, good question. What would be use cases here and what an implementation might look like?

@github-actions
Copy link
Contributor

❕ Gradle check result for 9cd0575: UNSTABLE

Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure.

@fdesu
Copy link
Contributor Author

fdesu commented Nov 11, 2025

@karenyrx could you please have a quick look? All the points seem to be covered and as for the Http Bullk API handling of error_trace, I've raised a separate issue #19945. Happy to polish things further if required!

@github-actions
Copy link
Contributor

❌ Gradle check result for 7863268: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@fdesu fdesu force-pushed the issue/19639-grpc-error-handling-setting branch from d3d661e to 06adbf2 Compare November 14, 2025 13:39
@github-actions
Copy link
Contributor

❌ Gradle check result for 06adbf2: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@github-actions
Copy link
Contributor

❌ Gradle check result for ba7fae3: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@github-actions
Copy link
Contributor

✅ Gradle check result for 0737559: SUCCESS

…ror-handling-setting

Signed-off-by: Sergei Ustimenko <fdesu@proton.me>
@fdesu fdesu force-pushed the issue/19639-grpc-error-handling-setting branch from 7c4c483 to 8767699 Compare November 17, 2025 17:16
@github-actions
Copy link
Contributor

✅ Gradle check result for 8767699: SUCCESS

@fdesu
Copy link
Contributor Author

fdesu commented Nov 17, 2025

The last commit contains the proper DCO, I'll rerun CI anyway, so the PR is marked green.

The issue with DCO was a bit deeper down the line. It's solved now.

Signed-off-by: Sergei Ustimenko <fdesu@proton.me>
Signed-off-by: Sergei Ustimenko <fdesu@proton.me>
Signed-off-by: Sergei Ustimenko <fdesu@proton.me>
Signed-off-by: Sergei Ustimenko <fdesu@proton.me>
Signed-off-by: Sergei Ustimenko <fdesu@proton.me>
@fdesu fdesu force-pushed the issue/19639-grpc-error-handling-setting branch from 4ba8567 to a5a64e3 Compare November 17, 2025 19:31
@github-actions
Copy link
Contributor

✅ Gradle check result for a5a64e3: SUCCESS

@coderabbitai
Copy link

coderabbitai bot commented Dec 4, 2025

Walkthrough

This PR implements handling for the global gRPC error_trace parameter by introducing a new SETTING_GRPC_DETAILED_ERRORS_ENABLED server-side configuration and threading GlobalParams through the error handling pipeline to control stack trace and error detail visibility in gRPC responses.

Changes

Cohort / File(s) Summary
Core Infrastructure
CHANGELOG.md, modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/GrpcPlugin.java, modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/Netty4GrpcServerTransport.java
Adds new setting SETTING_GRPC_DETAILED_ERRORS_ENABLED and exposes it via GrpcPlugin.getSettings(). Initializes GrpcParamsHandler in transport construction.
Global Parameters Handler
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/util/GrpcParamsHandler.java
New utility class managing gRPC global parameter handling with initialization, validation, and configuration checking methods for stack trace requests and server-side detailed error settings.
Request Listeners
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/listeners/BulkRequestActionListener.java, modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/listeners/SearchRequestActionListener.java
Updated constructors to accept and store GlobalParams; propagate params through response and error handling paths.
Service Implementations
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/services/DocumentServiceImpl.java, modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/services/SearchServiceImpl.java
Extract global parameters from requests, validate stack trace configuration, and pass params to listeners and error handlers.
Proto Utilities - Document Responses
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/document/bulk/BulkResponseProtoUtils.java, modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/document/bulk/BulkItemResponseProtoUtils.java, modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/document/common/DocWriteResponseProtoUtils.java, modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/document/common/ShardInfoProtoUtils.java
Thread GlobalParams through proto conversion methods to control error detail inclusion.
Proto Utilities - Exception Handling
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/opensearchexception/OpenSearchExceptionProtoUtils.java, modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/DefaultShardOperationFailedExceptionProtoUtils.java, modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/ReplicationResponseShardInfoFailureProtoUtils.java, modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/ShardOperationFailedExceptionProtoUtils.java, modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/ShardSearchFailureProtoUtils.java, modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/SnapshotShardFailureProtoUtils.java
Accept GlobalParams to control stack trace, cause propagation, and suppressed exception inclusion in serialized errors.
Proto Utilities - Search Responses
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/search/SearchResponseProtoUtils.java, modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/search/ProtoActionsProtoUtils.java, modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/search/ShardStatisticsProtoUtils.java
Thread GlobalParams through search response conversion and shard statistics building.
Error Handler Refactoring
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/util/GrpcErrorHandler.java
Refactored to accept GlobalParams; uses GrpcParamsHandler to determine stack trace inclusion; introduces helper methods for conditional stack trace and XContent metadata generation.
Test Infrastructure
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/TestFixtures.java
New utility class providing test constants and helper methods for GlobalParams configurations.
Test Updates
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/*.java
Updated test instantiations and method calls to pass GlobalParams; added new tests validating stack trace configuration validation and error handling under different trace settings. Tests span GrpcPluginTests, BulkRequestActionListenerTests, SearchRequestActionListenerTests, proto utility tests, service implementation tests, and comprehensive new tests in GrpcErrorHandlerTests and GrpcParamsHandlerTests.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • GrpcErrorHandler.java — Significant refactoring of error serialization logic with conditional stack trace inclusion; verify all exception type mappings correctly propagate the GlobalParams flag and produce expected output formats.
  • OpenSearchExceptionProtoUtils.java — Complex recursive exception serialization with conditional cause and suppressed exception handling; trace parameter threading through all nested conversion paths.
  • GrpcParamsHandler.java — New utility managing global state with thread-safety and validation; verify initialization ordering and exception handling consistency across service implementations.
  • Proto utility chain — Consistent parameter addition across ~8 utility classes; verify no callsites were missed and parameter propagation is complete end-to-end through bulk, search, and shard failure paths.
  • Test coverage — Extensive new test additions (30+ test methods); verify test fixtures and parametrization correctly reflect both enabled and disabled stack trace scenarios.

Suggested reviewers

  • cwperks
  • andrross
  • msfroh

Poem

🐰 A rabbit hops through error traces,
Parameters now thread through all places,
Stack traces dance when clients request,
Global params put error handling to the test!
Hop, hop, hop — gRPC flows with grace. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly summarizes the main change: adding handling for grpc.detailed_errors.enabled setting and global gRPC error_trace parameter, which aligns with the core objective of the changeset.
Description check ✅ Passed The PR description provides clear context about the change: introduces grpc.detailed_errors.enabled setting and error_trace parameter handling with parity to HTTP behavior, linked to issue #19639, includes testing evidence, and confirms API spec PR creation.
Linked Issues check ✅ Passed The PR fully addresses issue #19639 objectives: implements grpc.detailed_errors.enabled setting, handles globalParams#errorTrace parameter, achieves REST parity behavior, and prevents unconditional stack trace exposure via fail-fast validation.
Out of Scope Changes check ✅ Passed All code changes are directly related to the linked issue #19639: implementing the new setting, threading GlobalParams through error handling, adding validation, and updating tests. No unrelated modifications detected.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

…ror-handling-setting

Signed-off-by: Sergei Ustimenko <fdesu@proton.me>
@fdesu fdesu force-pushed the issue/19639-grpc-error-handling-setting branch from 5ceb0ee to 2907384 Compare December 4, 2025 09:09
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/ShardOperationFailedExceptionProtoUtils.java (1)

48-50: Minor typo: Missing space in error message.

There's a missing space before "cannot" in the error message.

             default -> throw new UnsupportedOperationException(
-                "Unsupported ShardOperationFailedException " + exception.getClass().getName() + "cannot be converted to proto."
+                "Unsupported ShardOperationFailedException " + exception.getClass().getName() + " cannot be converted to proto."
             );
🧹 Nitpick comments (12)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/GrpcPluginTests.java (1)

147-147: Consider adding an explicit assertion for the new setting.

The count was updated to 14 to account for SETTING_GRPC_DETAILED_ERRORS_ENABLED, but unlike other settings, there's no explicit assertTrue check verifying it's included. This could mask issues if the setting is accidentally removed later.

         assertTrue("SETTING_GRPC_KEEPALIVE_TIMEOUT should be included", settings.contains(SETTING_GRPC_KEEPALIVE_TIMEOUT));
+        assertTrue("SETTING_GRPC_DETAILED_ERRORS_ENABLED should be included", settings.contains(Netty4GrpcServerTransport.SETTING_GRPC_DETAILED_ERRORS_ENABLED));
 
         // Verify the number of settings
         assertEquals("Should return 14 settings", 14, settings.size());
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/document/bulk/BulkResponseProtoUtils.java (1)

38-56: LGTM - GlobalParams correctly threaded through bulk response conversion.

The params argument is properly propagated to BulkItemResponseProtoUtils.toProto(), enabling consistent error_trace handling for each bulk item's error cause.

Minor cleanup: Consider removing the commented-out debug statement on line 39.

modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/document/common/ShardInfoProtoUtilsTests.java (1)

22-23: LGTM - Tests updated to match new API signature.

The test cases correctly use GLOBAL_PARAMS_WITH_ERROR_TRACE_FALSE for the updated toProto() signature.

Consider adding a test case with GLOBAL_PARAMS_WITH_ERROR_TRACE_TRUE for the testToProtoWithFailures scenario to verify that stack traces are included in the shard failure reasons when error_trace is enabled.

Also applies to: 31-31, 60-60, 92-92

modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/listeners/SearchRequestActionListenerTests.java (1)

37-37: Consider using TestFixtures constants for consistency.

The listener is initialized with GlobalParams.newBuilder().build(). For consistency with other tests and clarity, consider using TestFixtures.GLOBAL_PARAMS_WITH_ERROR_TRACE_FALSE (which is equivalent since errorTrace defaults to false).

+import static org.opensearch.transport.grpc.TestFixtures.GLOBAL_PARAMS_WITH_ERROR_TRACE_FALSE;
...
-        listener = new SearchRequestActionListener(responseObserver, GlobalParams.newBuilder().build());
+        listener = new SearchRequestActionListener(responseObserver, GLOBAL_PARAMS_WITH_ERROR_TRACE_FALSE);
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/TestFixtures.java (1)

14-24: Add private constructor to complete utility class pattern.

The class is correctly marked final, but a private constructor should be added to prevent instantiation, following the utility class pattern used throughout this codebase.

 public final class TestFixtures {

+    private TestFixtures() {
+        // Utility class, no instances
+    }
+
     public static final GlobalParams GLOBAL_PARAMS_WITH_ERROR_TRACE_TRUE = GlobalParams.newBuilder().setErrorTrace(true).build();
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/listeners/SearchRequestActionListener.java (1)

39-43: Consider adding null-check for params parameter.

The constructor stores params without validation, but both onResponse and onFailure paths use it. If a caller passes null, this would cause an NPE when SearchResponseProtoUtils.toProto or GrpcErrorHandler.convertToGrpcError is invoked.

 public SearchRequestActionListener(StreamObserver<org.opensearch.protobufs.SearchResponse> responseObserver, GlobalParams params) {
     super();
+    if (params == null) {
+        throw new IllegalArgumentException("params cannot be null");
+    }
     this.responseObserver = responseObserver;
     this.params = params;
 }
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/document/common/ShardInfoProtoUtils.java (1)

52-60: Missing @param documentation for params.

The Javadoc for the private toProto method is missing the @param params entry to match the updated method signature.

     /**
      * Converts a ReplicationResponse.ShardInfo.Failure Java object to a protobuf ShardFailure.
      * Similar to {@link ReplicationResponse.ShardInfo.Failure#toXContent(XContentBuilder, ToXContent.Params)}
      *
      * @param failure The shard failure to convert to protobuf format
+     * @param params The global gRPC request parameters
      * @return The protobuf representation of the shard failure
      * @throws IOException If there's an error during conversion
      */
     private static ShardFailure toProto(ReplicationResponse.ShardInfo.Failure failure, GlobalParams params) throws IOException {
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/util/GrpcParamsHandlerTests.java (1)

35-43: Simplify the validation pass test.

Using try-catch with fail() is verbose. Since validateStackTraceDetailsConfiguration doesn't return a value, simply calling it without catching exceptions is sufficient—the test framework will fail if an unexpected exception is thrown.

 public void testValidationPassesWhenDetailedErrorsDisabledAndClientDoesNotRequestStackTrace() {
     GrpcParamsHandler.initialize(settingsWithGivenStackTraceConfig(false));
-
-    try {
-        GrpcParamsHandler.validateStackTraceDetailsConfiguration(GLOBAL_PARAMS_WITH_ERROR_TRACE_FALSE);
-    } catch (Exception e) {
-        fail("Validation should pass without exceptions when stack traces are not requested.");
-    }
+    // Should not throw - test framework will fail if exception is thrown
+    GrpcParamsHandler.validateStackTraceDetailsConfiguration(GLOBAL_PARAMS_WITH_ERROR_TRACE_FALSE);
 }
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/services/SearchServiceImplTests.java (2)

44-55: Redundant @After reset when @Before already initializes.

Both @Before and @After call GrpcParamsHandler.initialize(settingsWithGivenStackTraceConfig(true)). Since @Before runs before each test, the @After reset is unnecessary unless there's a concern about test class cleanup affecting other test classes sharing static state.

If the intent is to ensure clean state for other test classes, consider adding a clarifying comment. Otherwise, the @After method can be removed since @Before already handles initialization.


117-130: Misleading variable name in passing test case.

The variable serviceThatFailsToProvideErrorInfo is used in both tests, but its name only accurately describes the first test's scenario. In this test, validation passes and the service operates normally.

     public void testErrorTraceConfigValidationPassesWhenServerSettingIsDisabledAndRequestSkipsStackTrace() {
         // Setup request and the service, server setting is off and request skips a stack trace
         SearchRequest request = createTestSearchRequest().toBuilder()
             .setGlobalParams(org.opensearch.protobufs.GlobalParams.newBuilder().setErrorTrace(false))
             .build();
         GrpcParamsHandler.initialize(settingsWithGivenStackTraceConfig(false));
-        SearchServiceImpl serviceThatFailsToProvideErrorInfo = new SearchServiceImpl(client, queryUtils);
+        SearchServiceImpl serviceWithErrorTracingDisabled = new SearchServiceImpl(client, queryUtils);

         // Call search method
-        serviceThatFailsToProvideErrorInfo.search(request, responseObserver);
+        serviceWithErrorTracingDisabled.search(request, responseObserver);

         // Verify that client.search was called
         verify(client).search(any(org.opensearch.action.search.SearchRequest.class), any());
     }
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/util/GrpcErrorHandler.java (1)

52-57: Incomplete Javadoc for params parameter.

The @param params documentation is incomplete—it should describe what the parameter controls (e.g., "The global gRPC request parameters used to control error detail level").

      * @param e The exception to convert
-     * @param params
+     * @param params The global gRPC request parameters controlling error detail level (e.g., stack trace inclusion)
      * @return StatusRuntimeException with appropriate gRPC status and enhanced error details
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/util/GrpcErrorHandlerTests.java (1)

449-455: Consider adding a two-argument test for null exception handling.

This test uses the single-argument overload convertToGrpcError(null), while all other tests use the two-argument form. For completeness, consider adding a test that verifies null exception handling with the two-argument form as well, ensuring consistent behavior regardless of which overload is used.

public void testNullExceptionConversionWithGlobalParams() {
    StatusRuntimeException result = GrpcErrorHandler.convertToGrpcError(null, GLOBAL_PARAMS_WITH_ERROR_TRACE_FALSE);
    
    assertEquals(Status.INTERNAL.getCode(), result.getStatus().getCode());
    assertEquals("INTERNAL: Unexpected null exception", result.getMessage());
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b7f013f and 2907384.

📒 Files selected for processing (38)
  • CHANGELOG.md (1 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/GrpcPlugin.java (6 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/Netty4GrpcServerTransport.java (1 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/listeners/BulkRequestActionListener.java (4 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/listeners/SearchRequestActionListener.java (2 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/document/bulk/BulkItemResponseProtoUtils.java (3 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/document/bulk/BulkResponseProtoUtils.java (3 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/document/common/DocWriteResponseProtoUtils.java (3 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/document/common/ShardInfoProtoUtils.java (3 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/opensearchexception/OpenSearchExceptionProtoUtils.java (8 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/DefaultShardOperationFailedExceptionProtoUtils.java (6 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/ReplicationResponseShardInfoFailureProtoUtils.java (3 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/ShardOperationFailedExceptionProtoUtils.java (2 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/ShardSearchFailureProtoUtils.java (2 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/SnapshotShardFailureProtoUtils.java (2 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/search/ProtoActionsProtoUtils.java (3 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/search/SearchResponseProtoUtils.java (4 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/search/ShardStatisticsProtoUtils.java (4 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/services/DocumentServiceImpl.java (2 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/services/SearchServiceImpl.java (2 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/util/GrpcErrorHandler.java (8 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/util/GrpcParamsHandler.java (1 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/GrpcPluginTests.java (1 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/TestFixtures.java (1 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/listeners/BulkRequestActionListenerTests.java (2 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/listeners/SearchRequestActionListenerTests.java (3 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/BulkResponseProtoUtilsTests.java (4 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/document/bulk/BulkItemResponseProtoUtilsTests.java (8 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/document/common/DocWriteResponseProtoUtilsTests.java (5 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/document/common/ShardInfoProtoUtilsTests.java (3 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/exceptions/OpenSearchExceptionProtoUtilsTests.java (11 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/DefaultShardOperationFailedExceptionProtoUtilsTests.java (6 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/ShardOperationFailedExceptionProtoUtilsTests.java (6 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/search/SearchResponseProtoUtilsTests.java (8 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/services/SearchServiceImplTests.java (5 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/services/document/DocumentServiceImplTests.java (5 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/util/GrpcErrorHandlerTests.java (16 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/util/GrpcParamsHandlerTests.java (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (23)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/ShardOperationFailedExceptionProtoUtilsTests.java (2)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/TestFixtures.java (1)
  • TestFixtures (14-24)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/ShardOperationFailedExceptionProtoUtils.java (1)
  • ShardOperationFailedExceptionProtoUtils (25-53)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/document/bulk/BulkResponseProtoUtils.java (1)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/document/bulk/BulkItemResponseProtoUtils.java (1)
  • BulkItemResponseProtoUtils (31-98)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/document/common/DocWriteResponseProtoUtils.java (1)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/document/common/ShardInfoProtoUtils.java (1)
  • ShardInfoProtoUtils (23-70)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/SnapshotShardFailureProtoUtils.java (1)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/opensearchexception/OpenSearchExceptionProtoUtils.java (1)
  • OpenSearchExceptionProtoUtils (50-273)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/BulkResponseProtoUtilsTests.java (2)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/TestFixtures.java (1)
  • TestFixtures (14-24)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/document/bulk/BulkResponseProtoUtils.java (1)
  • BulkResponseProtoUtils (23-80)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/listeners/BulkRequestActionListenerTests.java (1)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/TestFixtures.java (1)
  • TestFixtures (14-24)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/document/bulk/BulkItemResponseProtoUtilsTests.java (2)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/TestFixtures.java (1)
  • TestFixtures (14-24)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/document/bulk/BulkItemResponseProtoUtils.java (1)
  • BulkItemResponseProtoUtils (31-98)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/search/ProtoActionsProtoUtils.java (1)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/search/ShardStatisticsProtoUtils.java (1)
  • ShardStatisticsProtoUtils (27-69)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/services/document/DocumentServiceImplTests.java (2)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/util/GrpcParamsHandler.java (1)
  • GrpcParamsHandler (30-82)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/TestFixtures.java (1)
  • TestFixtures (14-24)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/util/GrpcErrorHandler.java (3)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/util/GrpcParamsHandler.java (1)
  • GrpcParamsHandler (30-82)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/util/RestToGrpcStatusConverter.java (1)
  • RestToGrpcStatusConverter (18-152)
libs/core/src/main/java/org/opensearch/ExceptionsHelper.java (1)
  • ExceptionsHelper (76-476)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/GrpcPlugin.java (2)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/util/GrpcParamsHandler.java (1)
  • GrpcParamsHandler (30-82)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/Netty4GrpcServerTransport.java (1)
  • Netty4GrpcServerTransport (64-501)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/services/SearchServiceImpl.java (2)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/util/GrpcParamsHandler.java (1)
  • GrpcParamsHandler (30-82)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/util/GrpcErrorHandler.java (1)
  • GrpcErrorHandler (36-225)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/services/SearchServiceImplTests.java (2)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/util/GrpcParamsHandler.java (1)
  • GrpcParamsHandler (30-82)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/TestFixtures.java (1)
  • TestFixtures (14-24)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/listeners/SearchRequestActionListener.java (2)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/search/SearchResponseProtoUtils.java (1)
  • SearchResponseProtoUtils (25-208)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/util/GrpcErrorHandler.java (1)
  • GrpcErrorHandler (36-225)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/ReplicationResponseShardInfoFailureProtoUtils.java (1)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/opensearchexception/OpenSearchExceptionProtoUtils.java (1)
  • OpenSearchExceptionProtoUtils (50-273)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/search/SearchResponseProtoUtilsTests.java (2)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/TestFixtures.java (1)
  • TestFixtures (14-24)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/search/SearchResponseProtoUtils.java (1)
  • SearchResponseProtoUtils (25-208)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/TestFixtures.java (1)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/Netty4GrpcServerTransport.java (1)
  • Netty4GrpcServerTransport (64-501)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/DefaultShardOperationFailedExceptionProtoUtils.java (1)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/opensearchexception/OpenSearchExceptionProtoUtils.java (1)
  • OpenSearchExceptionProtoUtils (50-273)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/search/ShardStatisticsProtoUtils.java (1)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/ShardOperationFailedExceptionProtoUtils.java (1)
  • ShardOperationFailedExceptionProtoUtils (25-53)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/util/GrpcParamsHandlerTests.java (1)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/TestFixtures.java (1)
  • TestFixtures (14-24)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/opensearchexception/OpenSearchExceptionProtoUtils.java (2)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/util/GrpcParamsHandler.java (1)
  • GrpcParamsHandler (30-82)
libs/core/src/main/java/org/opensearch/ExceptionsHelper.java (1)
  • ExceptionsHelper (76-476)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/document/common/ShardInfoProtoUtilsTests.java (2)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/TestFixtures.java (1)
  • TestFixtures (14-24)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/document/common/ShardInfoProtoUtils.java (1)
  • ShardInfoProtoUtils (23-70)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/exceptions/OpenSearchExceptionProtoUtilsTests.java (2)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/TestFixtures.java (1)
  • TestFixtures (14-24)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/opensearchexception/OpenSearchExceptionProtoUtils.java (1)
  • OpenSearchExceptionProtoUtils (50-273)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
  • GitHub Check: gradle-check
  • GitHub Check: assemble (25, windows-latest)
  • GitHub Check: assemble (21, ubuntu-latest)
  • GitHub Check: assemble (25, ubuntu-latest)
  • GitHub Check: assemble (21, ubuntu-24.04-arm)
  • GitHub Check: assemble (25, ubuntu-24.04-arm)
  • GitHub Check: assemble (21, windows-latest)
  • GitHub Check: precommit (21, windows-latest)
  • GitHub Check: precommit (25, macos-15-intel)
  • GitHub Check: precommit (25, ubuntu-latest)
  • GitHub Check: precommit (25, macos-15)
  • GitHub Check: precommit (21, windows-2025, true)
  • GitHub Check: precommit (21, ubuntu-24.04-arm)
  • GitHub Check: precommit (25, ubuntu-24.04-arm)
  • GitHub Check: precommit (21, macos-15)
  • GitHub Check: precommit (25, windows-latest)
  • GitHub Check: precommit (21, ubuntu-latest)
  • GitHub Check: precommit (21, macos-15-intel)
  • GitHub Check: Analyze (java)
🔇 Additional comments (61)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/document/bulk/BulkItemResponseProtoUtilsTests.java (2)

33-34: LGTM!

The static import for GLOBAL_PARAMS_WITH_ERROR_TRACE_FALSE from TestFixtures provides a clean way to supply the required GlobalParams parameter across all test cases.


52-55: Consistent update to the new method signature.

All toProto calls are correctly updated to pass GLOBAL_PARAMS_WITH_ERROR_TRACE_FALSE, aligning with the production code's new signature that requires GlobalParams for error trace control.

modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/ShardOperationFailedExceptionProtoUtilsTests.java (2)

24-24: LGTM!

Static import added consistently with other test files in this PR.


136-144: Single-argument toProto overload exists and the test is valid.

The test code compiles successfully as shown in the final state, confirming the single-argument toProto(ShardOperationFailedException) overload is present. No action required.

modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/document/common/DocWriteResponseProtoUtilsTests.java (1)

20-21: LGTM!

Import and test updates are consistent with the pattern established across other test files in this PR.

modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/BulkResponseProtoUtilsTests.java (1)

25-26: LGTM!

Consistent with the GlobalParams propagation pattern across all updated test files.

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/document/common/DocWriteResponseProtoUtils.java (3)

13-13: LGTM!

Import added for the new GlobalParams parameter type.


35-39: Proper Javadoc and signature update for GlobalParams threading.

The method signature correctly includes the GlobalParams parameter with appropriate documentation. This enables error trace control to propagate through the proto conversion chain.


61-61: Correct propagation of GlobalParams to downstream conversion.

GlobalParams is properly passed to ShardInfoProtoUtils.toProto, which (per the relevant code snippet) uses it when generating error causes via OpenSearchExceptionProtoUtils.generateThrowableProto. This ensures consistent error trace behavior for shard failure information.

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/Netty4GrpcServerTransport.java (1)

190-200: Well-structured setting definition with clear documentation.

The new SETTING_GRPC_DETAILED_ERRORS_ENABLED setting follows the established pattern for gRPC transport settings. The Javadoc clearly explains the interaction between this server-side setting and the per-request error_trace parameter, which matches the PR's stated objectives for parity with HTTP behavior. Verify that this setting is consumed in GrpcParamsHandler or the relevant error handling implementation.

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/GrpcPlugin.java (3)

189-189: LGTM - GrpcParamsHandler initialization properly wired.

The initialization call correctly precedes transport and service creation, ensuring the handler is configured before any gRPC request processing occurs.


241-241: Consistent initialization in secure transport path.

Matches the non-secure path initialization pattern, ensuring both transport types respect the grpc.detailed_errors.enabled setting.


291-292: Setting correctly exposed via getSettings().

The new SETTING_GRPC_DETAILED_ERRORS_ENABLED is properly registered, allowing OpenSearch to recognize and validate the setting at node startup.

modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/listeners/BulkRequestActionListenerTests.java (1)

26-26: LGTM - Listener test properly updated for new constructor signature.

The test correctly passes GLOBAL_PARAMS_WITH_ERROR_TRACE_FALSE to the listener constructor, aligning with the production code changes.

Also applies to: 41-41

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/ReplicationResponseShardInfoFailureProtoUtils.java (1)

36-48: LGTM - GlobalParams correctly propagated for error reason generation.

The params argument is properly passed to generateThrowableProto(), ensuring stack trace inclusion respects the error_trace setting when generating the shard failure reason.

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/ShardSearchFailureProtoUtils.java (1)

36-44: LGTM - GlobalParams correctly propagated for search failure reason generation.

The params argument is properly passed to generateThrowableProto(), ensuring consistent error_trace handling for shard search failures.

modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/search/SearchResponseProtoUtilsTests.java (1)

24-24: LGTM - Consistent GlobalParams propagation in tests.

The test updates correctly align with the new toProto(SearchResponse, GlobalParams) API signature. All tests consistently use GLOBAL_PARAMS_WITH_ERROR_TRACE_FALSE.

Consider adding a test case with GLOBAL_PARAMS_WITH_ERROR_TRACE_TRUE to verify behavior when error traces are enabled, particularly for scenarios involving shard failures where the GlobalParams would affect error serialization.

Also applies to: 45-48

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/services/DocumentServiceImpl.java (1)

46-56: LGTM - Proper GlobalParams validation and propagation.

The implementation correctly:

  1. Validates stack trace configuration early (fail-fast pattern)
  2. Propagates GlobalParams to both the listener and error handler
  3. Handles validation failures through the existing exception path
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/ShardOperationFailedExceptionProtoUtils.java (1)

39-44: LGTM - Consistent GlobalParams propagation through exception handling.

The GlobalParams parameter is correctly propagated to all specialized exception proto utilities through the switch expression.

modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/listeners/SearchRequestActionListenerTests.java (1)

62-71: LGTM - Test correctly validates failure handling.

The test properly verifies that onFailure triggers onError with a StatusRuntimeException. The refactoring to use the class-level responseObserver is cleaner.

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/search/ProtoActionsProtoUtils.java (1)

43-54: LGTM - Clean GlobalParams propagation.

The GlobalParams parameter is correctly added to the method signature and propagated to ShardStatisticsProtoUtils.getShardStats, enabling error trace control for shard failure serialization.

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/search/SearchResponseProtoUtils.java (1)

40-44: LGTM - Proper GlobalParams threading through search response conversion.

The GlobalParams is correctly propagated through the conversion chain to ProtoActionsProtoUtils.buildBroadcastShardsHeader, enabling proper error trace control for shard failures in search responses.

Also applies to: 88-97

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/services/SearchServiceImpl.java (1)

60-75: LGTM - Consistent implementation with proper error handling.

The implementation correctly:

  1. Validates stack trace configuration early via GrpcParamsHandler.validateStackTraceDetailsConfiguration
  2. Propagates GlobalParams to the listener and error handler
  3. Handles both RuntimeException and IOException appropriately

This aligns well with DocumentServiceImpl and the broader GlobalParams propagation pattern.

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/SnapshotShardFailureProtoUtils.java (1)

36-49: Null-safety improvements and GlobalParams propagation look good.

The addition of null checks for index() and nodeId() (lines 38-45) is a good defensive practice. The method signature correctly propagates GlobalParams to control error detail level, aligning with the broader PR changes.

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/document/bulk/BulkItemResponseProtoUtils.java (1)

48-70: LGTM! GlobalParams propagation is correctly implemented.

The GlobalParams parameter is properly passed to both DocWriteResponseProtoUtils.toProto for success cases and OpenSearchExceptionProtoUtils.generateThrowableProto for failure cases, ensuring consistent error detail control throughout the response conversion pipeline.

modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/exceptions/OpenSearchExceptionProtoUtilsTests.java (3)

58-70: Good test coverage for summary mode.

This test correctly verifies that when error_trace=false, the resulting ErrorCause does not include stack trace, suppressed exceptions, or cause information. This validates the core behavior of the new GlobalParams-driven detail control.


95-116: Thorough nested exception testing for summary mode.

This test verifies that the summary mode correctly propagates through nested exceptions—both the outer exception and its cause should lack stack traces when error_trace=false, while still preserving the cause chain structure (type, reason). Good coverage of the recursive behavior.


205-217: Good symmetry with testInnerToProtoWithBasicException.

This new test provides the counterpart to the existing basic exception test, verifying that generateThrowableProto correctly omits stack traces when error_trace=false.

modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/services/document/DocumentServiceImplTests.java (4)

44-54: Good test setup with proper cleanup, though redundant.

The @After method ensures test isolation by resetting GrpcParamsHandler state, which is important since it uses static AtomicBoolean. However, both @Before and @After set the same value (true). Consider if the teardown is strictly necessary given it duplicates the setup.


81-92: Good test for server-side error trace rejection.

This test correctly validates that when grpc.detailed_errors.enabled=false and a request has errorTrace=true, the service rejects the request with a StatusRuntimeException. This aligns with the PR objective of failing fast when traces are requested but disabled.


94-107: Good test for allowed requests when server setting is disabled.

This test verifies that requests with errorTrace=false proceed normally even when the server setting is disabled. The test correctly rebuilds the request with modified GlobalParams and verifies that client.bulk is invoked.


117-121: Default request now includes errorTrace(true).

The helper method now sets errorTrace=true by default, which ensures existing tests exercise the stack-trace-enabled path. This is a sensible default for test coverage.

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/search/ShardStatisticsProtoUtils.java (1)

46-67: LGTM! Consistent GlobalParams propagation.

The GlobalParams parameter is correctly added to the method signature and propagated to ShardOperationFailedExceptionProtoUtils.toProto for shard failure conversion. This maintains consistency with the broader PR pattern of threading GlobalParams through all proto conversion utilities.

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/listeners/SearchRequestActionListener.java (1)

45-64: LGTM!

The GlobalParams is correctly propagated through both the success path (toProto) and error paths (convertToGrpcError), ensuring consistent error trace behavior across all response scenarios.

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/document/common/ShardInfoProtoUtils.java (1)

38-50: LGTM!

The GlobalParams propagation through the shard failure conversion chain ensures that error trace settings are respected when generating the failure reason proto.

modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/util/GrpcParamsHandlerTests.java (1)

18-54: Good test coverage for the critical validation paths.

The tests cover the key scenarios: validation failure when server disables traces but client requests them, and successful validation when client doesn't request traces. The isDetailedStackTraceRequested test verifies the basic parameter extraction.

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/util/GrpcParamsHandler.java (2)

30-46: LGTM! Thread-safe initialization with proper static state management.

The use of AtomicBoolean ensures thread-safe access to the detailedErrorsEnabled flag. The default value of true provides a safe starting state, and the initialize method correctly reads from the gRPC-specific setting.


76-80: Validation logic correctly implements fail-fast behavior.

The check detailedErrorsEnabled.get() == false && globalRequestParams.getErrorTrace() precisely enforces the requirement: reject requests that ask for error traces when the server has disabled them, aligning with the HTTP-side http.detailed_errors.enabled behavior.

modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/services/SearchServiceImplTests.java (1)

132-138: Good default for test helper.

Setting ErrorTrace(true) as the default in createTestSearchRequest ensures existing tests exercise the primary use case, while tests needing different behavior can override via toBuilder() as shown in testErrorTraceConfigValidationPassesWhenServerSettingIsDisabledAndRequestSkipsStackTrace.

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/listeners/BulkRequestActionListener.java (2)

30-42: LGTM! Clean threading of GlobalParams through the listener.

The GlobalParams field is properly stored and the constructor cleanly accepts and assigns the parameter. The Javadoc accurately describes the purpose.


51-75: Consistent error handling with GlobalParams.

Both the success path (with potential conversion failure) and the failure path properly pass params to GrpcErrorHandler.convertToGrpcError, ensuring consistent stack trace behavior based on request parameters.

modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/DefaultShardOperationFailedExceptionProtoUtilsTests.java (3)

21-22: Appropriate use of test fixture for consistent test behavior.

Using GLOBAL_PARAMS_WITH_ERROR_TRACE_FALSE ensures tests verify the non-stack-trace path consistently.


25-126: Test coverage appropriately updated for new API.

All exception type test cases (DefaultShardOperationFailedException, AddBlockShardResult.Failure, IndicesShardStoresResponse.Failure, CloseIndexResponse.ShardResult.Failure, and null nodeId scenario) correctly pass GLOBAL_PARAMS_WITH_ERROR_TRACE_FALSE to the updated toProto method.


128-135: Missing GlobalParams parameter in null test case.

This test calls toProto(null) with a single argument, but the updated API signature is toProto(DefaultShardOperationFailedException, GlobalParams). Either this test should be updated to pass GLOBAL_PARAMS_WITH_ERROR_TRACE_FALSE, or there's a separate overload for null handling that needs verification.

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/opensearchexception/OpenSearchExceptionProtoUtils.java (4)

20-21: Appropriate imports for GlobalParams support.

The imports for GlobalParams and GrpcParamsHandler are correctly added to support the new param-driven error detail control.


66-81: Correct propagation of GlobalParams through exception unwrapping.

Both the unwrapped cause path (generateThrowableProto(ex, params)) and the direct conversion path (innerToProto(..., params)) properly receive the GlobalParams parameter.


96-104: Proper delegation with GlobalParams in both exception branches.

The method correctly passes params to both toProto (for OpenSearchException) and innerToProto (for generic Throwable), maintaining consistent error detail behavior.


121-190: Well-implemented param-driven stack trace control.

The innerToProto method correctly:

  1. Propagates params to recursive generateThrowableProto calls for cause (line 166) and suppressed exceptions (line 185)
  2. Uses GrpcParamsHandler.isDetailedStackTraceRequested(params) to conditionally include stack traces (lines 177-179)

This ensures consistent error detail behavior throughout the exception hierarchy.

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/util/GrpcErrorHandler.java (5)

39-41: Clear constant for stack trace inclusion.

The INCLUDE_STACK_TRACES constant correctly sets REST_EXCEPTION_SKIP_STACK_TRACE to "false", which means stack traces will be included when this parameter is used. The naming aligns with the intent.


62-136: Consistent error detail handling across all exception types.

All exception branches properly use getErrorDetailsForConfig(exception, shouldIncludeDetailedStackTrace) to determine error detail level, with appropriate special handling for OpenSearchException (delegated to handleOpenSearchException) and null (static message).


148-159: Proper threading of stack trace flag to XContent metadata enhancement.

The handleOpenSearchException method correctly passes shouldIncludeDetailedStackTrace to enhanceDescriptionWithXContentMetadata, ensuring consistent error detail behavior for OpenSearchExceptions.


184-190: Correct separation of request-level and server-level error detail controls.

The implementation properly distinguishes between:

  1. shouldIncludeDetailedStackTrace (request parameter) → controls INCLUDE_STACK_TRACES vs EMPTY_PARAMS for XContent serialization
  2. GrpcParamsHandler.isDetailedErrorsEnabled() (server setting) → passed to generateFailureXContent

This aligns with the PR objective of providing both per-request and server-side control over error details.


215-223: Clean helper for conditional error detail selection.

The getErrorDetailsForConfig method clearly encapsulates the decision between full stack trace and simple message based on the request parameter. This avoids code duplication across all exception branches.

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/DefaultShardOperationFailedExceptionProtoUtils.java (4)

16-17: Appropriate import for GlobalParams.

The GlobalParams import is correctly added to support the param-driven error detail control.


40-60: Consistent GlobalParams propagation through all exception type branches.

The toProto method correctly passes params to all specialized innerToProto overloads and to parentInnerToProto for the default case. The null case appropriately returns an empty builder without needing params.


71-118: All innerToProto overloads correctly thread GlobalParams.

Each specialized innerToProto method for AddBlockShardResult.Failure, IndicesShardStoresResponse.Failure, and CloseIndexResponse.ShardResult.Failure properly accepts GlobalParams and passes it to parentInnerToProto. Javadocs are appropriately updated.


129-142: Critical integration point: GlobalParams flows to reason generation.

The parentInnerToProto method correctly passes params to OpenSearchExceptionProtoUtils.generateThrowableProto when building the failure reason. This ensures the error detail level (stack traces) is controlled by the request parameters throughout the entire exception conversion chain.

modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/util/GrpcErrorHandlerTests.java (4)

40-48: LGTM: Setup and teardown ensure consistent test state.

Both methods initialize with true to ensure each test starts with a known state and resets after completion, preventing state leakage between tests.


96-118: Missing test case: server-side disabled with error_trace=true should fail fast.

Per the PR objectives, when grpc.detailed_errors.enabled is false and a request includes error_trace=true, the server should "fail fast with an error indicating traces are disabled." This test only covers the case where both server-side config and request parameter are false.

Consider adding a test for the fail-fast behavior:

public void testOpenSearchExceptionConversionWhenDetailedErrorsAreDisabledButClientRequestsThem() {
    GrpcParamsHandler.initialize(settingsWithGivenStackTraceConfig(false));
    OpenSearchException exception = new OpenSearchException("Test exception") {
        @Override
        public RestStatus status() {
            return RestStatus.BAD_REQUEST;
        }
    };

    StatusRuntimeException result = GrpcErrorHandler.convertToGrpcError(exception, GLOBAL_PARAMS_WITH_ERROR_TRACE_TRUE);

    // Should fail fast with INVALID_ARGUMENT indicating traces are disabled
    assertEquals(Status.INVALID_ARGUMENT.getCode(), result.getStatus().getCode());
    assertTrue(result.getMessage().contains("error traces in responses are disabled"));
}

120-331: LGTM: Comprehensive test coverage for error_trace behavior across exception types.

The paired tests (with and without error trace) for each exception type provide good coverage of the new two-argument API. The assertions verify both the gRPC status code mapping and the expected message content based on the error_trace parameter.


333-447: LGTM: Edge cases are well covered.

Good coverage of edge cases including null messages, metadata extraction, XContent failures, and root cause analysis. The graceful fallback behavior when XContent extraction fails (line 422: assertFalse(result.getMessage().contains("details="))) is particularly important for robustness.

Comment on lines +18 to 20
- Add handling for the global gRPC error_trace parameter ([#19644](https://github.com/opensearch-project/OpenSearch/pull/19644))
- Handle deleted documents for filter rewrite subaggregation optimization ([#19643](https://github.com/opensearch-project/OpenSearch/pull/19643))
- Handle deleted documents for filter rewrite sub-aggregation optimization ([#19643](https://github.com/opensearch-project/OpenSearch/pull/19643))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Incomplete changelog entry and duplicate entry detected.

Line 18 describes the PR but only mentions the error_trace parameter, omitting the grpc.detailed_errors.enabled setting that was introduced according to the PR objectives. Additionally, lines 19 and 20 are duplicate entries—both reference PR #19643 with nearly identical descriptions but inconsistent terminology ("subaggregation" vs. "sub-aggregation").

Apply this diff to expand the gRPC entry and remove the duplicate:

- Add handling for the global gRPC error_trace parameter ([#19644](https://github.com/opensearch-project/OpenSearch/pull/19644))
- Handle deleted documents for filter rewrite subaggregation optimization ([#19643](https://github.com/opensearch-project/OpenSearch/pull/19643))
- Handle deleted documents for filter rewrite sub-aggregation optimization ([#19643](https://github.com/opensearch-project/OpenSearch/pull/19643))
+ Add handling for the global gRPC error_trace parameter and grpc.detailed_errors.enabled setting ([#19644](https://github.com/opensearch-project/OpenSearch/pull/19644))
+ Handle deleted documents for filter rewrite sub-aggregation optimization ([#19643](https://github.com/opensearch-project/OpenSearch/pull/19643))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- Add handling for the global gRPC error_trace parameter ([#19644](https://github.com/opensearch-project/OpenSearch/pull/19644))
- Handle deleted documents for filter rewrite subaggregation optimization ([#19643](https://github.com/opensearch-project/OpenSearch/pull/19643))
- Handle deleted documents for filter rewrite sub-aggregation optimization ([#19643](https://github.com/opensearch-project/OpenSearch/pull/19643))
- Add handling for the global gRPC error_trace parameter and grpc.detailed_errors.enabled setting ([#19644](https://github.com/opensearch-project/OpenSearch/pull/19644))
- Handle deleted documents for filter rewrite sub-aggregation optimization ([#19643](https://github.com/opensearch-project/OpenSearch/pull/19643))
🤖 Prompt for AI Agents
In CHANGELOG.md around lines 18 to 20, the gRPC changelog entry is incomplete
and there is a duplicate entry for PR #19643; update the gRPC line to mention
both the global gRPC error_trace parameter and the new
grpc.detailed_errors.enabled setting (briefly describe their effect), remove one
of the duplicate lines for PR #19643, and normalize the remaining PR #19643
entry to use consistent wording (e.g., "sub-aggregation") so the three bullets
read: the expanded gRPC item and a single, consistently-worded filter rewrite
sub-aggregation optimization line.

shardFailure.setNode(exception.nodeId());
}
shardFailure.setStatus(exception.status().name());
shardFailure.setReason(OpenSearchExceptionProtoUtils.generateThrowableProto(exception.getCause(), params));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Find SnapshotShardFailure class and getCause() method
find . -type f -name "SnapshotShardFailure.java" | head -5

Repository: opensearch-project/OpenSearch

Length of output: 202


🏁 Script executed:

# Search for getCause() in SnapshotShardFailure or related classes
rg -n "class SnapshotShardFailure" --type java -A 20

Repository: opensearch-project/OpenSearch

Length of output: 202


🏁 Script executed:

# Search for generateThrowableProto implementation
rg -n "def generateThrowableProto|public.*generateThrowableProto" --type java -B 2 -A 10

Repository: opensearch-project/OpenSearch

Length of output: 202


🏁 Script executed:

# Search for ExceptionsHelper.unwrapCause implementation
rg -n "unwrapCause" --type java -B 2 -A 10

Repository: opensearch-project/OpenSearch

Length of output: 202


🌐 Web query:

OpenSearch ExceptionsHelper unwrapCause null handling

💡 Result:

Short answer: ExceptionsHelper.unwrapCause(t) returns the deepest (unwrapped) throwable it can find — and if there is no deeper cause it returns the original throwable. In other words, passing a null or a throwable with no cause yields the input (null stays null; a throwable with no cause is returned as-is). This is the behavior used in Elasticsearch / OpenSearch code that calls ExceptionsHelper.unwrapCause to find the “real” cause before mapping to status/handling. [1][2]

Sources

  • Elasticsearch/OpenSearch usage and description of unwrapCause/why it’s used. [1]
  • Analysis/implementation notes showing the unwrapping loop and behavior when no deeper cause is found. [2]

🌐 Web query:

OpenSearch OpenSearchExceptionProtoUtils generateThrowableProto null safety

💡 Result:

Short answer: guard against null before calling generateThrowableProto (or change the util to accept/handle null). OpenSearch utilities don’t always null-check throwables—so either check t != null and supply a default, or modify generateThrowableProto to return an empty/placeholder proto when passed null.

Suggested options (Java):

  1. Call-site null check
  • Before calling:
    if (t == null) { /* build placeholder proto or skip */ } else { OpenSearchExceptionProtoUtils.generateThrowableProto(builder, t); }
  1. Small defensive wrapper
  • Wrap the utility so nulls are handled centrally:
    public static void safeGenerateThrowableProto(Builder b, @nullable Throwable t) throws IOException {
    if (t == null) {
    b.setType("null").setMessage("no throwable");
    return;
    }
    OpenSearchExceptionProtoUtils.generateThrowableProto(b, t);
    }
  1. Patch the util (if you maintain the code)
  • Edit generateThrowableProto to accept @nullable and early-return or populate a safe placeholder when t == null.

Rationale: OpenSearch exception XContent/proto helpers (see EngineException generateThrowableXContent for analogous behavior) are not guaranteed to accept null Throwables; many community reports show NPEs if exception data is missing, so defensive checks are required. [1][2]

References:

  • EngineException.generateThrowableXContent (OpenSearch source reference for exception serialization helpers). [1]
  • Community reports of NullPointerExceptions related to exception/aggregation serialization in OpenSearch logs/forums. [2]

If you want, tell me which OpenSearch version and the exact stack trace or code and I’ll give a concrete patch or wrapper snippet.


🌐 Web query:

SnapshotShardFailure getCause OpenSearch repository

💡 Result:

Use the Snapshot Status API (or the Java client SnapshotShardFailure model). The snapshot status response contains a failures array of SnapshotShardFailure entries; each failure exposes the human-readable failure text as the "reason" (the SnapshotShardFailure model has a reason field). Call GET /_snapshot// or GET /_snapshot/_status and inspect failures[].reason (or use the Java client SnapshotShardFailure.reason getter). [1][2]

Sources:

  • OpenSearch Java client snapshot types (SnapshotShardFailure in API docs). [1]
  • OpenSearch docs / error-log explaining snapshot failures and where the specific reason appears in the response. [2]

Potential NPE if exception.getCause() returns null.

The generateThrowableProto method does not safely handle null throwables. While ExceptionsHelper.unwrapCause() itself handles null gracefully, the proto generation utility requires defensive null-checking at call sites.

Add a null check before passing the cause:

-        shardFailure.setReason(OpenSearchExceptionProtoUtils.generateThrowableProto(exception.getCause(), params));
+        if (exception.getCause() != null) {
+            shardFailure.setReason(OpenSearchExceptionProtoUtils.generateThrowableProto(exception.getCause(), params));
+        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
shardFailure.setReason(OpenSearchExceptionProtoUtils.generateThrowableProto(exception.getCause(), params));
if (exception.getCause() != null) {
shardFailure.setReason(OpenSearchExceptionProtoUtils.generateThrowableProto(exception.getCause(), params));
}
🤖 Prompt for AI Agents
In
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/shardoperationfailedexception/SnapshotShardFailureProtoUtils.java
around line 47, the call
shardFailure.setReason(OpenSearchExceptionProtoUtils.generateThrowableProto(exception.getCause(),
params)); can NPE if exception.getCause() is null; add a defensive null check
and only call generateThrowableProto if cause != null, otherwise setReason(null)
or skip setting it, ensuring you use the unwrapped cause
(ExceptionsHelper.unwrapCause(exception)) if required and pass that to
generateThrowableProto when non-null.

*
* @param response The SearchResponse to convert
* @param searchResponseProtoBuilder The builder to populate with the SearchResponse data
* @param params
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Incomplete Javadoc for params parameter.

The @param params lacks a description. It should match the documentation style used elsewhere.

-     * @param params
+     * @param params The global gRPC request parameters
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
* @param params
* @param params The global gRPC request parameters
🤖 Prompt for AI Agents
In
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/search/SearchResponseProtoUtils.java
around line 52, the Javadoc contains an incomplete @param params tag; update the
Javadoc to include a brief description of what params represents (e.g., explain
that it is the serialization/deserialization parameters or context used when
converting SearchResponse to/from proto), following the same phrasing and style
as other @param tags in this class (concise, present-tense description), and
ensure the tag is formatted and aligned consistently with surrounding Javadoc
entries.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 4, 2025

❌ Gradle check result for 2907384: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@fdesu fdesu marked this pull request as draft December 5, 2025 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Enhancement or improvement to existing feature or request Other

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request][gRPC] Add separate error handling setting for gRPC

2 participants