Skip to content

Commit f91dd5d

Browse files
Merge branch '3.2' into 3.2-copy-tag
2 parents 51262cc + ea35f7e commit f91dd5d

File tree

94 files changed

+442
-1497
lines changed

Some content is hidden

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

94 files changed

+442
-1497
lines changed

.artifacts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,4 @@ dubbo-nacos-spring-boot-starter
115115
dubbo-zookeeper-spring-boot-starter
116116
dubbo-zookeeper-curator5-spring-boot-starter
117117
dubbo-spring-security
118-
dubbo-tracing
119118
dubbo-xds

dubbo-cluster/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,10 @@
8686
<version>${project.parent.version}</version>
8787
<optional>true</optional>
8888
</dependency>
89+
<dependency>
90+
<groupId>io.micrometer</groupId>
91+
<artifactId>micrometer-tracing-integration-test</artifactId>
92+
<scope>test</scope>
93+
</dependency>
8994
</dependencies>
9095
</project>

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,15 +476,21 @@ protected void destroyInvokers() {
476476
}
477477

478478
private boolean addValidInvoker(Invoker<T> invoker) {
479+
boolean result;
479480
synchronized (this.validInvokers) {
480-
return this.validInvokers.add(invoker);
481+
result = this.validInvokers.add(invoker);
481482
}
483+
MetricsEventBus.publish(RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary()));
484+
return result;
482485
}
483486

484487
private boolean removeValidInvoker(Invoker<T> invoker) {
488+
boolean result;
485489
synchronized (this.validInvokers) {
486-
return this.validInvokers.remove(invoker);
490+
result = this.validInvokers.remove(invoker);
487491
}
492+
MetricsEventBus.publish(RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary()));
493+
return result;
488494
}
489495

490496
protected abstract List<Invoker<T>> doList(SingleRouterChain<T> singleRouterChain,

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
*/
3737
public class StaticDirectory<T> extends AbstractDirectory<T> {
3838
private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(StaticDirectory.class);
39+
private final Class<T> interfaceClass;
3940

4041
public StaticDirectory(List<Invoker<T>> invokers) {
4142
this(null, invokers, null);
@@ -55,11 +56,12 @@ public StaticDirectory(URL url, List<Invoker<T>> invokers, RouterChain<T> router
5556
throw new IllegalArgumentException("invokers == null");
5657
}
5758
this.setInvokers(new BitList<>(invokers));
59+
this.interfaceClass = invokers.get(0).getInterface();
5860
}
5961

6062
@Override
6163
public Class<T> getInterface() {
62-
return getInvokers().get(0).getInterface();
64+
return interfaceClass;
6365
}
6466

6567
@Override
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.apache.dubbo.tracing.filter;
17+
package org.apache.dubbo.rpc.cluster.filter.support;
1818

1919
import org.apache.dubbo.common.extension.Activate;
20+
import org.apache.dubbo.metrics.observation.DefaultDubboClientObservationConvention;
21+
import org.apache.dubbo.metrics.observation.DubboClientContext;
22+
import org.apache.dubbo.metrics.observation.DubboClientObservationConvention;
23+
import org.apache.dubbo.metrics.observation.DubboObservationDocumentation;
2024
import org.apache.dubbo.rpc.BaseFilter;
2125
import org.apache.dubbo.rpc.Filter;
2226
import org.apache.dubbo.rpc.Invocation;
@@ -26,10 +30,6 @@
2630
import org.apache.dubbo.rpc.cluster.filter.ClusterFilter;
2731
import org.apache.dubbo.rpc.model.ApplicationModel;
2832
import org.apache.dubbo.rpc.model.ScopeModelAware;
29-
import org.apache.dubbo.tracing.DefaultDubboClientObservationConvention;
30-
import org.apache.dubbo.tracing.DubboClientObservationConvention;
31-
import org.apache.dubbo.tracing.DubboObservationDocumentation;
32-
import org.apache.dubbo.tracing.context.DubboClientContext;
3333

3434
import io.micrometer.observation.Observation;
3535
import io.micrometer.observation.ObservationRegistry;
@@ -39,16 +39,20 @@
3939
/**
4040
* A {@link Filter} that creates an {@link Observation} around the outgoing message.
4141
*/
42-
@Activate(group = CONSUMER, order = Integer.MIN_VALUE + 50, onClass = "io.micrometer.observation.NoopObservationRegistry")
42+
@Activate(group = CONSUMER, order = -1, onClass = "io.micrometer.observation.NoopObservationRegistry")
4343
public class ObservationSenderFilter implements ClusterFilter, BaseFilter.Listener, ScopeModelAware {
4444

4545
private ObservationRegistry observationRegistry;
4646

4747
private DubboClientObservationConvention clientObservationConvention;
4848

4949
public ObservationSenderFilter(ApplicationModel applicationModel) {
50-
observationRegistry = applicationModel.getBeanFactory().getBean(ObservationRegistry.class);
51-
clientObservationConvention = applicationModel.getBeanFactory().getBean(DubboClientObservationConvention.class);
50+
applicationModel.getApplicationConfigManager().getTracing().ifPresent(cfg -> {
51+
if (Boolean.TRUE.equals(cfg.getEnabled())) {
52+
observationRegistry = applicationModel.getBeanFactory().getBean(ObservationRegistry.class);
53+
clientObservationConvention = applicationModel.getBeanFactory().getBean(DubboClientObservationConvention.class);
54+
}
55+
});
5256
}
5357

5458
@Override
@@ -71,9 +75,6 @@ public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invoca
7175
if (observation == null) {
7276
return;
7377
}
74-
if (appResponse != null && appResponse.hasException()) {
75-
observation.error(appResponse.getException());
76-
}
7778
observation.stop();
7879
}
7980

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
consumercontext=org.apache.dubbo.rpc.cluster.filter.support.ConsumerContextFilter
22
consumer-classloader=org.apache.dubbo.rpc.cluster.filter.support.ConsumerClassLoaderFilter
33
router-snapshot=org.apache.dubbo.rpc.cluster.router.RouterSnapshotFilter
4+
observationsender=org.apache.dubbo.rpc.cluster.filter.support.ObservationSenderFilter
45
metricsClusterFilter=org.apache.dubbo.rpc.cluster.filter.support.MetricsClusterFilter
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
package org.apache.dubbo.rpc.cluster.filter;
18+
19+
import org.apache.dubbo.config.ApplicationConfig;
20+
import org.apache.dubbo.config.TracingConfig;
21+
import org.apache.dubbo.rpc.AppResponse;
22+
import org.apache.dubbo.rpc.BaseFilter;
23+
import org.apache.dubbo.rpc.Invoker;
24+
import org.apache.dubbo.rpc.RpcInvocation;
25+
import org.apache.dubbo.rpc.model.ApplicationModel;
26+
27+
import io.micrometer.tracing.test.SampleTestRunner;
28+
import org.junit.jupiter.api.AfterEach;
29+
30+
import static org.mockito.BDDMockito.given;
31+
import static org.mockito.Mockito.mock;
32+
33+
abstract class AbstractObservationFilterTest extends SampleTestRunner {
34+
35+
ApplicationModel applicationModel;
36+
RpcInvocation invocation;
37+
38+
BaseFilter filter;
39+
40+
Invoker<?> invoker = mock(Invoker.class);
41+
42+
static final String INTERFACE_NAME = "org.apache.dubbo.MockInterface";
43+
static final String METHOD_NAME = "mockMethod";
44+
static final String GROUP = "mockGroup";
45+
static final String VERSION = "1.0.0";
46+
47+
@AfterEach
48+
public void teardown() {
49+
if (applicationModel != null) {
50+
applicationModel.destroy();
51+
}
52+
}
53+
54+
abstract BaseFilter createFilter(ApplicationModel applicationModel);
55+
56+
void setupConfig() {
57+
ApplicationConfig config = new ApplicationConfig();
58+
config.setName("MockObservations");
59+
60+
applicationModel = ApplicationModel.defaultModel();
61+
applicationModel.getApplicationConfigManager().setApplication(config);
62+
63+
invocation = new RpcInvocation(new MockInvocation());
64+
invocation.addInvokedInvoker(invoker);
65+
66+
applicationModel.getBeanFactory().registerBean(getObservationRegistry());
67+
TracingConfig tracingConfig = new TracingConfig();
68+
tracingConfig.setEnabled(true);
69+
applicationModel.getApplicationConfigManager().setTracing(tracingConfig);
70+
71+
filter = createFilter(applicationModel);
72+
73+
given(invoker.invoke(invocation)).willReturn(new AppResponse("success"));
74+
75+
initParam();
76+
}
77+
78+
private void initParam() {
79+
invocation.setTargetServiceUniqueName(GROUP + "/" + INTERFACE_NAME + ":" + VERSION);
80+
invocation.setMethodName(METHOD_NAME);
81+
invocation.setParameterTypes(new Class[] {String.class});
82+
}
83+
84+
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,23 @@
1515
* limitations under the License.
1616
*/
1717

18-
package org.apache.dubbo.tracing.filter;
18+
package org.apache.dubbo.rpc.cluster.filter;
1919

2020
import org.apache.dubbo.common.URL;
2121
import org.apache.dubbo.rpc.RpcContext;
22-
import org.apache.dubbo.rpc.cluster.filter.ClusterFilter;
22+
import org.apache.dubbo.rpc.cluster.filter.support.ObservationSenderFilter;
2323
import org.apache.dubbo.rpc.model.ApplicationModel;
2424

2525
import io.micrometer.common.KeyValues;
2626
import io.micrometer.core.tck.MeterRegistryAssert;
27+
import io.micrometer.tracing.test.SampleTestRunner;
2728
import io.micrometer.tracing.test.simple.SpansAssert;
2829
import org.assertj.core.api.BDDAssertions;
2930

3031
class ObservationSenderFilterTest extends AbstractObservationFilterTest {
3132

3233
@Override
33-
public SampleTestRunnerConsumer yourCode() {
34+
public SampleTestRunner.SampleTestRunnerConsumer yourCode() {
3435
return (buildingBlocks, meterRegistry) -> {
3536
setupConfig();
3637
setupAttachments();

dubbo-common/src/main/java/org/apache/dubbo/common/constants/LoggerCodeConstants.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ public interface LoggerCodeConstants {
9292

9393
String VULNERABILITY_WARNING = "0-28";
9494

95-
String COMMON_NOT_FOUND_TRACER_DEPENDENCY = "0-29";
96-
9795

9896
// Registry module
9997

dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import java.util.concurrent.ConcurrentMap;
7474
import java.util.concurrent.atomic.AtomicBoolean;
7575
import java.util.regex.Pattern;
76+
import java.util.stream.Collectors;
7677

7778
import static java.util.Arrays.asList;
7879
import static java.util.ServiceLoader.load;
@@ -346,7 +347,9 @@ public List<T> getActivateExtension(URL url, String[] values, String group) {
346347
checkDestroyed();
347348
// solve the bug of using @SPI's wrapper method to report a null pointer exception.
348349
Map<Class<?>, T> activateExtensionsMap = new TreeMap<>(activateComparator);
349-
List<String> names = values == null ? new ArrayList<>(0) : asList(values);
350+
List<String> names = values == null ?
351+
new ArrayList<>(0) :
352+
Arrays.stream(values).map(StringUtils::trim).collect(Collectors.toList());
350353
Set<String> namesSet = new HashSet<>(names);
351354
if (!namesSet.contains(REMOVE_VALUE_PREFIX + DEFAULT_KEY)) {
352355
if (cachedActivateGroups.size() == 0) {

0 commit comments

Comments
 (0)