Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
SkyWalking
提交
5f26710d
S
SkyWalking
项目概览
apache
/
SkyWalking
上一次同步 大约 1 年
通知
302
Star
21345
Fork
6091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
5f26710d
编写于
5月 10, 2021
作者:
W
wallezhang
提交者:
GitHub
5月 10, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix pulsar plugin message listener error with multi partitions topic (#6918)
上级
94adbf1c
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
273 addition
and
51 deletion
+273
-51
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/main/java/org/apache/skywalking/apm/plugin/pulsar/ConsumerConstructorInterceptor.java
...ing/apm/plugin/pulsar/ConsumerConstructorInterceptor.java
+0
-1
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/main/java/org/apache/skywalking/apm/plugin/pulsar/ConsumerEnhanceRequiredInfo.java
...alking/apm/plugin/pulsar/ConsumerEnhanceRequiredInfo.java
+0
-13
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/main/java/org/apache/skywalking/apm/plugin/pulsar/PulsarConsumerInterceptor.java
...ywalking/apm/plugin/pulsar/PulsarConsumerInterceptor.java
+8
-10
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/main/java/org/apache/skywalking/apm/plugin/pulsar/PulsarConsumerListenerInterceptor.java
.../apm/plugin/pulsar/PulsarConsumerListenerInterceptor.java
+1
-1
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/main/java/org/apache/skywalking/apm/plugin/pulsar/TopicMessageConstructorInterceptor.java
...apm/plugin/pulsar/TopicMessageConstructorInterceptor.java
+45
-0
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/main/java/org/apache/skywalking/apm/plugin/pulsar/define/MessageInstrumentation.java
...king/apm/plugin/pulsar/define/MessageInstrumentation.java
+3
-3
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/main/java/org/apache/skywalking/apm/plugin/pulsar/define/TopicMessageInstrumentation.java
...apm/plugin/pulsar/define/TopicMessageInstrumentation.java
+71
-0
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/main/resources/skywalking-plugin.def
...in/pulsar-plugin/src/main/resources/skywalking-plugin.def
+2
-1
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/test/java/org/apache/skywalking/apm/plugin/pulsar/ConsumerConstructorInterceptorTest.java
...apm/plugin/pulsar/ConsumerConstructorInterceptorTest.java
+0
-9
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/test/java/org/apache/skywalking/apm/plugin/pulsar/PulsarConsumerInterceptorTest.java
...king/apm/plugin/pulsar/PulsarConsumerInterceptorTest.java
+0
-1
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/test/java/org/apache/skywalking/apm/plugin/pulsar/PulsarConsumerListenerInterceptorTest.java
.../plugin/pulsar/PulsarConsumerListenerInterceptorTest.java
+0
-1
test/plugin/scenarios/pulsar-scenario/config/expectedData.yaml
...plugin/scenarios/pulsar-scenario/config/expectedData.yaml
+102
-2
test/plugin/scenarios/pulsar-scenario/configuration.yml
test/plugin/scenarios/pulsar-scenario/configuration.yml
+3
-2
test/plugin/scenarios/pulsar-scenario/src/main/java/test/apache/skywalking/apm/testcase/pulsar/controller/CaseController.java
...alking/apm/testcase/pulsar/controller/CaseController.java
+37
-6
test/plugin/scenarios/pulsar-scenario/src/main/resources/application.properties
...pulsar-scenario/src/main/resources/application.properties
+1
-1
未找到文件。
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/main/java/org/apache/skywalking/apm/plugin/pulsar/ConsumerConstructorInterceptor.java
浏览文件 @
5f26710d
...
@@ -45,7 +45,6 @@ public class ConsumerConstructorInterceptor implements InstanceConstructorInterc
...
@@ -45,7 +45,6 @@ public class ConsumerConstructorInterceptor implements InstanceConstructorInterc
requireInfo
.
setServiceUrl
(
pulsarClient
.
getLookup
().
getServiceUrl
());
requireInfo
.
setServiceUrl
(
pulsarClient
.
getLookup
().
getServiceUrl
());
requireInfo
.
setTopic
(
topic
);
requireInfo
.
setTopic
(
topic
);
requireInfo
.
setSubscriptionName
(
consumerConfigurationData
.
getSubscriptionName
());
requireInfo
.
setSubscriptionName
(
consumerConfigurationData
.
getSubscriptionName
());
requireInfo
.
setHasMessageListener
(
consumerConfigurationData
.
getMessageListener
()
!=
null
);
objInst
.
setSkyWalkingDynamicField
(
requireInfo
);
objInst
.
setSkyWalkingDynamicField
(
requireInfo
);
}
}
}
}
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/main/java/org/apache/skywalking/apm/plugin/pulsar/ConsumerEnhanceRequiredInfo.java
浏览文件 @
5f26710d
...
@@ -38,19 +38,6 @@ public class ConsumerEnhanceRequiredInfo {
...
@@ -38,19 +38,6 @@ public class ConsumerEnhanceRequiredInfo {
*/
*/
private
String
subscriptionName
;
private
String
subscriptionName
;
/**
* whether the consumer has a message listener
*/
private
boolean
hasMessageListener
;
public
boolean
isHasMessageListener
()
{
return
hasMessageListener
;
}
public
void
setHasMessageListener
(
boolean
hasMessageListener
)
{
this
.
hasMessageListener
=
hasMessageListener
;
}
public
String
getServiceUrl
()
{
public
String
getServiceUrl
()
{
return
serviceUrl
;
return
serviceUrl
;
}
}
...
...
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/main/java/org/apache/skywalking/apm/plugin/pulsar/PulsarConsumerInterceptor.java
浏览文件 @
5f26710d
...
@@ -77,17 +77,15 @@ public class PulsarConsumerInterceptor implements InstanceMethodsAroundIntercept
...
@@ -77,17 +77,15 @@ public class PulsarConsumerInterceptor implements InstanceMethodsAroundIntercept
if
(
allArguments
[
0
]
!=
null
)
{
if
(
allArguments
[
0
]
!=
null
)
{
final
ConsumerEnhanceRequiredInfo
requiredInfo
=
(
ConsumerEnhanceRequiredInfo
)
objInst
final
ConsumerEnhanceRequiredInfo
requiredInfo
=
(
ConsumerEnhanceRequiredInfo
)
objInst
.
getSkyWalkingDynamicField
();
.
getSkyWalkingDynamicField
();
if
(
requiredInfo
.
isHasMessageListener
())
{
EnhancedInstance
msg
=
(
EnhancedInstance
)
allArguments
[
0
];
EnhancedInstance
msg
=
(
EnhancedInstance
)
allArguments
[
0
];
MessageEnhanceRequiredInfo
messageEnhanceRequiredInfo
=
(
MessageEnhanceRequiredInfo
)
msg
MessageEnhanceRequiredInfo
messageEnhanceRequiredInfo
=
(
MessageEnhanceRequiredInfo
)
msg
.
getSkyWalkingDynamicField
();
.
getSkyWalkingDynamicField
();
if
(
messageEnhanceRequiredInfo
==
null
)
{
if
(
messageEnhanceRequiredInfo
==
null
)
{
messageEnhanceRequiredInfo
=
new
MessageEnhanceRequiredInfo
();
messageEnhanceRequiredInfo
=
new
MessageEnhanceRequiredInfo
();
msg
.
setSkyWalkingDynamicField
(
messageEnhanceRequiredInfo
);
msg
.
setSkyWalkingDynamicField
(
messageEnhanceRequiredInfo
);
}
messageEnhanceRequiredInfo
.
setTopic
(
requiredInfo
.
getTopic
());
messageEnhanceRequiredInfo
.
setContextSnapshot
(
ContextManager
.
capture
());
}
}
messageEnhanceRequiredInfo
.
setTopic
(
requiredInfo
.
getTopic
());
messageEnhanceRequiredInfo
.
setContextSnapshot
(
ContextManager
.
capture
());
ContextManager
.
stopSpan
();
ContextManager
.
stopSpan
();
}
}
return
ret
;
return
ret
;
...
...
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/main/java/org/apache/skywalking/apm/plugin/pulsar/PulsarConsumerListenerInterceptor.java
浏览文件 @
5f26710d
...
@@ -58,7 +58,7 @@ public class PulsarConsumerListenerInterceptor implements InstanceMethodsAroundI
...
@@ -58,7 +58,7 @@ public class PulsarConsumerListenerInterceptor implements InstanceMethodsAroundI
return
ret
==
null
?
null
:
(
MessageListener
)
(
consumer
,
message
)
->
{
return
ret
==
null
?
null
:
(
MessageListener
)
(
consumer
,
message
)
->
{
final
MessageEnhanceRequiredInfo
requiredInfo
=
(
MessageEnhanceRequiredInfo
)
((
EnhancedInstance
)
message
)
final
MessageEnhanceRequiredInfo
requiredInfo
=
(
MessageEnhanceRequiredInfo
)
((
EnhancedInstance
)
message
)
.
getSkyWalkingDynamicField
();
.
getSkyWalkingDynamicField
();
if
(
requiredInfo
==
null
)
{
if
(
requiredInfo
==
null
||
requiredInfo
.
getContextSnapshot
()
==
null
)
{
((
MessageListener
)
ret
).
received
(
consumer
,
message
);
((
MessageListener
)
ret
).
received
(
consumer
,
message
);
}
else
{
}
else
{
AbstractSpan
activeSpan
=
ContextManager
AbstractSpan
activeSpan
=
ContextManager
...
...
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/main/java/org/apache/skywalking/apm/plugin/pulsar/TopicMessageConstructorInterceptor.java
0 → 100644
浏览文件 @
5f26710d
/*
* 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.pulsar
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor
;
/**
* Interceptor of pulsar topic message constructor.
* <p>
* The interceptor create {@link MessageEnhanceRequiredInfo} which is required by passing message span across
* threads. Another purpose of this interceptor is to make {@link ClassEnhancePluginDefine} enable enhanced class
* to implement {@link EnhancedInstance} interface. Because if {@link ClassEnhancePluginDefine} class will not create
* SkyWalkingDynamicField without any constructor or method interceptor.
*/
public
class
TopicMessageConstructorInterceptor
implements
InstanceConstructorInterceptor
{
@Override
public
void
onConstruct
(
EnhancedInstance
objInst
,
Object
[]
allArguments
)
{
final
Object
msgArgument
=
allArguments
[
2
];
if
(
msgArgument
instanceof
EnhancedInstance
)
{
objInst
.
setSkyWalkingDynamicField
(((
EnhancedInstance
)
msgArgument
).
getSkyWalkingDynamicField
());
}
else
{
objInst
.
setSkyWalkingDynamicField
(
new
MessageEnhanceRequiredInfo
());
}
}
}
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/main/java/org/apache/skywalking/apm/plugin/pulsar/define/MessageInstrumentation.java
浏览文件 @
5f26710d
...
@@ -26,7 +26,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsIn
...
@@ -26,7 +26,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsIn
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine
;
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.ClassMatch
;
import
static
org
.
apache
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
match
.
HierarchyMatch
.
byHierarchyMatch
;
import
static
org
.
apache
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
match
.
NameMatch
.
byName
;
/**
/**
* Pulsar message instrumentation.
* Pulsar message instrumentation.
...
@@ -39,7 +39,7 @@ import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.b
...
@@ -39,7 +39,7 @@ import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.b
*/
*/
public
class
MessageInstrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
public
class
MessageInstrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
public
static
final
String
ENHANCE_CLASS
=
"org.apache.pulsar.client.
api.Message
"
;
public
static
final
String
ENHANCE_CLASS
=
"org.apache.pulsar.client.
impl.MessageImpl
"
;
public
static
final
String
CONSTRUCTOR_INTERCEPTOR_CLASS
=
"org.apache.skywalking.apm.plugin.pulsar.MessageConstructorInterceptor"
;
public
static
final
String
CONSTRUCTOR_INTERCEPTOR_CLASS
=
"org.apache.skywalking.apm.plugin.pulsar.MessageConstructorInterceptor"
;
@Override
@Override
...
@@ -66,6 +66,6 @@ public class MessageInstrumentation extends ClassInstanceMethodsEnhancePluginDef
...
@@ -66,6 +66,6 @@ public class MessageInstrumentation extends ClassInstanceMethodsEnhancePluginDef
@Override
@Override
protected
ClassMatch
enhanceClass
()
{
protected
ClassMatch
enhanceClass
()
{
return
by
HierarchyMatch
(
ENHANCE_CLASS
);
return
by
Name
(
ENHANCE_CLASS
);
}
}
}
}
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/main/java/org/apache/skywalking/apm/plugin/pulsar/define/TopicMessageInstrumentation.java
0 → 100644
浏览文件 @
5f26710d
/*
* 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.pulsar.define
;
import
net.bytebuddy.description.method.MethodDescription
;
import
net.bytebuddy.matcher.BooleanMatcher
;
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
static
org
.
apache
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
match
.
NameMatch
.
byName
;
/**
* Pulsar topic message instrumentation.
* <p>
* The topic message enhanced object is only for passing message reception span across threads.
* <p>
* Enhanced message object will be injected {@link org.apache.skywalking.apm.plugin.pulsar.MessageEnhanceRequiredInfo}
* after message process method if consumer has a message listener.
* </p>
*/
public
class
TopicMessageInstrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
public
static
final
String
ENHANCE_CLASS
=
"org.apache.pulsar.client.impl.TopicMessageImpl"
;
public
static
final
String
CONSTRUCTOR_INTERCEPTOR_CLASS
=
"org.apache.skywalking.apm.plugin.pulsar.TopicMessageConstructorInterceptor"
;
@Override
public
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
new
ConstructorInterceptPoint
[]{
new
ConstructorInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getConstructorMatcher
()
{
return
new
BooleanMatcher
<>(
true
);
}
@Override
public
String
getConstructorInterceptor
()
{
return
CONSTRUCTOR_INTERCEPTOR_CLASS
;
}
}
};
}
@Override
public
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[
0
];
}
@Override
protected
ClassMatch
enhanceClass
()
{
return
byName
(
ENHANCE_CLASS
);
}
}
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/main/resources/skywalking-plugin.def
浏览文件 @
5f26710d
...
@@ -18,4 +18,5 @@ pulsar=org.apache.skywalking.apm.plugin.pulsar.define.SendCallbackInstrumentatio
...
@@ -18,4 +18,5 @@ pulsar=org.apache.skywalking.apm.plugin.pulsar.define.SendCallbackInstrumentatio
pulsar=org.apache.skywalking.apm.plugin.pulsar.define.PulsarConsumerInstrumentation
pulsar=org.apache.skywalking.apm.plugin.pulsar.define.PulsarConsumerInstrumentation
pulsar=org.apache.skywalking.apm.plugin.pulsar.define.PulsarConsumerListenerInstrumentation
pulsar=org.apache.skywalking.apm.plugin.pulsar.define.PulsarConsumerListenerInstrumentation
pulsar=org.apache.skywalking.apm.plugin.pulsar.define.PulsarProducerInstrumentation
pulsar=org.apache.skywalking.apm.plugin.pulsar.define.PulsarProducerInstrumentation
pulsar=org.apache.skywalking.apm.plugin.pulsar.define.MessageInstrumentation
pulsar=org.apache.skywalking.apm.plugin.pulsar.define.MessageInstrumentation
\ No newline at end of file
pulsar=org.apache.skywalking.apm.plugin.pulsar.define.TopicMessageInstrumentation
\ No newline at end of file
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/test/java/org/apache/skywalking/apm/plugin/pulsar/ConsumerConstructorInterceptorTest.java
浏览文件 @
5f26710d
...
@@ -18,7 +18,6 @@
...
@@ -18,7 +18,6 @@
package
org.apache.skywalking.apm.plugin.pulsar
;
package
org.apache.skywalking.apm.plugin.pulsar
;
import
org.apache.pulsar.client.api.PulsarClientException
;
import
org.apache.pulsar.client.impl.LookupService
;
import
org.apache.pulsar.client.impl.LookupService
;
import
org.apache.pulsar.client.impl.PulsarClientImpl
;
import
org.apache.pulsar.client.impl.PulsarClientImpl
;
import
org.apache.pulsar.client.impl.conf.ConsumerConfigurationData
;
import
org.apache.pulsar.client.impl.conf.ConsumerConfigurationData
;
...
@@ -71,13 +70,6 @@ public class ConsumerConstructorInterceptorTest {
...
@@ -71,13 +70,6 @@ public class ConsumerConstructorInterceptorTest {
when
(
lookupService
.
getServiceUrl
()).
thenReturn
(
SERVICE_URL
);
when
(
lookupService
.
getServiceUrl
()).
thenReturn
(
SERVICE_URL
);
when
(
pulsarClient
.
getLookup
()).
thenReturn
(
lookupService
);
when
(
pulsarClient
.
getLookup
()).
thenReturn
(
lookupService
);
when
(
consumerConfigurationData
.
getSubscriptionName
()).
thenReturn
(
SUBSCRIPTION_NAME
);
when
(
consumerConfigurationData
.
getSubscriptionName
()).
thenReturn
(
SUBSCRIPTION_NAME
);
when
(
consumerConfigurationData
.
getMessageListener
()).
thenReturn
((
consumer
,
message
)
->
{
try
{
consumer
.
acknowledge
(
message
);
}
catch
(
PulsarClientException
e
)
{
e
.
printStackTrace
();
}
});
constructorInterceptor
=
new
ConsumerConstructorInterceptor
();
constructorInterceptor
=
new
ConsumerConstructorInterceptor
();
}
}
...
@@ -92,6 +84,5 @@ public class ConsumerConstructorInterceptorTest {
...
@@ -92,6 +84,5 @@ public class ConsumerConstructorInterceptorTest {
assertThat
(
requiredInfo
.
getServiceUrl
(),
is
(
SERVICE_URL
));
assertThat
(
requiredInfo
.
getServiceUrl
(),
is
(
SERVICE_URL
));
assertThat
(
requiredInfo
.
getTopic
(),
is
(
TOPIC_NAME
));
assertThat
(
requiredInfo
.
getTopic
(),
is
(
TOPIC_NAME
));
assertThat
(
requiredInfo
.
getSubscriptionName
(),
is
(
SUBSCRIPTION_NAME
));
assertThat
(
requiredInfo
.
getSubscriptionName
(),
is
(
SUBSCRIPTION_NAME
));
assertThat
(
requiredInfo
.
isHasMessageListener
(),
is
(
true
));
}
}
}
}
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/test/java/org/apache/skywalking/apm/plugin/pulsar/PulsarConsumerInterceptorTest.java
浏览文件 @
5f26710d
...
@@ -122,7 +122,6 @@ public class PulsarConsumerInterceptorTest {
...
@@ -122,7 +122,6 @@ public class PulsarConsumerInterceptorTest {
@Test
@Test
public
void
testConsumerWithMessageListener
()
throws
Throwable
{
public
void
testConsumerWithMessageListener
()
throws
Throwable
{
consumerEnhanceRequiredInfo
.
setHasMessageListener
(
true
);
consumerInterceptor
.
beforeMethod
(
consumerInstance
,
null
,
new
Object
[]{
msg
},
new
Class
[
0
],
null
);
consumerInterceptor
.
beforeMethod
(
consumerInstance
,
null
,
new
Object
[]{
msg
},
new
Class
[
0
],
null
);
consumerInterceptor
.
afterMethod
(
consumerInstance
,
null
,
new
Object
[]{
msg
},
new
Class
[
0
],
null
);
consumerInterceptor
.
afterMethod
(
consumerInstance
,
null
,
new
Object
[]{
msg
},
new
Class
[
0
],
null
);
...
...
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/test/java/org/apache/skywalking/apm/plugin/pulsar/PulsarConsumerListenerInterceptorTest.java
浏览文件 @
5f26710d
...
@@ -96,7 +96,6 @@ public class PulsarConsumerListenerInterceptorTest {
...
@@ -96,7 +96,6 @@ public class PulsarConsumerListenerInterceptorTest {
consumerEnhanceRequiredInfo
.
setTopic
(
"persistent://my-tenant/my-ns/my-topic"
);
consumerEnhanceRequiredInfo
.
setTopic
(
"persistent://my-tenant/my-ns/my-topic"
);
consumerEnhanceRequiredInfo
.
setServiceUrl
(
"pulsar://localhost:6650"
);
consumerEnhanceRequiredInfo
.
setServiceUrl
(
"pulsar://localhost:6650"
);
consumerEnhanceRequiredInfo
.
setSubscriptionName
(
"my-sub"
);
consumerEnhanceRequiredInfo
.
setSubscriptionName
(
"my-sub"
);
consumerEnhanceRequiredInfo
.
setHasMessageListener
(
true
);
msg
=
new
MockMessage
();
msg
=
new
MockMessage
();
msg
.
getMessageBuilder
()
msg
.
getMessageBuilder
()
.
addProperties
(
PulsarApi
.
KeyValue
.
newBuilder
()
.
addProperties
(
PulsarApi
.
KeyValue
.
newBuilder
()
...
...
test/plugin/scenarios/pulsar-scenario/config/expectedData.yaml
浏览文件 @
5f26710d
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
# limitations under the License.
# limitations under the License.
segmentItems
:
segmentItems
:
-
serviceName
:
pulsar-scenario
-
serviceName
:
pulsar-scenario
segmentSize
:
ge
6
segmentSize
:
ge
9
segments
:
segments
:
-
segmentId
:
not
null
-
segmentId
:
not
null
spans
:
spans
:
...
@@ -34,6 +34,21 @@ segmentItems:
...
@@ -34,6 +34,21 @@ segmentItems:
-
{
key
:
mq.broker
,
value
:
not null
}
-
{
key
:
mq.broker
,
value
:
not null
}
-
{
key
:
mq.topic
,
value
:
test
}
-
{
key
:
mq.topic
,
value
:
test
}
skipAnalysis
:
'
false'
skipAnalysis
:
'
false'
-
operationName
:
Pulsar/testMultiPartition/Producer
operationId
:
0
parentSpanId
:
0
spanId
:
2
spanLayer
:
MQ
startTime
:
nq
0
endTime
:
nq
0
componentId
:
73
isError
:
false
spanType
:
Exit
peer
:
not
null
skipAnalysis
:
false
tags
:
-
{
key
:
mq.broker
,
value
:
not null
}
-
{
key
:
mq.topic
,
value
:
testMultiPartition
}
-
operationName
:
/case/pulsar-case
-
operationName
:
/case/pulsar-case
operationId
:
0
operationId
:
0
parentSpanId
:
-1
parentSpanId
:
-1
...
@@ -46,7 +61,7 @@ segmentItems:
...
@@ -46,7 +61,7 @@ segmentItems:
spanType
:
Entry
spanType
:
Entry
peer
:
'
'
peer
:
'
'
tags
:
tags
:
-
{
key
:
url
,
value
:
'
http://localhost:808
0
/pulsar-scenario/case/pulsar-case'
}
-
{
key
:
url
,
value
:
'
http://localhost:808
8
/pulsar-scenario/case/pulsar-case'
}
-
{
key
:
http.method
,
value
:
GET
}
-
{
key
:
http.method
,
value
:
GET
}
skipAnalysis
:
'
false'
skipAnalysis
:
'
false'
-
segmentId
:
not
null
-
segmentId
:
not
null
...
@@ -134,3 +149,88 @@ segmentItems:
...
@@ -134,3 +149,88 @@ segmentItems:
parentSpanId
:
0
,
parentTraceSegmentId
:
not null
,
parentServiceInstance
:
not null
,
parentSpanId
:
0
,
parentTraceSegmentId
:
not null
,
parentServiceInstance
:
not null
,
parentService
:
pulsar-scenario
,
traceId
:
not null
}
parentService
:
pulsar-scenario
,
traceId
:
not null
}
skipAnalysis
:
'
false'
skipAnalysis
:
'
false'
-
segmentId
:
not
null
spans
:
-
operationName
:
Pulsar/Producer/Callback
operationId
:
0
parentSpanId
:
-1
spanId
:
0
spanLayer
:
MQ
startTime
:
nq
0
endTime
:
nq
0
componentId
:
73
isError
:
false
spanType
:
Local
peer
:
'
'
tags
:
-
{
key
:
mq.topic
,
value
:
testMultiPartition
}
refs
:
-
{
parentEndpoint
:
/case/pulsar-case
,
networkAddress
:
'
'
,
refType
:
CrossThread
,
parentSpanId
:
2
,
parentTraceSegmentId
:
not null
,
parentServiceInstance
:
not
null
,
parentService
:
pulsar-scenario
,
traceId
:
not null
}
skipAnalysis
:
'
false'
-
segmentId
:
not
null
spans
:
-
operationName
:
Pulsar/testMultiPartition/Consumer/test
operationId
:
0
parentSpanId
:
-1
spanId
:
0
spanLayer
:
MQ
startTime
:
nq
0
endTime
:
nq
0
componentId
:
74
isError
:
false
spanType
:
Entry
peer
:
'
'
tags
:
-
{
key
:
transmission.latency
,
value
:
not null
}
-
{
key
:
mq.broker
,
value
:
not null
}
-
{
key
:
mq.topic
,
value
:
testMultiPartition
}
refs
:
-
{
parentEndpoint
:
/case/pulsar-case
,
networkAddress
:
not null
,
refType
:
CrossProcess
,
parentSpanId
:
2
,
parentTraceSegmentId
:
not null
,
parentServiceInstance
:
not
null
,
parentService
:
pulsar-scenario
,
traceId
:
not null
}
skipAnalysis
:
'
false'
-
segmentId
:
not
null
spans
:
-
operationName
:
Pulsar/testMultiPartition/Consumer/testWithListener
operationId
:
0
parentSpanId
:
-1
spanId
:
0
spanLayer
:
MQ
startTime
:
nq
0
endTime
:
nq
0
componentId
:
74
isError
:
false
spanType
:
Entry
peer
:
'
'
skipAnalysis
:
'
false'
tags
:
-
{
key
:
transmission.latency
,
value
:
not null
}
-
{
key
:
mq.broker
,
value
:
not null
}
-
{
key
:
mq.topic
,
value
:
testMultiPartition
}
refs
:
-
{
parentEndpoint
:
/case/pulsar-case
,
networkAddress
:
not null
,
refType
:
CrossProcess
,
parentSpanId
:
2
,
parentTraceSegmentId
:
not null
,
parentServiceInstance
:
not null
,
parentService
:
pulsar-scenario
,
traceId
:
not null
}
-
segmentId
:
not
null
spans
:
-
operationName
:
Pulsar/testMultiPartition/Consumer/MessageListener
operationId
:
0
parentSpanId
:
-1
spanId
:
0
spanLayer
:
MQ
startTime
:
nq
0
endTime
:
nq
0
componentId
:
74
isError
:
false
spanType
:
Local
peer
:
'
'
tags
:
-
{
key
:
mq.topic
,
value
:
testMultiPartition
}
refs
:
-
{
parentEndpoint
:
Pulsar/testMultiPartition/Consumer/testWithListener
,
networkAddress
:
'
'
,
refType
:
CrossThread
,
parentSpanId
:
0
,
parentTraceSegmentId
:
not null
,
parentServiceInstance
:
not null
,
parentService
:
pulsar-scenario
,
traceId
:
not null
}
skipAnalysis
:
'
false'
test/plugin/scenarios/pulsar-scenario/configuration.yml
浏览文件 @
5f26710d
...
@@ -15,8 +15,8 @@
...
@@ -15,8 +15,8 @@
# limitations under the License.
# limitations under the License.
type
:
jvm
type
:
jvm
entryService
:
http://localhost:808
0
/pulsar-scenario/case/pulsar-case
entryService
:
http://localhost:808
8
/pulsar-scenario/case/pulsar-case
healthCheck
:
http://localhost:808
0
/pulsar-scenario/case/healthCheck
healthCheck
:
http://localhost:808
8
/pulsar-scenario/case/healthCheck
startScript
:
./bin/startup.sh
startScript
:
./bin/startup.sh
environment
:
environment
:
-
PULSAR_STANDALONE=pulsar-standalone:6650
-
PULSAR_STANDALONE=pulsar-standalone:6650
...
@@ -29,3 +29,4 @@ dependencies:
...
@@ -29,3 +29,4 @@ dependencies:
startScript
:
[
"
bin/pulsar"
,
"
standalone"
]
startScript
:
[
"
bin/pulsar"
,
"
standalone"
]
expose
:
expose
:
-
6650
-
6650
-
8080
test/plugin/scenarios/pulsar-scenario/src/main/java/test/apache/skywalking/apm/testcase/pulsar/controller/CaseController.java
浏览文件 @
5f26710d
...
@@ -31,6 +31,11 @@ import org.springframework.stereotype.Controller;
...
@@ -31,6 +31,11 @@ import org.springframework.stereotype.Controller;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.nio.charset.StandardCharsets
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
...
@@ -48,10 +53,24 @@ public class CaseController {
...
@@ -48,10 +53,24 @@ public class CaseController {
@RequestMapping
(
"/pulsar-case"
)
@RequestMapping
(
"/pulsar-case"
)
@ResponseBody
@ResponseBody
public
String
pulsarCase
()
throws
PulsarClientException
,
InterruptedException
{
public
String
pulsarCase
()
{
String
topic
=
"test"
;
String
topicOnePartition
=
"test"
;
String
topicMultiPartition
=
"testMultiPartition"
;
try
{
doSendAndReceiveMessage
(
topicOnePartition
);
createTopic
(
topicMultiPartition
,
2
);
doSendAndReceiveMessage
(
topicMultiPartition
);
}
catch
(
IOException
e
)
{
LOGGER
.
error
(
"test error"
,
e
);
}
return
"Success"
;
}
private
void
doSendAndReceiveMessage
(
String
topic
)
throws
PulsarClientException
{
CountDownLatch
latch
=
new
CountDownLatch
(
2
);
CountDownLatch
latch
=
new
CountDownLatch
(
2
);
PulsarClient
pulsarClient
=
PulsarClient
.
builder
().
serviceUrl
(
PULSAR_DOMAIN
+
serviceUrl
).
build
();
PulsarClient
pulsarClient
=
PulsarClient
.
builder
().
serviceUrl
(
PULSAR_DOMAIN
+
serviceUrl
).
build
();
...
@@ -60,7 +79,7 @@ public class CaseController {
...
@@ -60,7 +79,7 @@ public class CaseController {
Consumer
<
byte
[]>
consumer
=
pulsarClient
.
newConsumer
().
topic
(
topic
).
subscriptionName
(
"test"
).
subscribe
();
Consumer
<
byte
[]>
consumer
=
pulsarClient
.
newConsumer
().
topic
(
topic
).
subscriptionName
(
"test"
).
subscribe
();
pulsarClient
.
newConsumer
().
topic
(
topic
)
final
Consumer
<
byte
[]>
consumerWithListener
=
pulsarClient
.
newConsumer
().
topic
(
topic
)
.
subscriptionName
(
"testWithListener"
)
.
subscriptionName
(
"testWithListener"
)
.
messageListener
((
c
,
msg
)
->
{
.
messageListener
((
c
,
msg
)
->
{
try
{
try
{
...
@@ -70,7 +89,8 @@ public class CaseController {
...
@@ -70,7 +89,8 @@ public class CaseController {
msg
.
getProperties
()
msg
.
getProperties
()
.
forEach
((
k
,
v
)
->
builder
.
append
(
String
.
format
(
propertiesFormat
,
k
,
v
))
.
forEach
((
k
,
v
)
->
builder
.
append
(
String
.
format
(
propertiesFormat
,
k
,
v
))
.
append
(
", "
));
.
append
(
", "
));
LOGGER
.
info
(
"Received message with messageId = {}, key = {}, value = {}, properties = {}"
,
LOGGER
.
info
(
"Received message with messageId = {}, key = {}, value = {}, properties = {}"
,
msg
.
getMessageId
(),
msg
msg
.
getMessageId
(),
msg
.
getKey
(),
new
String
(
msg
.
getValue
()),
builder
.
toString
());
.
getKey
(),
new
String
(
msg
.
getValue
()),
builder
.
toString
());
...
@@ -113,13 +133,24 @@ public class CaseController {
...
@@ -113,13 +133,24 @@ public class CaseController {
}
catch
(
InterruptedException
e
)
{
}
catch
(
InterruptedException
e
)
{
LOGGER
.
error
(
"Can get message from consumer"
,
e
);
LOGGER
.
error
(
"Can get message from consumer"
,
e
);
t
.
interrupt
();
t
.
interrupt
();
throw
e
;
}
}
producer
.
close
();
producer
.
close
();
consumer
.
close
();
consumer
.
close
();
consumerWithListener
.
close
();
}
return
"Success"
;
private
void
createTopic
(
String
topic
,
int
numOfPartitions
)
throws
IOException
{
final
URL
url
=
new
URL
(
"http://pulsar-standalone:8080/admin/v2/persistent/public/default/"
+
topic
+
"/partitions"
);
final
HttpURLConnection
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
connection
.
setRequestMethod
(
"PUT"
);
connection
.
setDoOutput
(
true
);
final
OutputStream
outputStream
=
connection
.
getOutputStream
();
outputStream
.
write
(
String
.
valueOf
(
numOfPartitions
).
getBytes
(
StandardCharsets
.
UTF_8
));
outputStream
.
flush
();
LOGGER
.
info
(
"Create topic result:{}"
,
connection
.
getResponseCode
());
}
}
@RequestMapping
(
"/healthCheck"
)
@RequestMapping
(
"/healthCheck"
)
...
...
test/plugin/scenarios/pulsar-scenario/src/main/resources/application.properties
浏览文件 @
5f26710d
...
@@ -15,5 +15,5 @@
...
@@ -15,5 +15,5 @@
# limitations under the License.
# limitations under the License.
#
#
#
#
server.port
=
808
0
server.port
=
808
8
server.contextPath
=
/pulsar-scenario
server.contextPath
=
/pulsar-scenario
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录