Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
be675c2
Feat: Add a plugin that supports the Solon framework.
xsShuang Jun 20, 2024
06732e8
Update ComponentsDefine.java
xsShuang Jun 20, 2024
924c61f
Add Solon plugin test
xsShuang Jun 20, 2024
ffd56db
Merge remote-tracking branch 'origin/main'
xsShuang Jun 20, 2024
dbd24b4
Add Solon plugin test
xsShuang Jun 20, 2024
0b2afff
Add Solon plugin test and update doc.
xsShuang Jun 22, 2024
b96e8c5
Merge remote-tracking branch 'origin/main'
xsShuang Jun 22, 2024
88ef3ca
merge the latest commits.
xsShuang Jun 22, 2024
0716d24
Modify the test code.
xsShuang Jun 22, 2024
1704f4d
Modify the test code.
xsShuang Jun 22, 2024
0d32357
Improvement of processing span code and test case information
xsShuang Jun 22, 2024
47eb826
Modify the test code.
xsShuang Jun 22, 2024
c77ba51
Merge branch 'apache:main' into main
xsShuang Jun 26, 2024
4b772bf
Merge remote-tracking branch 'origin/main'
xsShuang Jun 26, 2024
b68aa80
Modify the test code.
xsShuang Jun 26, 2024
62884f5
Merge remote-tracking branch 'origin/main'
xsShuang Jun 26, 2024
c05c8f8
update skywalking-solon-2.x-scenario pom.xml
xsShuang Jun 26, 2024
05bc9e5
Modify the test code.
xsShuang Jun 27, 2024
ae6c7cf
Merge pull request #1 from xsShuang/dev
xsShuang Jun 27, 2024
d253974
modify def file
xsShuang Jun 27, 2024
20a3507
Merge pull request #2 from xsShuang/dev
xsShuang Jun 27, 2024
2b72e14
update solon plugin
xsShuang Jun 27, 2024
8fcb404
Modify the test code.
xsShuang Jun 27, 2024
a8cb8c3
Modify the test code.
xsShuang Jun 27, 2024
f6ffd0e
Merge pull request #3 from xsShuang/dev
xsShuang Jun 27, 2024
3ace531
Add plugin configuration and instructions
xsShuang Jun 28, 2024
53b9c5a
Add plugin configuration and instructions
xsShuang Jun 28, 2024
ca6ff8b
Modify the test code.
xsShuang Jun 28, 2024
c205c1a
Merge pull request #4 from xsShuang/dev
xsShuang Jun 28, 2024
4b5e558
Add plugin configuration and instructions
xsShuang Jun 28, 2024
5fbdc2a
Merge pull request #5 from xsShuang/dev
xsShuang Jun 28, 2024
4982488
Add plugin configuration and instructions
xsShuang Jun 28, 2024
916dc21
Merge pull request #6 from xsShuang/dev
xsShuang Jun 28, 2024
505e99c
Modified to V2 version of the interceptor
xsShuang Jun 28, 2024
115727f
Modified to V2 version of the interceptor
xsShuang Jun 28, 2024
24799a6
Modified to V2 version of the interceptor
xsShuang Jun 28, 2024
22a4a8f
Merge pull request #7 from xsShuang/dev
xsShuang Jun 28, 2024
3524717
Modified to V2 version of the interceptor
xsShuang Jun 28, 2024
160668c
Remove the code that collects all headers by default
xsShuang Jun 28, 2024
08bdfcb
Merge pull request #8 from xsShuang/dev
xsShuang Jun 28, 2024
38cb7b1
Optimised code
xsShuang Jun 28, 2024
193b532
Modify the test code.
xsShuang Jun 28, 2024
20c3545
Modify the test code.
xsShuang Jun 28, 2024
9f3392e
Merge pull request #9 from xsShuang/dev
xsShuang Jun 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,6 @@ public class ComponentsDefine {

public static final OfficialComponent OCEANBASE_JDBC_DRIVER = new OfficialComponent(157, "OceanBase-jdbc-driver");

public static final OfficialComponent SOLON_MVC = new OfficialComponent(158, "SolonMVC");

}
48 changes: 48 additions & 0 deletions apm-sniffer/apm-sdk-plugin/solon-2.x-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0"?>
<!--
~ 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.
~
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>apm-sdk-plugin</artifactId>
<groupId>org.apache.skywalking</groupId>
<version>9.3.0-SNAPSHOT</version>
</parent>

<artifactId>solon-2.x-plugin</artifactId>
<packaging>jar</packaging>

<name>solon-plugin</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<apache-httpclient.version>4.3</apache-httpclient.version>
<junit.version>4.12</junit.version>
</properties>

<dependencies>
<dependency>
<groupId>org.noear</groupId>
<artifactId>solon-lib</artifactId>
<version>2.8.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/*
* 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.solon;

public class FastPathMatcher {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is this? I think we didn't discuss about this part.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ignore plugin is reading configurations from the agent folder, why do ou need that for Solon?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

solon 不需要他,是我自己想添加这样一个功能。尽管有 trace-ignore-plugin 这个插件,但我认为这个插件是在链路追踪后写入数据时阻止忽略的数据写入,而我希望的是插件在生效时,直接过滤排除的 url 请求地址

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

这个类用 进行 URL 地址匹配,从而实现排除某些不需要链路追踪 URL 的目的

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please keep in English in GH discussion.

I don't think ignoring should be implemented by a specific plugin of a specific framework.

Please remove this part.

AFAIK, the existing ignore plugin could collaborate with your plugin automatically.


public boolean match(String pattern, String path) {
return normalMatch(pattern, 0, path, 0);
}

private boolean normalMatch(String pat, int p, String str, int s) {
while (p < pat.length()) {
char pc = pat.charAt(p);
char sc = safeCharAt(str, s);

// Got * in pattern, enter the wildcard mode.
// ↓ ↓
// pattern: a/* a/*
// ↓ ↓
// string: a/bcd a/
if (pc == '*') {
p++;
// Got * in pattern again, enter the multi-wildcard mode.
// ↓ ↓
// pattern: a/** a/**
// ↓ ↓
// string: a/bcd a/
if (safeCharAt(pat, p) == '*') {
p++;
// Enter the multi-wildcard mode.
// ↓ ↓
// pattern: a/** a/**
// ↓ ↓
// string: a/bcd a/
return multiWildcardMatch(pat, p, str, s);
} else {
// Enter the wildcard mode.
// ↓
// pattern: a/*
// ↓
// string: a/bcd
return wildcardMatch(pat, p, str, s);
}
}

// Matching ? for non-'/' char, or matching the same chars.
// ↓ ↓ ↓
// pattern: a/?/c a/b/c a/b
// ↓ ↓ ↓
// string: a/b/c a/b/d a/d
if (pc == '?' && sc != 0 && sc != '/' || pc == sc) {
s++;
p++;
continue;
}

// Not matched.
// ↓
// pattern: a/b
// ↓
// string: a/c
return false;
}

return s == str.length();
}

private boolean wildcardMatch(String pat, int p, String str, int s) {
char pc = safeCharAt(pat, p);

// End of pattern, check string only has zero or one '/' at end.
// ↓ ↓
// pattern: a/* a/*
// ↓ ↓
// string: a/bc/ a/bc
if (pc == 0) {
while (true) {
char sc = safeCharAt(str, s);
// No '/' found
if (sc == 0) return true;
// Check '/' is the last char of string
if (sc == '/') return s == str.length() - 1;
s++;
}
}

while (true) {
char sc = safeCharAt(str, s);

if (sc == '/') {
// Both of pattern and string '/' matched, exit wildcard mode.
// ↓
// pattern: a/*/
// ↓
// string: a/bc/
if (pc == sc) {
return normalMatch(pat, p + 1, str, s + 1);
}

// Not matched string in current path part.
// ↓ ↓
// pattern: a/* a/*d
// ↓ ↓
// string: a/bc/ a/bc/
return false;
}

// Try to enter normal mode, if not matched, increasing pointer of string and try again.
if (!normalMatch(pat, p, str, s)) {
// End of string, not matched.
if (s >= str.length()) {
return false;
}

s++;
continue;
}

// Matched in next normal mode.
return true;
}
}

private boolean multiWildcardMatch(String pat, int p, String str, int s) {
switch (safeCharAt(pat, p)) {
// End of pattern, just return true quickly.
case 0: return true;
// Skip next '/' for pattern to match zero path part.
case '/': p++;
}

while (true) {
// Try to enter normal mode, if not matched, increasing pointer of string and try again.
if (!normalMatch(pat, p, str, s)) {
// End of string, not matched.
if (s >= str.length()) {
return false;
}

s++;
continue;
}

return true;
}
}

private char safeCharAt(String value, int index) {
if (index >= value.length()) {
return 0;
}

return value.charAt(index);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* 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.solon;

import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.apm.agent.core.context.CarrierItem;
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
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.apache.skywalking.apm.util.StringUtil;
import org.noear.solon.Utils;
import org.noear.solon.core.handle.Context;

import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

@Slf4j
public class SolonActionExecuteInterceptor implements InstanceMethodsAroundInterceptor {

private static FastPathMatcher pathMatcher = new FastPathMatcher();

private final Set<String> excludePaths = new HashSet<>();

private final Set<String> matchPaths = new HashSet<>();

public SolonActionExecuteInterceptor() {
String excluded = System.getProperty("skywalking.agent.solon.excluded", "");
if (Utils.isNotEmpty(excluded)) {
for (String path : excluded.split(",")) {
path = path.trim();
if (!path.isEmpty()) {
if (!path.startsWith("/")) {
path = "/" + path;
}
if (path.contains("*")) {
matchPaths.add(path);
} else {
excludePaths.add(path);
}
}
}
}
}

public boolean pathMatch(String path) {
for (String matchPath : matchPaths) {
if (pathMatcher.match(matchPath, path)) {
return true;
}
}
return false;
}

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
Context ctx = (Context) allArguments[0];
if (excludePaths.contains(ctx.pathNew()) || pathMatch(ctx.pathNew())) {
return;
}
ContextCarrier contextCarrier = new ContextCarrier();
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
next.setHeadValue(ctx.header(next.getHeadKey()));
}
String operationName = "Solon:" + ctx.method() + ":" + ctx.path();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
String operationName = "Solon:" + ctx.method() + ":" + ctx.path();
String operationName = ctx.method() + ":" + ctx.path();

The operation name of the span should be framework stack irrelevant. And you need to change test cases accordingly.

AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier);
span.setComponent(ComponentsDefine.SOLON_MVC);
Comment thread
wu-sheng marked this conversation as resolved.
Comment thread
wu-sheng marked this conversation as resolved.
SpanLayer.asHttp(span);
span.tag("http.method", ctx.method());
span.tag("http.path", ctx.path());
span.tag("framework", "solon");
for (Map.Entry<String, String> stringStringEntry : ctx.headerMap().entrySet()) {
span.tag(stringStringEntry.getKey(), stringStringEntry.getValue());
}
String body = ctx.body();
if (StringUtil.isNotBlank(body)) {
if (body.length() > 1024) {
body = body.substring(0, 1024);
}
span.tag("http.body", body);
}
String param = ctx.paramMap().toString();
if (param.length() > 1024) {
param = param.substring(0, 1024);
}
span.tag("http.param", param);
}

@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) {
Context ctx = (Context) allArguments[0];
if (excludePaths.contains(ctx.pathNew()) || pathMatch(ctx.pathNew())) {
return ret;
}

ContextManager.activeSpan().tag("http.status_code", String.valueOf(ctx.status()));
ContextManager.stopSpan();
return ret;
}

@Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes, Throwable t) {
AbstractSpan activeSpan = ContextManager.activeSpan();
activeSpan.log(t);
}
}
Loading