forked from apache/dubbo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/3.2' into provider-payload
* origin/3.2: (22 commits) Remove logic to simplify ConstraintViolationException to ValidationException. (apache#11883) Bump spring-boot-dependencies from 2.7.9 to 2.7.10 (apache#11904) Bump spring-boot.version from 2.7.9 to 2.7.10 (apache#11905) Bump spring-boot-starter-test from 2.7.9 to 2.7.10 (apache#11906) Bump commons-compress from 1.22 to 1.23.0 (apache#11907) Bump spring-boot-maven-plugin from 2.7.9 to 2.7.10 (apache#11908) dubbo-starter import metrics dep (apache#11921) Add histogram (apache#11632) Add metrics for configcenter (apache#11602) Fix/dependency cycle (apache#11919) bugfix && add testcase (apache#11918) adding the reject task indicator for thread pool burying point(apache#11706) (apache#11916) Revert "optimize performance. decode in user thread (apache#11879)" (apache#11917) Reject if response do not match any request (apache#11882) triple server batch flush (apache#11723) optimize performance. decode in user thread (apache#11879) Code opt (apache#11857) Bump maven-release-plugin from 3.0.0-M7 to 3.0.0 (apache#11877) support exception process when service not found (apache#11088) Bump maven-core from 3.9.0 to 3.9.1 (apache#11869) ... # Conflicts: # dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java
- Loading branch information
Showing
95 changed files
with
2,269 additions
and
415 deletions.
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
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
79 changes: 79 additions & 0 deletions
79
...ster/src/test/java/org/apache/dubbo/rpc/cluster/filter/AbstractObservationFilterTest.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,79 @@ | ||
/* | ||
* 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.dubbo.rpc.cluster.filter; | ||
|
||
import io.micrometer.tracing.test.SampleTestRunner; | ||
import org.apache.dubbo.config.ApplicationConfig; | ||
import org.apache.dubbo.rpc.AppResponse; | ||
import org.apache.dubbo.rpc.BaseFilter; | ||
import org.apache.dubbo.rpc.Invoker; | ||
import org.apache.dubbo.rpc.RpcInvocation; | ||
import org.apache.dubbo.rpc.model.ApplicationModel; | ||
import org.junit.jupiter.api.AfterEach; | ||
|
||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.Mockito.mock; | ||
|
||
abstract class AbstractObservationFilterTest extends SampleTestRunner { | ||
|
||
ApplicationModel applicationModel; | ||
RpcInvocation invocation; | ||
|
||
BaseFilter filter; | ||
|
||
Invoker<?> invoker = mock(Invoker.class); | ||
|
||
static final String INTERFACE_NAME = "org.apache.dubbo.MockInterface"; | ||
static final String METHOD_NAME = "mockMethod"; | ||
static final String GROUP = "mockGroup"; | ||
static final String VERSION = "1.0.0"; | ||
|
||
@AfterEach | ||
public void teardown() { | ||
if (applicationModel != null) { | ||
applicationModel.destroy(); | ||
} | ||
} | ||
|
||
abstract BaseFilter createFilter(ApplicationModel applicationModel); | ||
|
||
void setupConfig() { | ||
ApplicationConfig config = new ApplicationConfig(); | ||
config.setName("MockObservations"); | ||
|
||
applicationModel = ApplicationModel.defaultModel(); | ||
applicationModel.getApplicationConfigManager().setApplication(config); | ||
|
||
invocation = new RpcInvocation(new MockInvocation()); | ||
invocation.addInvokedInvoker(invoker); | ||
|
||
applicationModel.getBeanFactory().registerBean(getObservationRegistry()); | ||
|
||
filter = createFilter(applicationModel); | ||
|
||
given(invoker.invoke(invocation)).willReturn(new AppResponse("success")); | ||
|
||
initParam(); | ||
} | ||
|
||
private void initParam() { | ||
invocation.setTargetServiceUniqueName(GROUP + "/" + INTERFACE_NAME + ":" + VERSION); | ||
invocation.setMethodName(METHOD_NAME); | ||
invocation.setParameterTypes(new Class[] {String.class}); | ||
} | ||
|
||
} |
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
183 changes: 183 additions & 0 deletions
183
...o-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/MetricsClusterFilterTest.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,183 @@ | ||
/* | ||
* 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.dubbo.rpc.cluster.filter; | ||
|
||
import org.apache.dubbo.common.URL; | ||
import org.apache.dubbo.common.constants.CommonConstants; | ||
import org.apache.dubbo.config.ApplicationConfig; | ||
import org.apache.dubbo.metrics.collector.DefaultMetricsCollector; | ||
import org.apache.dubbo.metrics.filter.MetricsFilter; | ||
import org.apache.dubbo.metrics.model.MetricsKey; | ||
import org.apache.dubbo.metrics.model.sample.GaugeMetricSample; | ||
import org.apache.dubbo.metrics.model.sample.MetricSample; | ||
import org.apache.dubbo.rpc.Invocation; | ||
import org.apache.dubbo.rpc.Invoker; | ||
import org.apache.dubbo.rpc.Result; | ||
import org.apache.dubbo.rpc.RpcContext; | ||
import org.apache.dubbo.rpc.RpcException; | ||
import org.apache.dubbo.rpc.RpcInvocation; | ||
import org.apache.dubbo.rpc.cluster.filter.support.MetricsClusterFilter; | ||
import org.apache.dubbo.rpc.model.ApplicationModel; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.Mockito.mock; | ||
|
||
class MetricsClusterFilterTest { | ||
|
||
private ApplicationModel applicationModel; | ||
private MetricsFilter filter; | ||
private MetricsClusterFilter metricsClusterFilter; | ||
private DefaultMetricsCollector collector; | ||
private RpcInvocation invocation; | ||
private final Invoker<?> invoker = mock(Invoker.class); | ||
|
||
private static final String INTERFACE_NAME = "org.apache.dubbo.MockInterface"; | ||
private static final String METHOD_NAME = "mockMethod"; | ||
private static final String GROUP = "mockGroup"; | ||
private static final String VERSION = "1.0.0"; | ||
private String side; | ||
|
||
private AtomicBoolean initApplication = new AtomicBoolean(false); | ||
|
||
|
||
@BeforeEach | ||
public void setup() { | ||
ApplicationConfig config = new ApplicationConfig(); | ||
config.setName("MockMetrics"); | ||
//RpcContext.getContext().setAttachment("MockMetrics","MockMetrics"); | ||
|
||
applicationModel = ApplicationModel.defaultModel(); | ||
applicationModel.getApplicationConfigManager().setApplication(config); | ||
|
||
invocation = new RpcInvocation(); | ||
filter = new MetricsFilter(); | ||
|
||
collector = applicationModel.getBeanFactory().getOrRegisterBean(DefaultMetricsCollector.class); | ||
if(!initApplication.get()) { | ||
collector.collectApplication(applicationModel); | ||
initApplication.set(true); | ||
} | ||
filter.setApplicationModel(applicationModel); | ||
side = CommonConstants.CONSUMER; | ||
invocation.setInvoker(new TestMetricsInvoker(side)); | ||
RpcContext.getServiceContext().setUrl(URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&side=" + side)); | ||
|
||
metricsClusterFilter = new MetricsClusterFilter(); | ||
metricsClusterFilter.setApplicationModel(applicationModel); | ||
} | ||
|
||
@AfterEach | ||
public void teardown() { | ||
applicationModel.destroy(); | ||
} | ||
|
||
@Test | ||
public void testNoProvider(){ | ||
testClusterFilterError(RpcException.FORBIDDEN_EXCEPTION, | ||
MetricsKey.METRIC_REQUESTS_SERVICE_UNAVAILABLE_FAILED.getNameByType(CommonConstants.CONSUMER)); | ||
} | ||
|
||
private void testClusterFilterError(int errorCode,String name){ | ||
collector.setCollectEnabled(true); | ||
given(invoker.invoke(invocation)).willThrow(new RpcException(errorCode)); | ||
initParam(); | ||
|
||
Long count = 1L; | ||
|
||
for (int i = 0; i < count; i++) { | ||
try { | ||
metricsClusterFilter.invoke(invoker, invocation); | ||
} catch (Exception e) { | ||
Assertions.assertTrue(e instanceof RpcException); | ||
metricsClusterFilter.onError(e, invoker, invocation); | ||
} | ||
} | ||
Map<String, MetricSample> metricsMap = getMetricsMap(); | ||
Assertions.assertTrue(metricsMap.containsKey(name)); | ||
|
||
MetricSample sample = metricsMap.get(name); | ||
|
||
Assertions.assertSame(((GaugeMetricSample) sample).applyAsLong(), count); | ||
teardown(); | ||
} | ||
|
||
|
||
|
||
private void initParam() { | ||
invocation.setTargetServiceUniqueName(GROUP + "/" + INTERFACE_NAME + ":" + VERSION); | ||
invocation.setMethodName(METHOD_NAME); | ||
invocation.setParameterTypes(new Class[]{String.class}); | ||
} | ||
|
||
private Map<String, MetricSample> getMetricsMap() { | ||
List<MetricSample> samples = collector.collect(); | ||
List<MetricSample> samples1 = new ArrayList<>(); | ||
for (MetricSample sample : samples) { | ||
if (sample.getName().contains("dubbo.thread.pool")) { | ||
continue; | ||
} | ||
samples1.add(sample); | ||
} | ||
return samples1.stream().collect(Collectors.toMap(MetricSample::getName, Function.identity())); | ||
} | ||
|
||
public class TestMetricsInvoker implements Invoker { | ||
|
||
private String side; | ||
|
||
public TestMetricsInvoker(String side) { | ||
this.side = side; | ||
} | ||
|
||
@Override | ||
public Class getInterface() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Result invoke(Invocation invocation) throws RpcException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public URL getUrl() { | ||
return URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&side="+side); | ||
} | ||
|
||
@Override | ||
public boolean isAvailable() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.