-
Notifications
You must be signed in to change notification settings - Fork 594
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
Support to trace redisson lock #567
Merged
wu-sheng
merged 6 commits into
apache:main
from
peachisai:feature/support-to-trace-redisson-lock
Jul 2, 2023
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
05cbf94
Support to trace redisson lock
1085ed7
Remove unit from the tag label value of redisson lock interceptor
84250ac
Fix test codes
c5c1728
Fix redisson lock interceptor judge
1fcb20f
Move the duplicated tags into Tags class
2cf8368
Fix the redisson test codes
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 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
73 changes: 73 additions & 0 deletions
73
...n/src/main/java/org/apache/skywalking/apm/plugin/redisson/v3/RedissonLockInterceptor.java
This file contains 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,73 @@ | ||
/* | ||
* 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.redisson.v3; | ||
|
||
import org.apache.skywalking.apm.agent.core.context.ContextManager; | ||
import org.apache.skywalking.apm.agent.core.context.tag.AbstractTag; | ||
import org.apache.skywalking.apm.agent.core.context.tag.Tags; | ||
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; | ||
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; | ||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; | ||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; | ||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; | ||
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; | ||
import org.redisson.api.RLock; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class RedissonLockInterceptor implements InstanceMethodsAroundInterceptor { | ||
|
||
private static final AbstractTag<String> TAG_LOCK_NAME = Tags.ofKey("lock_name"); | ||
|
||
private static final AbstractTag<String> TAG_LEASE_TIME = Tags.ofKey("lease_time"); | ||
|
||
private static final AbstractTag<String> TAG_THREAD_ID = Tags.ofKey("thead_id"); | ||
|
||
@Override | ||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { | ||
AbstractSpan span = ContextManager.createLocalSpan("Redisson/LOCK"); | ||
span.setComponent(ComponentsDefine.REDISSON); | ||
SpanLayer.asCache(span); | ||
RLock rLock = (RLock) objInst; | ||
span.tag(TAG_LOCK_NAME, rLock.getName()); | ||
Tags.CACHE_TYPE.set(span, "Redis"); | ||
TimeUnit unit; | ||
if (allArguments[1] instanceof TimeUnit) { | ||
wu-sheng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
unit = (TimeUnit) allArguments[1]; | ||
span.tag(TAG_LEASE_TIME, String.valueOf(unit.toMillis((Long) allArguments[0]))); | ||
span.tag(TAG_THREAD_ID, String.valueOf(allArguments[2])); | ||
} else if (allArguments[2] instanceof TimeUnit) { | ||
unit = (TimeUnit) allArguments[2]; | ||
span.tag(TAG_LEASE_TIME, String.valueOf(unit.toMillis((Long) allArguments[0]))); | ||
span.tag(TAG_THREAD_ID, String.valueOf(allArguments[3])); | ||
} | ||
} | ||
|
||
@Override | ||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable { | ||
ContextManager.stopSpan(); | ||
return ret; | ||
} | ||
|
||
@Override | ||
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) { | ||
ContextManager.activeSpan().log(t); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...java/org/apache/skywalking/apm/plugin/redisson/v3/define/RedissonLockInstrumentation.java
This file contains 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,72 @@ | ||
/* | ||
* 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.redisson.v3.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.InstanceMethodsInterceptPoint; | ||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; | ||
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; | ||
import org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch; | ||
import org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch; | ||
import org.apache.skywalking.apm.agent.core.plugin.match.logical.LogicalMatchOperation; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
|
||
public class RedissonLockInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { | ||
|
||
private static final String REDISSON_LOCK_CLASS = "org.redisson.RedissonLock"; | ||
|
||
private static final String REDISSON_SPIN_LOCK_CLASS = "org.redisson.RedissonSpinLock"; | ||
|
||
private static final String REDISSON_LOCK_INTERCEPTOR = "org.apache.skywalking.apm.plugin.redisson.v3.RedissonLockInterceptor"; | ||
|
||
@Override | ||
protected ClassMatch enhanceClass() { | ||
return LogicalMatchOperation.or(HierarchyMatch.byHierarchyMatch(REDISSON_LOCK_CLASS), MultiClassNameMatch.byMultiClassMatch(REDISSON_LOCK_CLASS, REDISSON_SPIN_LOCK_CLASS)); | ||
} | ||
|
||
@Override | ||
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { | ||
return new ConstructorInterceptPoint[0]; | ||
} | ||
|
||
@Override | ||
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { | ||
return new InstanceMethodsInterceptPoint[]{ | ||
new InstanceMethodsInterceptPoint() { | ||
@Override | ||
public ElementMatcher<MethodDescription> getMethodsMatcher() { | ||
return named("tryLockInnerAsync"); | ||
} | ||
|
||
@Override | ||
public String getMethodsInterceptor() { | ||
return REDISSON_LOCK_INTERCEPTOR; | ||
} | ||
|
||
@Override | ||
public boolean isOverrideArgs() { | ||
return false; | ||
} | ||
} | ||
}; | ||
} | ||
} |
This file contains 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 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these duplicated? If so, please move them into a
Tags
class to avoid the duplication.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Others are good.