Skip to content

Commit 4f1b6c4

Browse files
wangwang
authored andcommitted
merge upstream
2 parents 507b366 + b7139d6 commit 4f1b6c4

File tree

44 files changed

+1049
-42
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1049
-42
lines changed

.github/workflows/plugins-test.1.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ jobs:
7272
- kafka-scenario
7373
- kotlin-coroutine-scenario
7474
- lettuce-scenario
75+
- lettuce-6.5.x-scenario
7576
- mongodb-3.x-scenario
7677
- mongodb-4.x-scenario
7778
- netty-socketio-scenario

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ Release Notes.
1212
initialization. Delay so11y metrics#build when the services are not ready to avoid MeterService status is not
1313
initialized.
1414
* Fix retransform failure when enhancing both parent and child classes.
15+
* Add support for `dameng(DM)` JDBC url format in `URLParser`.
16+
* Fix RabbitMQ Consumer could not receive handleCancelOk callback.
17+
* Support for tracking in lettuce versions 6.5.x and above.
18+
* Upgrade byte-buddy version to 1.17.6.
1519

1620
All issues and pull requests are [here](https://github.com/apache/skywalking/milestone/236?closed=1)
1721

apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,7 @@ public class ComponentsDefine {
262262
public static final OfficialComponent CAFFEINE = new OfficialComponent(160, "Caffeine");
263263

264264
public static final OfficialComponent THREAD_PER_TASK_EXECUTOR = new OfficialComponent(161, "ThreadPerTask-executor");
265+
266+
public static final OfficialComponent DMDB_JDBC_DRIVER = new OfficialComponent(163, "Dmdb-jdbc-driver");
267+
265268
}

apm-sniffer/apm-agent/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
<artifact>net.bytebuddy:byte-buddy</artifact>
107107
<excludes>
108108
<exclude>META-INF/versions/9/module-info.class</exclude>
109+
<exclude>META-INF/versions/24/**</exclude>
109110
</excludes>
110111
</filter>
111112
<filter>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package org.apache.skywalking.apm.plugin.jdbc.connectionurl.parser;
20+
21+
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
22+
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
23+
24+
public class DMURLParser extends AbstractURLParser {
25+
private static final int DEFAULT_PORT = 5236;
26+
private static final String DB_TYPE = "DM";
27+
private static final String URL_PARAMS_HOST_KEY = "host";
28+
private static final String URL_PARAMS_PORT_KEY = "port";
29+
private static final String URL_PARAMS_SCHEMA_KEY = "schema";
30+
31+
public DMURLParser(String url) {
32+
super(url);
33+
}
34+
35+
@Override
36+
protected URLLocation fetchDatabaseHostsIndexRange() {
37+
int hostLabelStartIndex = url.indexOf("//");
38+
if (hostLabelStartIndex == -1) {
39+
return new URLLocation(0, 0);
40+
}
41+
int hostLabelEndIndex = url.indexOf("?", hostLabelStartIndex + 2);
42+
if (hostLabelEndIndex == -1) {
43+
hostLabelEndIndex = url.length();
44+
}
45+
return new URLLocation(hostLabelStartIndex + 2, hostLabelEndIndex);
46+
}
47+
48+
@Override
49+
protected URLLocation fetchDatabaseNameIndexRange() {
50+
return new URLLocation(0, 0);
51+
}
52+
53+
@Override
54+
public ConnectionInfo parse() {
55+
URLLocation location = fetchDatabaseHostsIndexRange();
56+
String hostPortSegment = "";
57+
if (location.endIndex() > location.startIndex()) {
58+
hostPortSegment = url.substring(location.startIndex(), location.endIndex());
59+
}
60+
61+
String host = "";
62+
String port = "";
63+
64+
if (!hostPortSegment.isEmpty()) {
65+
String[] parts = hostPortSegment.split(":");
66+
if (parts.length >= 1) {
67+
host = parts[0];
68+
}
69+
if (parts.length == 2) {
70+
port = parts[1];
71+
}
72+
}
73+
74+
if (host.isEmpty()) {
75+
host = fetchFromUrlParams(URL_PARAMS_HOST_KEY);
76+
}
77+
if (port == null || port.isEmpty()) {
78+
port = fetchFromUrlParams(URL_PARAMS_PORT_KEY);
79+
}
80+
81+
if (port == null || port.isEmpty()) {
82+
port = String.valueOf(DEFAULT_PORT);
83+
}
84+
85+
String schema = fetchFromUrlParams(URL_PARAMS_SCHEMA_KEY);
86+
87+
return new ConnectionInfo(
88+
ComponentsDefine.DMDB_JDBC_DRIVER,
89+
DB_TYPE,
90+
host,
91+
Integer.parseInt(port),
92+
schema == null ? "" : schema
93+
);
94+
}
95+
96+
private String fetchFromUrlParams(String key) {
97+
int paramIndex = url.indexOf("?");
98+
if (paramIndex == -1) {
99+
return null;
100+
}
101+
String[] params = url.substring(paramIndex + 1).split("&");
102+
for (String pair : params) {
103+
if (pair.startsWith(key + "=")) {
104+
String[] segments = pair.split("=", 2);
105+
if (segments.length == 2) {
106+
return segments[1];
107+
}
108+
}
109+
}
110+
return null;
111+
}
112+
}

apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class URLParser {
4141
private static final String DB2_JDBC_URL_PREFIIX = "jdbc:db2:";
4242
private static final String SYBASE_JDBC_URL_PREFIX = "jdbc:sybase:tds:";
4343
private static final String OCEANBASE_JDBC_URL_PREFIX = "jdbc:oceanbase:";
44+
private static final String DM_JDBC_URL_PREFIX = "jdbc:dm:";
4445

4546
public static ConnectionInfo parser(String url) {
4647
ConnectionURLParser parser = null;
@@ -75,7 +76,10 @@ public static ConnectionInfo parser(String url) {
7576
parser = new SybaseURLParser(url);
7677
} else if (lowerCaseUrl.startsWith(OCEANBASE_JDBC_URL_PREFIX)) {
7778
parser = new OceanBaseURLParser(url);
79+
} else if (lowerCaseUrl.startsWith(DM_JDBC_URL_PREFIX)) {
80+
parser = new DMURLParser(url);
7881
}
82+
7983
return parser.parse();
8084
}
8185
}

apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,4 +415,49 @@ public void testParseSybaseJDBCURL() {
415415
assertThat(connectionInfo.getDatabaseName(), is("mydb"));
416416
assertThat(connectionInfo.getDatabasePeer(), is("localhost:5000"));
417417
}
418+
419+
@Test
420+
public void testParseDMJDBCURLWithNamedParams()
421+
{
422+
ConnectionInfo connectionInfo = URLParser.parser("jdbc:dm://?host=localhost&port=5236");
423+
assertThat(connectionInfo.getDBType(), is("DM"));
424+
assertThat(connectionInfo.getDatabaseName(), is(""));
425+
assertThat(connectionInfo.getDatabasePeer(), is("localhost:5236"));
426+
}
427+
428+
@Test
429+
public void testParseDMJDBCURLWithNamedParamsAndScheme()
430+
{
431+
ConnectionInfo connectionInfo = URLParser.parser("jdbc:dm://?host=localhost&port=5236&schema=dm");
432+
assertThat(connectionInfo.getDBType(), is("DM"));
433+
assertThat(connectionInfo.getDatabaseName(), is("dm"));
434+
assertThat(connectionInfo.getDatabasePeer(), is("localhost:5236"));
435+
}
436+
437+
@Test
438+
public void testParseDMJDBCURLWithoutHost()
439+
{
440+
ConnectionInfo connectionInfo = URLParser.parser("jdbc:dm://localhost");
441+
assertThat(connectionInfo.getDBType(), is("DM"));
442+
assertThat(connectionInfo.getDatabaseName(), is(""));
443+
assertThat(connectionInfo.getDatabasePeer(), is("localhost:5236"));
444+
}
445+
446+
@Test
447+
public void testParseDMJDBCURLWithoutHostAndScheme()
448+
{
449+
ConnectionInfo connectionInfo = URLParser.parser("jdbc:dm://localhost?schema=dm");
450+
assertThat(connectionInfo.getDBType(), is("DM"));
451+
assertThat(connectionInfo.getDatabaseName(), is("dm"));
452+
assertThat(connectionInfo.getDatabasePeer(), is("localhost:5236"));
453+
}
454+
455+
@Test
456+
public void testParseDMJDBCURLWithoutHostPort()
457+
{
458+
ConnectionInfo connectionInfo = URLParser.parser("jdbc:dm://localhost:5237?schema=dm");
459+
assertThat(connectionInfo.getDBType(), is("DM"));
460+
assertThat(connectionInfo.getDatabaseName(), is("dm"));
461+
assertThat(connectionInfo.getDatabasePeer(), is("localhost:5237"));
462+
}
418463
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to You under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
~
18+
-->
19+
20+
<project xmlns="http://maven.apache.org/POM/4.0.0"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23+
<modelVersion>4.0.0</modelVersion>
24+
<parent>
25+
<groupId>org.apache.skywalking</groupId>
26+
<artifactId>lettuce-plugins</artifactId>
27+
<version>9.5.0-SNAPSHOT</version>
28+
</parent>
29+
30+
<artifactId>apm-lettuce-5.x-6.4.x-plugin</artifactId>
31+
<packaging>jar</packaging>
32+
33+
<name>lettuce-5.x-6.4.x-plugin</name>
34+
35+
<properties>
36+
<lettuce-core.version>5.0.0.RELEASE</lettuce-core.version>
37+
</properties>
38+
39+
<dependencies>
40+
<dependency>
41+
<groupId>org.apache.skywalking</groupId>
42+
<artifactId>apm-lettuce-common</artifactId>
43+
<version>${project.version}</version>
44+
<scope>provided</scope>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>io.lettuce</groupId>
49+
<artifactId>lettuce-core</artifactId>
50+
<version>${lettuce-core.version}</version>
51+
<scope>provided</scope>
52+
</dependency>
53+
</dependencies>
54+
55+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package org.apache.skywalking.apm.plugin.lettuce.v5;
20+
21+
import io.lettuce.core.protocol.ProtocolKeyword;
22+
import org.apache.skywalking.apm.plugin.lettuce.common.RedisChannelWriterInterceptor;
23+
24+
public class RedisChannelWriterInterceptorV5 extends RedisChannelWriterInterceptor {
25+
@Override
26+
protected String getCommandName(final ProtocolKeyword protocol) {
27+
return protocol.name();
28+
}
29+
}

apm-sniffer/apm-sdk-plugin/lettuce-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/lettuce/v5/define/RedisChannelWriterInstrumentation.java renamed to apm-sniffer/apm-sdk-plugin/lettuce-plugins/lettuce-5.x-6.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/lettuce/v5/define/RedisChannelWriterInstrumentationV5.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,26 @@
1818

1919
package org.apache.skywalking.apm.plugin.lettuce.v5.define;
2020

21+
import java.util.Collections;
22+
import java.util.List;
2123
import net.bytebuddy.description.method.MethodDescription;
2224
import net.bytebuddy.matcher.ElementMatcher;
25+
import net.bytebuddy.matcher.ElementMatchers;
26+
import org.apache.skywalking.apm.agent.core.plugin.WitnessMethod;
2327
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
2428
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
2529
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
2630
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
2731

28-
import java.util.List;
29-
3032
import static net.bytebuddy.matcher.ElementMatchers.named;
3133
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
3234
import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch;
3335

34-
/**
35-
* The writeAndFlush method is used in versions lower than 5.0.2.RELEASE
36-
*/
37-
public class RedisChannelWriterInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
36+
public class RedisChannelWriterInstrumentationV5 extends ClassInstanceMethodsEnhancePluginDefine {
3837

3938
private static final String ENHANCE_CLASS = "io.lettuce.core.RedisChannelWriter";
4039

41-
private static final String REDIS_CHANNEL_WRITER_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.lettuce.v5.RedisChannelWriterInterceptor";
40+
private static final String REDIS_CHANNEL_WRITER_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.lettuce.v5.RedisChannelWriterInterceptorV5";
4241

4342
@Override
4443
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
@@ -47,12 +46,12 @@ public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
4746

4847
@Override
4948
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
50-
return new InstanceMethodsInterceptPoint[]{
49+
return new InstanceMethodsInterceptPoint[] {
5150
new InstanceMethodsInterceptPoint() {
5251
@Override
5352
public ElementMatcher<MethodDescription> getMethodsMatcher() {
5453
return named("write").and(takesArgument(0, named("io.lettuce.core.protocol.RedisCommand")).or(
55-
takesArgument(0, List.class)));
54+
takesArgument(0, List.class)));
5655
}
5756

5857
@Override
@@ -65,11 +64,19 @@ public boolean isOverrideArgs() {
6564
return false;
6665
}
6766
},
68-
};
67+
};
6968
}
7069

7170
@Override
7271
public ClassMatch enhanceClass() {
7372
return byHierarchyMatch(ENHANCE_CLASS);
7473
}
74+
75+
@Override
76+
protected List<WitnessMethod> witnessMethods() {
77+
return Collections.singletonList(new WitnessMethod(
78+
"io.lettuce.core.protocol.ProtocolKeyword",
79+
ElementMatchers.named("name")
80+
));
81+
}
7582
}

0 commit comments

Comments
 (0)