Repository navigation
Classify Redisson Redis server errors #20779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
22
commits into
main
Choose a base branch
from
copilot/redisson-redis-error-classification
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,087
−6
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
28bbbe7
Initial plan
Copilot 5102160
Classify Redisson server errors
Copilot 36a4c0b
Capture Redisson server error replies
Copilot d88c597
Document Redisson latest test range
Copilot 8ea8079
Restore Redisson latest release coverage
Copilot 748681d
Handle dedicated Redisson server errors
Copilot c66ccc7
Preserve Redisson error prefixes across supported versions
trask ffdcff1
Use literal Unicode in Redis prefix tests
trask b03040e
Merge branch 'main' into copilot/redisson-redis-error-classification
trask 775a387
Use shared Redis prefix extraction
Copilot 67ca1b0
Remove redundant Redisson getter test
Copilot c4e9ffa
Capture Redisson batch failure prefixes
Copilot e6c95e6
Merge main into Redisson error classification
trask f581f15
Simplify Redisson decoder capture
Copilot baf0436
Consume captured Redisson server error prefix before completion callb…
Copilot 7955b92
Test reentrant Redisson completion callbacks
Copilot 110a764
Apply suggestion from @trask
trask 281ede5
Refactor Redisson CRLF scanning
Copilot e1db51d
Use named Redis error virtual field
Copilot 75b55b6
Pin Redisson helper unit-test baseline
Copilot 7670cc9
Simplify checked exceptions in Redisson tests
Copilot 693bf82
Rename Redisson error assertion helper
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...ry/javaagent/instrumentation/redisson/common/v3_0/RedisCommandDecoderInstrumentation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.redisson.common.v3_0; | ||
|
|
||
| import static io.opentelemetry.javaagent.instrumentation.redisson.common.v3_0.RedissonErrorCapture.currentServerErrorType; | ||
| import static io.opentelemetry.javaagent.instrumentation.redisson.common.v3_0.RedissonErrorCapture.parseServerErrorType; | ||
| import static net.bytebuddy.matcher.ElementMatchers.named; | ||
| import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
|
||
| import io.netty.buffer.ByteBuf; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
| import javax.annotation.Nullable; | ||
| import net.bytebuddy.asm.Advice; | ||
| import net.bytebuddy.description.type.TypeDescription; | ||
| import net.bytebuddy.matcher.ElementMatcher; | ||
|
|
||
| public class RedisCommandDecoderInstrumentation implements TypeInstrumentation { | ||
|
|
||
| @Override | ||
| public ElementMatcher<TypeDescription> typeMatcher() { | ||
| return named("org.redisson.client.handler.CommandDecoder"); | ||
| } | ||
|
|
||
| @Override | ||
| public void transform(TypeTransformer transformer) { | ||
| transformer.applyAdviceToMethod( | ||
| named("decode") | ||
| .and(takesArgument(0, named("io.netty.buffer.ByteBuf"))) | ||
| .and(takesArgument(1, named("org.redisson.client.protocol.CommandData"))), | ||
| getClass().getName() + "$DecodeAdvice"); | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class DecodeAdvice { | ||
|
|
||
| @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) | ||
| public static String onEnter(@Advice.Argument(0) ByteBuf input) { | ||
| return currentServerErrorType().set(parseServerErrorType(input)); | ||
| } | ||
|
|
||
| @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class, inline = false) | ||
| public static void onExit(@Advice.Enter @Nullable String previousErrorType) { | ||
| currentServerErrorType().restore(previousErrorType); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...io/opentelemetry/javaagent/instrumentation/redisson/common/v3_0/RedissonErrorCapture.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.redisson.common.v3_0; | ||
|
|
||
| import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
|
||
| import io.netty.buffer.ByteBuf; | ||
| import io.opentelemetry.instrumentation.api.incubator.semconv.db.internal.RedisErrorPrefix; | ||
| import io.opentelemetry.instrumentation.api.internal.ScopedThreadValue; | ||
| import io.opentelemetry.instrumentation.api.util.VirtualField; | ||
| import javax.annotation.Nullable; | ||
| import org.redisson.client.RedisException; | ||
|
|
||
| /** | ||
| * Captures the first token from RESP error replies before Redisson completes the command promise. | ||
| * | ||
| * <p>Redisson's {@code CommandDecoder} calls {@code CommandData.tryFailure} while decoding a {@code | ||
| * -} reply, so the token is scoped to that decoder frame and attached to the resulting Redisson | ||
| * exception before completion callbacks can run. The operation listener clears it after extracting | ||
| * telemetry; all other errors use the shared exception-class fallback. | ||
| * | ||
| * @see <a | ||
| * href="https://redis.io/docs/latest/develop/reference/protocol-spec/#resp-protocol-description">RESP | ||
| * specification</a> | ||
| * @see <a | ||
| * href="https://github.com/redisson/redisson/blob/3.52.0/redisson/src/main/java/org/redisson/client/handler/CommandDecoder.java">Redisson | ||
| * CommandDecoder</a> | ||
| */ | ||
| public final class RedissonErrorCapture { | ||
|
|
||
| private static final ScopedThreadValue<String> currentServerErrorType = new ScopedThreadValue<>(); | ||
|
|
||
| private static final VirtualField<RedisException, String> SERVER_ERROR = | ||
| VirtualField.find(RedisException.class, String.class, "redissonServerErrorType"); | ||
|
|
||
| public static ScopedThreadValue<String> currentServerErrorType() { | ||
| return currentServerErrorType; | ||
| } | ||
|
|
||
| @Nullable | ||
| public static String parseServerErrorType(ByteBuf input) { | ||
|
trask marked this conversation as resolved.
|
||
| try { | ||
| int replyStart = input.readerIndex(); | ||
| if (input.getByte(replyStart) != '-') { | ||
| return null; | ||
| } | ||
|
|
||
| int lineStart = replyStart + 1; | ||
| int lineEnd = findCrlf(input, lineStart); | ||
| if (lineEnd == -1) { | ||
| return null; | ||
| } | ||
|
|
||
| return RedisErrorPrefix.extract(input.toString(lineStart, lineEnd - lineStart, UTF_8)); | ||
| } catch (Throwable ignored) { | ||
| // ReplayingDecoder retries incomplete replies; leave buffer handling to Redisson. | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| private static int findCrlf(ByteBuf input, int start) { | ||
| int end = input.writerIndex(); | ||
| for (int i = start; i + 1 < end; i++) { | ||
| if (input.getByte(i) == '\r' && input.getByte(i + 1) == '\n') { | ||
| return i; | ||
| } | ||
| } | ||
| return -1; | ||
| } | ||
|
|
||
| public static void captureServerError(@Nullable Throwable error) { | ||
| if (!(error instanceof RedisException)) { | ||
| return; | ||
| } | ||
|
|
||
| String errorType = currentServerErrorType.get(); | ||
|
trask marked this conversation as resolved.
trask marked this conversation as resolved.
|
||
| if (errorType != null) { | ||
| SERVER_ERROR.set((RedisException) error, errorType); | ||
| // consume so completion callbacks run by tryFailure cannot attribute it to another command | ||
| currentServerErrorType.set(null); | ||
| } | ||
| } | ||
|
|
||
| @Nullable | ||
| public static String getServerErrorType(@Nullable Throwable error) { | ||
| if (!(error instanceof RedisException)) { | ||
| return null; | ||
| } | ||
|
|
||
| return SERVER_ERROR.get((RedisException) error); | ||
| } | ||
|
|
||
| public static void clearServerError(@Nullable Throwable error) { | ||
| if (error instanceof RedisException) { | ||
| SERVER_ERROR.set((RedisException) error, null); | ||
| } | ||
| } | ||
|
|
||
| private RedissonErrorCapture() {} | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.