-
Notifications
You must be signed in to change notification settings - Fork 670
Added support for Lettuce reactive Redis commands #788
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
wuwen5
wants to merge
6
commits into
apache:main
Choose a base branch
from
wuwen5:lettuce-reactive
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.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
df5c04c
Added support for Lettuce reactive Redis commands
wuwen5 f68a73f
Merge branch 'main' into lettuce-reactive
wuwen5 d06112c
Add RedisCommandEnhanceInfo to manage tracing data for Lettuce commands
wuwen5 11bc1a3
Add dependency management for Spring Boot in pom.xml (Resolve log com…
wuwen5 f40fc96
Update expectedData.yaml and RedisChannelWriterInterceptor for improv…
wuwen5 b62a04a
Merge branch 'main' into lettuce-reactive
wu-sheng 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
39 changes: 39 additions & 0 deletions
39
.../apache/skywalking/apm/plugin/lettuce/common/RedisSubscriptionConstructorInterceptor.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,39 @@ | ||
| /* | ||
| * 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.skywalking.apm.plugin.lettuce.common; | ||
|
|
||
| import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; | ||
| import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; | ||
|
|
||
| /** | ||
| * Interceptor for RedisSubscription constructor. | ||
| * <p> | ||
| * This interceptor captures the {@link io.lettuce.core.protocol.RedisCommand} instance | ||
| * at subscription construction time and stores it into SkyWalking dynamic field. | ||
| * </p> | ||
| */ | ||
| public class RedisSubscriptionConstructorInterceptor implements InstanceConstructorInterceptor { | ||
|
|
||
| @Override | ||
| public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { | ||
| // allArguments[1] is the RedisCommand passed to the RedisSubscription constructor | ||
| objInst.setSkyWalkingDynamicField(allArguments[1]); | ||
| } | ||
|
|
||
| } |
59 changes: 59 additions & 0 deletions
59
...che/skywalking/apm/plugin/lettuce/common/RedisSubscriptionSubscribeMethodInterceptor.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,59 @@ | ||
| /* | ||
| * 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.skywalking.apm.plugin.lettuce.common; | ||
|
|
||
| import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; | ||
| import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.v2.InstanceMethodsAroundInterceptorV2; | ||
| import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.v2.MethodInvocationContext; | ||
| import reactor.core.CoreSubscriber; | ||
|
|
||
| import java.lang.reflect.Method; | ||
|
|
||
| /** | ||
| * Interceptor for {@code RedisPublisher.RedisSubscription#subscribe(Subscriber)} method. | ||
| * | ||
| * <p> | ||
| * This interceptor works together with the constructor interceptor of | ||
| * {@code RedisSubscription}: | ||
| * </p> | ||
| */ | ||
| public class RedisSubscriptionSubscribeMethodInterceptor implements InstanceMethodsAroundInterceptorV2 { | ||
|
|
||
| @Override | ||
| public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInvocationContext context) { | ||
| if (allArguments[0] instanceof CoreSubscriber) { | ||
| CoreSubscriber<?> subscriber = (CoreSubscriber<?>) allArguments[0]; | ||
| // get ContextSnapshot from reactor context, the snapshot is set to reactor context by any other plugin | ||
| // such as DispatcherHandlerHandleMethodInterceptor in spring-webflux-5.x-plugin | ||
| Object skywalkingContextSnapshot = subscriber.currentContext().getOrDefault("SKYWALKING_CONTEXT_SNAPSHOT", null); | ||
| if (skywalkingContextSnapshot != null) { | ||
| ((EnhancedInstance) objInst.getSkyWalkingDynamicField()).setSkyWalkingDynamicField(skywalkingContextSnapshot); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret, MethodInvocationContext context) { | ||
| return ret; | ||
| } | ||
|
|
||
| @Override | ||
| public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t, MethodInvocationContext context) { | ||
| } | ||
| } |
86 changes: 86 additions & 0 deletions
86
.../apache/skywalking/apm/plugin/lettuce/common/define/RedisSubscriptionInstrumentation.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,86 @@ | ||
| /* | ||
| * 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.skywalking.apm.plugin.lettuce.common.define; | ||
|
|
||
| import net.bytebuddy.description.method.MethodDescription; | ||
| import net.bytebuddy.matcher.ElementMatcher; | ||
| import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; | ||
| import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.v2.ClassInstanceMethodsEnhancePluginDefineV2; | ||
| import org.apache.skywalking.apm.agent.core.plugin.interceptor.v2.InstanceMethodsInterceptV2Point; | ||
| import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; | ||
|
|
||
| import static net.bytebuddy.matcher.ElementMatchers.any; | ||
| import static net.bytebuddy.matcher.ElementMatchers.named; | ||
| import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
| import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| public class RedisSubscriptionInstrumentation extends ClassInstanceMethodsEnhancePluginDefineV2 { | ||
|
|
||
| private static final String ENHANCE_CLASS = "io.lettuce.core.RedisPublisher$RedisSubscription"; | ||
|
|
||
| private static final String REDIS_SUBSCRIPTION_SUBSCRIBE_METHOD_INTERCEPTOR = "org.apache.skywalking.apm.plugin.lettuce.common.RedisSubscriptionSubscribeMethodInterceptor"; | ||
| private static final String REDIS_SUBSCRIPTION_CONST_METHOD_INTERCEPTOR = "org.apache.skywalking.apm.plugin.lettuce.common.RedisSubscriptionConstructorInterceptor"; | ||
|
|
||
| @Override | ||
| public InstanceMethodsInterceptV2Point[] getInstanceMethodsInterceptV2Points() { | ||
| return new InstanceMethodsInterceptV2Point[]{ | ||
| new InstanceMethodsInterceptV2Point() { | ||
| @Override | ||
| public ElementMatcher<MethodDescription> getMethodsMatcher() { | ||
| return named("subscribe"); | ||
| } | ||
|
|
||
| @Override | ||
| public String getMethodsInterceptorV2() { | ||
| return REDIS_SUBSCRIPTION_SUBSCRIBE_METHOD_INTERCEPTOR; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isOverrideArgs() { | ||
| return false; | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| public ClassMatch enhanceClass() { | ||
| return byName(ENHANCE_CLASS); | ||
| } | ||
|
|
||
| @Override | ||
| public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { | ||
| return new ConstructorInterceptPoint[] { | ||
| new ConstructorInterceptPoint() { | ||
| @Override | ||
| public ElementMatcher<MethodDescription> getConstructorMatcher() { | ||
| return any().and(takesArgument(1, named("io.lettuce.core.protocol.RedisCommand"))); | ||
| } | ||
|
|
||
| @Override | ||
| public String getConstructorInterceptor() { | ||
| return REDIS_SUBSCRIPTION_CONST_METHOD_INTERCEPTOR; | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| } |
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
21 changes: 21 additions & 0 deletions
21
test/plugin/scenarios/lettuce-webflux-5x-scenario/bin/startup.sh
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,21 @@ | ||
| #!/bin/bash | ||
| # | ||
| # 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. | ||
|
|
||
| home="$(cd "$(dirname $0)"; pwd)" | ||
|
|
||
| java -Dredis.host=${REDIS_SERVERS} -jar -Dskywalking.plugin.lettuce.trace_redis_parameters=true ${agent_opts} ${home}/../libs/lettuce-webflux-5x-scenario.jar & |
119 changes: 119 additions & 0 deletions
119
test/plugin/scenarios/lettuce-webflux-5x-scenario/config/expectedData.yaml
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,119 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| segmentItems: | ||
| - serviceName: lettuce-webflux-5x-scenario | ||
| segmentSize: nq 0 | ||
| segments: | ||
| - segmentId: not null | ||
| spans: | ||
| - operationName: /case/healthCheck | ||
| parentSpanId: -1 | ||
| spanId: 0 | ||
| spanLayer: Http | ||
| startTime: not null | ||
| endTime: not null | ||
| componentId: 67 | ||
| isError: false | ||
| spanType: Entry | ||
| peer: '' | ||
| skipAnalysis: false | ||
| tags: | ||
| - {key: url, value: 'http://localhost:8080/case/healthCheck'} | ||
| - {key: http.method, value: HEAD} | ||
| - {key: http.status_code, value: '200'} | ||
| - segmentId: not null | ||
| spans: | ||
| - operationName: Lettuce/GET | ||
| parentSpanId: -1 | ||
| spanId: 0 | ||
| spanLayer: Cache | ||
| startTime: not null | ||
| endTime: not null | ||
| componentId: 57 | ||
| isError: false | ||
| spanType: Exit | ||
| peer: not null | ||
| skipAnalysis: false | ||
| tags: | ||
| - {key: cache.type, value: Redis} | ||
| - {key: cache.key, value: key} | ||
| - {key: cache.cmd, value: GET} | ||
| - {key: cache.op, value: read} | ||
| refs: | ||
| - { parentEndpoint: /case/lettuce-case, networkAddress: '', refType: CrossThread, | ||
| parentSpanId: 0, parentTraceSegmentId: not null, parentServiceInstance: not | ||
| null, parentService: not null, traceId: not null } | ||
| - segmentId: not null | ||
| spans: | ||
| - operationName: Lettuce/SET | ||
| parentSpanId: -1 | ||
| spanId: 0 | ||
| spanLayer: Cache | ||
| startTime: not null | ||
| endTime: not null | ||
| componentId: 57 | ||
| isError: false | ||
| spanType: Exit | ||
| peer: not null | ||
| skipAnalysis: false | ||
| tags: | ||
| - { key: cache.type, value: Redis } | ||
| - { key: cache.key, value: key0 } | ||
| - { key: cache.cmd, value: SET } | ||
| - { key: cache.op, value: write } | ||
| refs: | ||
| - { parentEndpoint: /case/lettuce-case, networkAddress: '', refType: CrossThread, | ||
| parentSpanId: 0, parentTraceSegmentId: not null, parentServiceInstance: not | ||
| null, parentService: not null, traceId: not null } | ||
| - segmentId: not null | ||
| spans: | ||
| - operationName: Lettuce/SET | ||
| parentSpanId: -1 | ||
| spanId: 0 | ||
| spanLayer: Cache | ||
| startTime: not null | ||
| endTime: not null | ||
| componentId: 57 | ||
| isError: false | ||
| spanType: Exit | ||
| peer: not null | ||
| skipAnalysis: false | ||
| tags: | ||
| - { key: cache.type, value: Redis } | ||
| - { key: cache.key, value: key1 } | ||
| - { key: cache.cmd, value: SET } | ||
| - { key: cache.op, value: write } | ||
| refs: | ||
| - { parentEndpoint: /case/lettuce-case, networkAddress: '', refType: CrossThread, | ||
| parentSpanId: 0, parentTraceSegmentId: not null, parentServiceInstance: not | ||
| null, parentService: not null, traceId: not null } | ||
| - segmentId: not null | ||
| spans: | ||
| - operationName: /case/lettuce-case | ||
| parentSpanId: -1 | ||
| spanId: 0 | ||
| spanLayer: Http | ||
| startTime: not null | ||
| endTime: not null | ||
| componentId: 67 | ||
| isError: false | ||
| spanType: Entry | ||
| peer: '' | ||
| skipAnalysis: false | ||
| tags: | ||
| - {key: url, value: 'http://localhost:8080/case/lettuce-case'} | ||
| - {key: http.method, value: GET} | ||
| - {key: http.status_code, value: '200'} |
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.