diff --git a/all/pom.xml b/all/pom.xml
index 502f6dfcf..60541d362 100644
--- a/all/pom.xml
+++ b/all/pom.xml
@@ -59,13 +59,12 @@
1.4.0
3.29.2-GA
4.1.44.Final
- 3.5.4
+ 3.5.5
3.6.3.Final
1.6.10
3.1.6
- 1.4.1
1.9.8
- 6.3.0
+ 6.5.6
1.6.9
7.0
4.5.13
@@ -285,11 +284,6 @@
sofa-rpc-tracer-opentracing-triple
${project.version}
-
- com.alipay.sofa
- sofa-rpc-metrics-lookout
- ${project.version}
-
com.alipay.sofa
sofa-rpc-metrics-micrometer
@@ -376,11 +370,6 @@
resteasy-jackson2-provider
${resteasy.version}
-
- com.alipay.sofa.lookout
- lookout-api
- ${lookout.version}
-
io.swagger
swagger-core
@@ -545,7 +534,6 @@
com.alipay.sofa:sofa-rpc-fault-tolerance
com.alipay.sofa:sofa-rpc-fault-hystrix
com.alipay.sofa:sofa-rpc-log-common-tools
- com.alipay.sofa:sofa-rpc-metrics-lookout
com.alipay.sofa:sofa-rpc-metrics-micrometer
com.alipay.sofa:sofa-rpc-metrics-prometheus
com.alipay.sofa:sofa-rpc-registry-consul
diff --git a/bom/pom.xml b/bom/pom.xml
index 3ad5d01a3..35bc91d86 100644
--- a/bom/pom.xml
+++ b/bom/pom.xml
@@ -25,14 +25,14 @@
0.22.0
3.1.11
2.0.3
- 6.3.0
+ 6.5.6
1.2.2
1.6.9
7.0
32.0.0-jre
0.16.0
- 3.5.4
+ 3.5.5
0.9.2
3.22.0
2.12.7
@@ -56,7 +56,6 @@
1.6.10
1.4.0
3.1.6
- 1.4.1
true
true
@@ -472,17 +471,6 @@
tracer-core
${tracer.version}
-
-
- com.alipay.sofa.lookout
- lookout-api
- ${lookout.version}
-
-
- com.alipay.sofa.lookout
- lookout-core
- ${lookout.version}
-
io.micrometer
diff --git a/core/api/src/main/java/com/alipay/sofa/rpc/common/RpcOptions.java b/core/api/src/main/java/com/alipay/sofa/rpc/common/RpcOptions.java
index 46c43206c..ff9ebebd3 100644
--- a/core/api/src/main/java/com/alipay/sofa/rpc/common/RpcOptions.java
+++ b/core/api/src/main/java/com/alipay/sofa/rpc/common/RpcOptions.java
@@ -529,6 +529,7 @@ public class RpcOptions {
/**
* Whether to close lookout collection.
*/
+ @Deprecated
public static final String LOOKOUT_COLLECT_DISABLE = "lookout.collect.disable";
/**
diff --git a/metrics/metrics-lookout/pom.xml b/metrics/metrics-lookout/pom.xml
deleted file mode 100644
index d8696fa0b..000000000
--- a/metrics/metrics-lookout/pom.xml
+++ /dev/null
@@ -1,107 +0,0 @@
-
-
-
- sofa-rpc-metrics
- com.alipay.sofa
- ${revision}
-
- 4.0.0
-
- sofa-rpc-metrics-lookout
-
-
-
-
-
- com.alipay.sofa
- sofa-rpc-log-common-tools
- ${project.parent.version}
-
-
-
-
- com.alipay.sofa.lookout
- lookout-api
-
-
-
-
- com.alipay.sofa.lookout
- lookout-core
- test
-
-
-
- org.slf4j
- slf4j-log4j12
- test
-
-
- junit
- junit
- test
-
-
-
-
- src/main/java
-
-
- src/main/resources
- false
-
- **/**
-
-
-
- src/test/java
-
-
- src/test/resources
- false
-
- **/**
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
-
- ${maven.compiler.source}
- ${maven.compiler.target}
- ${project.build.sourceEncoding}
-
-
-
- org.apache.maven.plugins
- maven-install-plugin
-
- ${module.install.skip}
-
-
-
- org.apache.maven.plugins
- maven-deploy-plugin
-
- ${module.deploy.skip}
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
- ${skipTests}
-
- **/*Test.java
-
- once
-
-
-
-
-
diff --git a/metrics/metrics-lookout/src/main/java/com/alipay/sofa/rpc/event/LookoutSubscriber.java b/metrics/metrics-lookout/src/main/java/com/alipay/sofa/rpc/event/LookoutSubscriber.java
deleted file mode 100644
index 51f292f92..000000000
--- a/metrics/metrics-lookout/src/main/java/com/alipay/sofa/rpc/event/LookoutSubscriber.java
+++ /dev/null
@@ -1,199 +0,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.
- */
-package com.alipay.sofa.rpc.event;
-
-import com.alipay.sofa.rpc.common.RemotingConstants;
-import com.alipay.sofa.rpc.common.RpcConfigs;
-import com.alipay.sofa.rpc.common.RpcConstants;
-import com.alipay.sofa.rpc.common.RpcOptions;
-import com.alipay.sofa.rpc.context.RpcInternalContext;
-import com.alipay.sofa.rpc.context.RpcRunningState;
-import com.alipay.sofa.rpc.core.request.SofaRequest;
-import com.alipay.sofa.rpc.core.response.SofaResponse;
-import com.alipay.sofa.rpc.metrics.lookout.RpcClientLookoutModel;
-import com.alipay.sofa.rpc.metrics.lookout.RpcLookout;
-import com.alipay.sofa.rpc.metrics.lookout.RpcServerLookoutModel;
-
-/**
- * Collect the raw information for lookout by listening to events.
- *
- * @author LiWei.Liangen
- */
-public class LookoutSubscriber extends Subscriber {
-
- /**
- * Whether lookout be banned from collecting information.
- */
- public static boolean lookoutCollectDisable = RpcConfigs
- .getBooleanValue(RpcOptions.LOOKOUT_COLLECT_DISABLE);
-
- private final RpcLookout rpcMetrics = new RpcLookout();
-
- public LookoutSubscriber() {
- super(false);
- }
-
- @Override
- public void onEvent(Event event) {
-
- if (RpcRunningState.isUnitTestMode() || lookoutCollectDisable) {
- return;
- }
-
- Class eventClass = event.getClass();
-
- if (eventClass == ClientEndInvokeEvent.class) {
-
- ClientEndInvokeEvent clientEndInvokeEvent = (ClientEndInvokeEvent) event;
-
- RpcClientLookoutModel rpcClientMetricsModel = createClientMetricsModel(clientEndInvokeEvent.getRequest(),
- clientEndInvokeEvent.getResponse());
-
- rpcMetrics.collectClient(rpcClientMetricsModel);
-
- } else if (eventClass == ServerSendEvent.class) {
-
- ServerSendEvent serverSendEvent = (ServerSendEvent) event;
-
- RpcServerLookoutModel rpcServerMetricsModel = createServerMetricsModel(serverSendEvent.getRequest(),
- serverSendEvent.getResponse());
-
- rpcMetrics.collectServer(rpcServerMetricsModel);
-
- } else if (eventClass == ServerStartedEvent.class) {
-
- ServerStartedEvent serverStartedEvent = (ServerStartedEvent) event;
-
- if (serverStartedEvent.getThreadPoolExecutor() != null) {
- rpcMetrics.collectThreadPool(serverStartedEvent.getServerConfig(),
- serverStartedEvent.getThreadPoolExecutor());
- }
-
- } else if (eventClass == ServerStoppedEvent.class) {
- ServerStoppedEvent serverStartedEvent = (ServerStoppedEvent) event;
- rpcMetrics.removeThreadPool(serverStartedEvent.getServerConfig());
- } else if (eventClass == ProviderPubEvent.class) {
- ProviderPubEvent providerPubEvent = (ProviderPubEvent) event;
- rpcMetrics.collectProvderPubInfo(providerPubEvent.getProviderConfig());
- }
- else if (eventClass == ConsumerSubEvent.class) {
- ConsumerSubEvent consumerSubEvent = (ConsumerSubEvent) event;
- rpcMetrics.collectConsumerSubInfo(consumerSubEvent.getConsumerConfig());
- }
- }
-
- /**
- * create RpcClientLookoutModel
- * @param request
- * @param response
- * @return
- */
- private RpcClientLookoutModel createClientMetricsModel(SofaRequest request, SofaResponse response) {
-
- RpcClientLookoutModel clientMetricsModel = new RpcClientLookoutModel();
-
- RpcInternalContext context = RpcInternalContext.getContext();
-
- String app = getStringAvoidNull(context.getAttachment(RpcConstants.INTERNAL_KEY_APP_NAME));
- String service = request.getTargetServiceUniqueName();
- String method = request.getMethodName();
- String protocol = getStringAvoidNull(context.getAttachment(RpcConstants.INTERNAL_KEY_PROTOCOL_NAME));
- String invokeType = request.getInvokeType();
- String targetApp = request.getTargetAppName();
- Long requestSize = getLongAvoidNull(context.getAttachment(RpcConstants.INTERNAL_KEY_REQ_SIZE));
- Long responseSize = getLongAvoidNull(context.getAttachment(RpcConstants.INTERNAL_KEY_RESP_SIZE));
- Long elapsedTime = getLongAvoidNull(context.getAttachment(RpcConstants.INTERNAL_KEY_CLIENT_ELAPSE));
- Boolean success = response != null && !response.isError() && response.getErrorMsg() == null &&
- (!(response.getAppResponse() instanceof Throwable));
-
- clientMetricsModel.setApp(app);
- clientMetricsModel.setService(service);
- clientMetricsModel.setMethod(method);
- clientMetricsModel.setProtocol(protocol);
- clientMetricsModel.setInvokeType(invokeType);
- clientMetricsModel.setTargetApp(targetApp);
- clientMetricsModel.setRequestSize(requestSize);
- clientMetricsModel.setResponseSize(responseSize);
- clientMetricsModel.setElapsedTime(elapsedTime);
- clientMetricsModel.setSuccess(success);
-
- return clientMetricsModel;
- }
-
- /**
- * create RpcServerLookoutModel
- * @param request
- * @param response
- * @return
- */
- private RpcServerLookoutModel createServerMetricsModel(SofaRequest request, SofaResponse response) {
-
- RpcServerLookoutModel rpcServerMetricsModel = new RpcServerLookoutModel();
-
- RpcInternalContext context = RpcInternalContext.getContext();
-
- String app = request.getTargetAppName();
- String service = request.getTargetServiceUniqueName();
- String method = request.getMethodName();
- String protocol = getStringAvoidNull(request.getRequestProp(RemotingConstants.HEAD_PROTOCOL));
- String invokeType = request.getInvokeType();
- String callerApp = getStringAvoidNull(request.getRequestProp(RemotingConstants.HEAD_APP_NAME));
- Long elapsedTime = getLongAvoidNull(context.getAttachment(RpcConstants.INTERNAL_KEY_IMPL_ELAPSE));
- boolean success = response != null && !response.isError() && response.getErrorMsg() == null &&
- (!(response.getAppResponse() instanceof Throwable));
-
- rpcServerMetricsModel.setApp(app);
- rpcServerMetricsModel.setService(service);
- rpcServerMetricsModel.setMethod(method);
- rpcServerMetricsModel.setProtocol(protocol);
- rpcServerMetricsModel.setInvokeType(invokeType);
- rpcServerMetricsModel.setCallerApp(callerApp);
- rpcServerMetricsModel.setElapsedTime(elapsedTime);
- rpcServerMetricsModel.setSuccess(success);
-
- return rpcServerMetricsModel;
- }
-
- private String getStringAvoidNull(Object object) {
- if (object == null) {
- return null;
- }
-
- return (String) object;
-
- }
-
- private Long getLongAvoidNull(Object object) {
- if (object == null) {
- return null;
- }
-
- if (object instanceof Integer) {
- return Long.parseLong(object.toString());
- }
-
- return (Long) object;
- }
-
- public static boolean isLookoutCollectDisable() {
- return lookoutCollectDisable;
- }
-
- public static void setLookoutCollectDisable(boolean lookoutCollectDisable) {
- LookoutSubscriber.lookoutCollectDisable = lookoutCollectDisable;
- }
-}
\ No newline at end of file
diff --git a/metrics/metrics-lookout/src/main/java/com/alipay/sofa/rpc/metrics/lookout/RpcAbstractLookoutModel.java b/metrics/metrics-lookout/src/main/java/com/alipay/sofa/rpc/metrics/lookout/RpcAbstractLookoutModel.java
deleted file mode 100644
index 72d4ec773..000000000
--- a/metrics/metrics-lookout/src/main/java/com/alipay/sofa/rpc/metrics/lookout/RpcAbstractLookoutModel.java
+++ /dev/null
@@ -1,164 +0,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.
- */
-package com.alipay.sofa.rpc.metrics.lookout;
-
-/**
- *
- * @author LiWei.Liangen
- */
-public class RpcAbstractLookoutModel {
-
- protected String app;
-
- protected String service;
-
- protected String method;
-
- protected String protocol;
-
- protected String invokeType;
-
- protected Long elapsedTime;
-
- protected boolean success;
-
- /**
- * Getter method for property app.
- *
- * @return property value of app
- */
- public String getApp() {
- return app;
- }
-
- /**
- * Setter method for property app.
- *
- * @param app value to be assigned to property app
- */
- public void setApp(String app) {
- this.app = app;
- }
-
- /**
- * Getter method for property service.
- *
- * @return property value of service
- */
- public String getService() {
- return service;
- }
-
- /**
- * Setter method for property service.
- *
- * @param service value to be assigned to property service
- */
- public void setService(String service) {
- this.service = service;
- }
-
- /**
- * Getter method for property method.
- *
- * @return property value of method
- */
- public String getMethod() {
- return method;
- }
-
- /**
- * Setter method for property method.
- *
- * @param method value to be assigned to property method
- */
- public void setMethod(String method) {
- this.method = method;
- }
-
- /**
- * Getter method for property protocol.
- *
- * @return property value of protocol
- */
- public String getProtocol() {
- return protocol;
- }
-
- /**
- * Setter method for property protocol.
- *
- * @param protocol value to be assigned to property protocol
- */
- public void setProtocol(String protocol) {
- this.protocol = protocol;
- }
-
- /**
- * Getter method for property invokeType.
- *
- * @return property value of invokeType
- */
- public String getInvokeType() {
- return invokeType;
- }
-
- /**
- * Setter method for property invokeType.
- *
- * @param invokeType value to be assigned to property invokeType
- */
- public void setInvokeType(String invokeType) {
- this.invokeType = invokeType;
- }
-
- /**
- * Getter method for property elapsedTime.
- *
- * @return property value of elapsedTime
- */
- public Long getElapsedTime() {
- return elapsedTime;
- }
-
- /**
- * Setter method for property elapsedTime.
- *
- * @param elapsedTime value to be assigned to property elapsedTime
- */
- public void setElapsedTime(Long elapsedTime) {
- this.elapsedTime = elapsedTime;
- }
-
- /**
- * Getter method for property success.
- *
- * @return property value of success
- */
- public boolean getSuccess() {
- return success;
- }
-
- /**
- * Setter method for property success.
- *
- * @param success value to be assigned to property success
- */
- public void setSuccess(boolean success) {
- this.success = success;
- }
-}
\ No newline at end of file
diff --git a/metrics/metrics-lookout/src/main/java/com/alipay/sofa/rpc/metrics/lookout/RpcClientLookoutModel.java b/metrics/metrics-lookout/src/main/java/com/alipay/sofa/rpc/metrics/lookout/RpcClientLookoutModel.java
deleted file mode 100644
index 1128934c1..000000000
--- a/metrics/metrics-lookout/src/main/java/com/alipay/sofa/rpc/metrics/lookout/RpcClientLookoutModel.java
+++ /dev/null
@@ -1,101 +0,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.
- */
-package com.alipay.sofa.rpc.metrics.lookout;
-
-/**
- * The model for lookout info of client
- *
- * @author LiWei.Liangen
- */
-public class RpcClientLookoutModel extends RpcAbstractLookoutModel {
-
- protected String targetApp;
-
- protected Long requestSize;
-
- protected Long responseSize;
-
- /**
- * Getter method for property targetApp.
- *
- * @return property value of targetApp
- */
- public String getTargetApp() {
- return targetApp;
- }
-
- /**
- * Setter method for property targetApp.
- *
- * @param targetApp value to be assigned to property targetApp
- */
- public void setTargetApp(String targetApp) {
- this.targetApp = targetApp;
- }
-
- /**
- * Getter method for property requestSize.
- *
- * @return property value of requestSize
- */
- public Long getRequestSize() {
- return requestSize;
- }
-
- /**
- * Setter method for property requestSize.
- *
- * @param requestSize value to be assigned to property requestSize
- */
- public void setRequestSize(Long requestSize) {
- this.requestSize = requestSize;
- }
-
- /**
- * Getter method for property responseSize.
- *
- * @return property value of responseSize
- */
- public Long getResponseSize() {
- return responseSize;
- }
-
- /**
- * Setter method for property responseSize.
- *
- * @param responseSize value to be assigned to property responseSize
- */
- public void setResponseSize(Long responseSize) {
- this.responseSize = responseSize;
- }
-
- @Override
- public String toString() {
- return "RpcClientLookoutModel{" +
- "targetApp='" + targetApp + '\'' +
- ", requestSize=" + requestSize +
- ", responseSize=" + responseSize +
- ", app='" + app + '\'' +
- ", service='" + service + '\'' +
- ", method='" + method + '\'' +
- ", protocol='" + protocol + '\'' +
- ", invokeType='" + invokeType + '\'' +
- ", elapsedTime=" + elapsedTime +
- ", success=" + success +
- '}';
- }
-}
\ No newline at end of file
diff --git a/metrics/metrics-lookout/src/main/java/com/alipay/sofa/rpc/metrics/lookout/RpcLookout.java b/metrics/metrics-lookout/src/main/java/com/alipay/sofa/rpc/metrics/lookout/RpcLookout.java
deleted file mode 100644
index 64f878c91..000000000
--- a/metrics/metrics-lookout/src/main/java/com/alipay/sofa/rpc/metrics/lookout/RpcLookout.java
+++ /dev/null
@@ -1,354 +0,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.
- */
-package com.alipay.sofa.rpc.metrics.lookout;
-
-import com.alipay.lookout.api.Counter;
-import com.alipay.lookout.api.DistributionSummary;
-import com.alipay.lookout.api.Gauge;
-import com.alipay.lookout.api.Id;
-import com.alipay.lookout.api.Lookout;
-import com.alipay.lookout.api.Timer;
-import com.alipay.lookout.api.composite.MixinMetric;
-import com.alipay.lookout.api.info.Info;
-import com.alipay.sofa.rpc.common.utils.StringUtils;
-import com.alipay.sofa.rpc.config.ConsumerConfig;
-import com.alipay.sofa.rpc.config.ProviderConfig;
-import com.alipay.sofa.rpc.config.ServerConfig;
-import com.alipay.sofa.rpc.log.LogCodes;
-import com.alipay.sofa.rpc.log.Logger;
-import com.alipay.sofa.rpc.log.LoggerFactory;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Rpc reports the information to lookout.
- *
- * @author LiWei.Liangen
- */
-public class RpcLookout {
-
- /**
- * slf4j Logger for this class
- */
- private final static Logger LOGGER = LoggerFactory.getLogger(RpcLookout.class);
-
- private final RpcLookoutId rpcLookoutId = new RpcLookoutId();
-
- /**
- * Collect the RPC client information.
- *
- * @param rpcClientMetricsModel client information model
- */
- public void collectClient(RpcClientLookoutModel rpcClientMetricsModel) {
-
- try {
- Id methodConsumerId = createMethodConsumerId(rpcClientMetricsModel);
- MixinMetric methodConsumerMetric = Lookout.registry().mixinMetric(methodConsumerId);
-
- recordCounterAndTimer(methodConsumerMetric, rpcClientMetricsModel);
-
- recordSize(methodConsumerMetric, rpcClientMetricsModel);
-
- } catch (Throwable t) {
- LOGGER.error(LogCodes.getLog(LogCodes.ERROR_METRIC_REPORT_ERROR), t);
- }
- }
-
- /**
- * Collect the RPC server information.
- *
- * @param rpcServerMetricsModel server information model
- */
- public void collectServer(RpcServerLookoutModel rpcServerMetricsModel) {
-
- try {
- Id methodProviderId = createMethodProviderId(rpcServerMetricsModel);
- MixinMetric methodProviderMetric = Lookout.registry().mixinMetric(methodProviderId);
-
- recordCounterAndTimer(methodProviderMetric, rpcServerMetricsModel);
-
- } catch (Throwable t) {
- LOGGER.error(LogCodes.getLog(LogCodes.ERROR_METRIC_REPORT_ERROR), t);
- }
- }
-
- /**
- * Collect the thread pool information
- *
- * @param serverConfig ServerConfig
- * @param threadPoolExecutor ThreadPoolExecutor
- */
- public void collectThreadPool(ServerConfig serverConfig, final ThreadPoolExecutor threadPoolExecutor) {
- try {
-
- int coreSize = serverConfig.getCoreThreads();
- int maxSize = serverConfig.getMaxThreads();
- int queueSize = serverConfig.getQueues();
-
- final ThreadPoolConfig threadPoolConfig = new ThreadPoolConfig(coreSize, maxSize, queueSize);
-
- Lookout.registry().info(rpcLookoutId.fetchServerThreadConfigId(serverConfig), new Info() {
-
- @Override
- public ThreadPoolConfig value() {
- return threadPoolConfig;
- }
- });
-
- Lookout.registry().gauge(rpcLookoutId.fetchServerThreadPoolActiveCountId(serverConfig),
- new Gauge() {
-
- @Override
- public Integer value() {
- return threadPoolExecutor.getActiveCount();
- }
- });
-
- Lookout.registry().gauge(rpcLookoutId.fetchServerThreadPoolIdleCountId(serverConfig), new Gauge() {
-
- @Override
- public Integer value() {
- return threadPoolExecutor.getPoolSize() - threadPoolExecutor.getActiveCount();
- }
- });
-
- Lookout.registry().gauge(rpcLookoutId.fetchServerThreadPoolQueueSizeId(serverConfig), new Gauge() {
-
- @Override
- public Integer value() {
- return threadPoolExecutor.getQueue().size();
- }
- });
- } catch (Throwable t) {
- LOGGER.error(LogCodes.getLog(LogCodes.ERROR_METRIC_REPORT_ERROR), t);
- }
- }
-
- /**
- * remove the thread pool information
- *
- * @param serverConfig server config
- */
- public void removeThreadPool(ServerConfig serverConfig) {
- Lookout.registry().removeMetric(rpcLookoutId.removeServerThreadConfigId(serverConfig));
- Lookout.registry().removeMetric(rpcLookoutId.removeServerThreadPoolActiveCountId(serverConfig));
- Lookout.registry().removeMetric(rpcLookoutId.removeServerThreadPoolIdleCountId(serverConfig));
- Lookout.registry().removeMetric(rpcLookoutId.removeServerThreadPoolQueueSizeId(serverConfig));
- }
-
- /**
- * Record the number of calls and time consuming.
- *
- * @param mixinMetric MixinMetric
- * @param model information model
- */
- private void recordCounterAndTimer(MixinMetric mixinMetric, RpcAbstractLookoutModel model) {
- Counter totalCounter = mixinMetric.counter("total_count");
- Timer totalTimer = mixinMetric.timer("total_time");
-
- Long elapsedTime = model.getElapsedTime();
-
- totalCounter.inc();
- if (elapsedTime != null) {
- totalTimer.record(elapsedTime, TimeUnit.MILLISECONDS);
- }
-
- if (!model.getSuccess()) {
- Counter failCounter = mixinMetric.counter("fail_count");
- Timer failTimer = mixinMetric.timer("fail_time");
-
- failCounter.inc();
- if (elapsedTime != null) {
- failTimer.record(elapsedTime, TimeUnit.MILLISECONDS);
- }
- }
- }
-
- /**
- * Record request size and response size
- *
- * @param mixinMetric MixinMetric
- * @param model information model
- */
- private void recordSize(MixinMetric mixinMetric, RpcClientLookoutModel model) {
-
- Long requestSize = model.getRequestSize();
- Long responseSize = model.getResponseSize();
-
- if (requestSize != null) {
- DistributionSummary requestSizeDS = mixinMetric.distributionSummary("request_size");
- requestSizeDS.record(model.getRequestSize());
- }
-
- if (responseSize != null) {
- DistributionSummary responseSizeDS = mixinMetric.distributionSummary("response_size");
- responseSizeDS.record(model.getResponseSize());
- }
- }
-
- /**
- * Create consumer id
- *
- * @param model RpcClientLookoutModel
- * @return Id
- */
- private Id createMethodConsumerId(RpcClientLookoutModel model) {
-
- Map tags = new HashMap(6);
-
- tags.put("app", StringUtils.defaultString(model.getApp()));
- tags.put("service", StringUtils.defaultString(model.getService()));
- tags.put("method", StringUtils.defaultString(model.getMethod()));
- tags.put("protocol", StringUtils.defaultString(model.getProtocol()));
- tags.put("invoke_type", StringUtils.defaultString(model.getInvokeType()));
- tags.put("target_app", StringUtils.defaultString(model.getTargetApp()));
-
- return rpcLookoutId.fetchConsumerStatId(tags);
- }
-
- /**
- * Create provider id
- *
- * @param model RpcServerLookoutModel
- * @return Id
- */
- public Id createMethodProviderId(RpcServerLookoutModel model) {
- Map tags = new HashMap(5);
- tags.put("app", StringUtils.defaultString(model.getApp()));
- tags.put("service", StringUtils.defaultString(model.getService()));
- tags.put("method", StringUtils.defaultString(model.getMethod()));
- tags.put("protocol", StringUtils.defaultString(model.getProtocol()));
- tags.put("caller_app", StringUtils.defaultString(model.getCallerApp()));
-
- return rpcLookoutId.fetchProviderStatId(tags);
- }
-
- /**
- * Collect the RPC client information.
- *
- * @param providerConfig client information model
- */
- public void collectProvderPubInfo(final ProviderConfig providerConfig) {
-
- try {
- Id providerConfigId = rpcLookoutId.fetchProviderPubId();
- Lookout.registry().info(providerConfigId, new Info() {
- @Override
- public ProviderConfig value() {
- return providerConfig;
- }
- });
- } catch (Throwable t) {
- LOGGER.error(LogCodes.getLog(LogCodes.ERROR_METRIC_REPORT_ERROR), t);
- }
- }
-
- /**
- * Collect the RPC client information.
- *
- * @param consumerConfig client information model
- */
- public void collectConsumerSubInfo(final ConsumerConfig consumerConfig) {
-
- try {
- Id consumerConfigId = rpcLookoutId.fetchConsumerSubId();
- Lookout.registry().info(consumerConfigId, new Info() {
- @Override
- public ConsumerConfig value() {
- return consumerConfig;
- }
- });
- } catch (Throwable t) {
- LOGGER.error(LogCodes.getLog(LogCodes.ERROR_METRIC_REPORT_ERROR), t);
- }
- }
-
- /**
- * Thread pool static configuration information.
- */
- private class ThreadPoolConfig {
-
- private int corePoolSize;
-
- private int maxPoolSize;
-
- private int queueSize;
-
- public ThreadPoolConfig(int corePoolSize, int maxPoolSize, int queueSize) {
- this.corePoolSize = corePoolSize;
- this.maxPoolSize = maxPoolSize;
- this.queueSize = queueSize;
- }
-
- /**
- * Getter method for property corePoolSize.
- *
- * @return property value of corePoolSize
- */
- public int getCorePoolSize() {
- return corePoolSize;
- }
-
- /**
- * Setter method for property corePoolSize.
- *
- * @param corePoolSize value to be assigned to property corePoolSize
- */
- public void setCorePoolSize(int corePoolSize) {
- this.corePoolSize = corePoolSize;
- }
-
- /**
- * Getter method for property maxPoolSize.
- *
- * @return property value of maxPoolSize
- */
- public int getMaxPoolSize() {
- return maxPoolSize;
- }
-
- /**
- * Setter method for property maxPoolSize.
- *
- * @param maxPoolSize value to be assigned to property maxPoolSize
- */
- public void setMaxPoolSize(int maxPoolSize) {
- this.maxPoolSize = maxPoolSize;
- }
-
- /**
- * Getter method for property queueSize.
- *
- * @return property value of queueSize
- */
- public int getQueueSize() {
- return queueSize;
- }
-
- /**
- * Setter method for property queueSize.
- *
- * @param queueSize value to be assigned to property queueSize
- */
- public void setQueueSize(int queueSize) {
- this.queueSize = queueSize;
- }
- }
-}
\ No newline at end of file
diff --git a/metrics/metrics-lookout/src/main/java/com/alipay/sofa/rpc/metrics/lookout/RpcLookoutId.java b/metrics/metrics-lookout/src/main/java/com/alipay/sofa/rpc/metrics/lookout/RpcLookoutId.java
deleted file mode 100644
index e9d406d78..000000000
--- a/metrics/metrics-lookout/src/main/java/com/alipay/sofa/rpc/metrics/lookout/RpcLookoutId.java
+++ /dev/null
@@ -1,179 +0,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.
- */
-package com.alipay.sofa.rpc.metrics.lookout;
-
-import com.alipay.lookout.api.Id;
-import com.alipay.lookout.api.Lookout;
-import com.alipay.sofa.rpc.config.ServerConfig;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
-/**
- * @author LiWei.Liangen
- */
-public class RpcLookoutId {
-
- private final ConcurrentMap consumerIds = new ConcurrentHashMap();
-
- private final ConcurrentMap providerIds = new ConcurrentHashMap();
-
- private final ConcurrentMap serverConfigIds = new ConcurrentHashMap();
-
- private volatile Id consumerConfigId;
-
- private volatile Id providerConfigId;
-
- private static final Lock classLock = new ReentrantLock();
- private final Lock consumerConfigIdLock = new ReentrantLock();
- private final Lock providerConfigIdLock = new ReentrantLock();
-
- /**
- * create consumerId
- *
- * @return consumerId
- */
- public Id fetchConsumerStatId(Map tags) {
-
- String key = tags.toString();
- Id lookoutId = consumerIds.get(key);
- if (lookoutId == null) {
- classLock.lock();
- try {
- lookoutId = consumerIds.get(key);
- if (lookoutId == null) {
- lookoutId = Lookout.registry().createId("rpc.consumer.service.stats", tags);
- consumerIds.put(key, lookoutId);
- }
- } finally {
- classLock.unlock();
- }
- }
- return lookoutId;
- }
-
- /**
- * Create ProviderId
- *
- * @return ProviderId
- */
- public Id fetchProviderStatId(Map tags) {
- String key = tags.toString();
- Id lookoutId = providerIds.get(key);
- if (lookoutId == null) {
- classLock.lock();
- try {
- lookoutId = providerIds.get(key);
- if (lookoutId == null) {
- lookoutId = Lookout.registry().createId("rpc.provider.service.stats", tags);
- providerIds.put(key, lookoutId);
- }
- } finally {
- classLock.unlock();
- }
- }
- return lookoutId;
- }
-
- public Id fetchConsumerSubId() {
- if (consumerConfigId == null) {
- consumerConfigIdLock.lock();
- try {
- if (consumerConfigId == null) {
- consumerConfigId = Lookout.registry().createId("rpc.consumer.info.stats");
- }
- } finally {
- consumerConfigIdLock.unlock();
- }
- }
- return consumerConfigId;
- }
-
- public Id fetchProviderPubId() {
- if (providerConfigId == null) {
- providerConfigIdLock.lock();
- try {
- if (providerConfigId == null) {
- providerConfigId = Lookout.registry().createId("rpc.provider.info.stats");
- }
- } finally {
- providerConfigIdLock.unlock();
- }
- }
- return providerConfigId;
- }
-
- public synchronized Id fetchServerThreadConfigId(ServerConfig serverConfig) {
- String key = "rpc." + serverConfig.getProtocol() + ".threadpool.config";
- return fetchServerConfigId(key);
- }
-
- public Id fetchServerThreadPoolActiveCountId(ServerConfig serverConfig) {
- String key = "rpc." + serverConfig.getProtocol() + ".threadpool.active.count";
- return fetchServerConfigId(key);
- }
-
- public Id fetchServerThreadPoolIdleCountId(ServerConfig serverConfig) {
- String key = "rpc." + serverConfig.getProtocol() + ".threadpool.idle.count";
- return fetchServerConfigId(key);
- }
-
- public Id fetchServerThreadPoolQueueSizeId(ServerConfig serverConfig) {
- String key = "rpc." + serverConfig.getProtocol() + ".threadpool.queue.size";
- return fetchServerConfigId(key);
- }
-
- private Id fetchServerConfigId(String key) {
- Id lookoutId = serverConfigIds.get(key);
- if (lookoutId == null) {
- classLock.lock();
- try {
- lookoutId = serverConfigIds.get(key);
- if (lookoutId == null) {
- lookoutId = Lookout.registry().createId(key);
- serverConfigIds.put(key, lookoutId);
- }
- } finally {
- classLock.unlock();
- }
- }
- return lookoutId;
- }
-
- public Id removeServerThreadConfigId(ServerConfig serverConfig) {
- String key = "rpc." + serverConfig.getProtocol() + ".threadpool.config";
- return serverConfigIds.remove(key);
- }
-
- public Id removeServerThreadPoolActiveCountId(ServerConfig serverConfig) {
- String key = "rpc." + serverConfig.getProtocol() + ".threadpool.active.count";
- return serverConfigIds.remove(key);
- }
-
- public Id removeServerThreadPoolIdleCountId(ServerConfig serverConfig) {
- String key = "rpc." + serverConfig.getProtocol() + ".threadpool.idle.count";
- return serverConfigIds.remove(key);
- }
-
- public Id removeServerThreadPoolQueueSizeId(ServerConfig serverConfig) {
- String key = "rpc." + serverConfig.getProtocol() + ".threadpool.queue.size";
- return serverConfigIds.remove(key);
- }
-}
\ No newline at end of file
diff --git a/metrics/metrics-lookout/src/main/java/com/alipay/sofa/rpc/metrics/lookout/RpcServerLookoutModel.java b/metrics/metrics-lookout/src/main/java/com/alipay/sofa/rpc/metrics/lookout/RpcServerLookoutModel.java
deleted file mode 100644
index db29dacc7..000000000
--- a/metrics/metrics-lookout/src/main/java/com/alipay/sofa/rpc/metrics/lookout/RpcServerLookoutModel.java
+++ /dev/null
@@ -1,59 +0,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.
- */
-package com.alipay.sofa.rpc.metrics.lookout;
-
-/**
- * The model for lookout info of server
- *
- * @author LiWei.Liangen
- */
-public class RpcServerLookoutModel extends RpcAbstractLookoutModel {
-
- protected String callerApp;
-
- /**
- * Getter method for property callerApp.
- *
- * @return property value of callerApp
- */
- public String getCallerApp() {
- return callerApp;
- }
-
- /**
- * Setter method for property callerApp.
- *
- * @param callerApp value to be assigned to property callerApp
- */
- public void setCallerApp(String callerApp) {
- this.callerApp = callerApp;
- }
-
- @Override
- public String toString() {
- return "RpcServerLookoutModel{" +
- "callerApp='" + callerApp + '\'' +
- ", app='" + app + '\'' +
- ", service='" + service + '\'' +
- ", method='" + method + '\'' +
- ", protocol='" + protocol + '\'' +
- ", invokeType='" + invokeType + '\'' +
- ", elapsedTime=" + elapsedTime +
- ", success=" + success +
- '}';
- }
-}
\ No newline at end of file
diff --git a/metrics/metrics-lookout/src/main/java/com/alipay/sofa/rpc/module/LookoutModule.java b/metrics/metrics-lookout/src/main/java/com/alipay/sofa/rpc/module/LookoutModule.java
deleted file mode 100644
index a1ed9ed93..000000000
--- a/metrics/metrics-lookout/src/main/java/com/alipay/sofa/rpc/module/LookoutModule.java
+++ /dev/null
@@ -1,71 +0,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.
- */
-package com.alipay.sofa.rpc.module;
-
-import com.alipay.sofa.rpc.event.ClientEndInvokeEvent;
-import com.alipay.sofa.rpc.event.ConsumerSubEvent;
-import com.alipay.sofa.rpc.event.EventBus;
-import com.alipay.sofa.rpc.event.LookoutSubscriber;
-import com.alipay.sofa.rpc.event.ProviderPubEvent;
-import com.alipay.sofa.rpc.event.ServerSendEvent;
-import com.alipay.sofa.rpc.event.ServerStartedEvent;
-import com.alipay.sofa.rpc.event.ServerStoppedEvent;
-import com.alipay.sofa.rpc.ext.Extension;
-
-/**
- *
- * @author LiWei.Liangen
- */
-@Extension("lookout")
-public class LookoutModule implements Module {
-
- private LookoutSubscriber subscriber;
-
- @Override
- public boolean needLoad() {
- try {
- Class.forName("com.alipay.lookout.spi.MetricsImporterLocator");
- return true;
- } catch (Exception e) {
- return false;
- }
- }
-
- @Override
- public void install() {
- subscriber = new LookoutSubscriber();
- EventBus.register(ClientEndInvokeEvent.class, subscriber);
- EventBus.register(ServerSendEvent.class, subscriber);
- EventBus.register(ServerStartedEvent.class, subscriber);
- EventBus.register(ServerStoppedEvent.class, subscriber);
- EventBus.register(ProviderPubEvent.class, subscriber);
- EventBus.register(ConsumerSubEvent.class, subscriber);
-
- }
-
- @Override
- public void uninstall() {
- if (subscriber != null) {
- EventBus.unRegister(ClientEndInvokeEvent.class, subscriber);
- EventBus.unRegister(ServerSendEvent.class, subscriber);
- EventBus.unRegister(ServerStartedEvent.class, subscriber);
- EventBus.unRegister(ServerStoppedEvent.class, subscriber);
- EventBus.unRegister(ProviderPubEvent.class, subscriber);
- EventBus.unRegister(ConsumerSubEvent.class, subscriber);
- }
- }
-}
\ No newline at end of file
diff --git a/metrics/metrics-lookout/src/main/resources/META-INF/services/sofa-rpc/com.alipay.sofa.rpc.module.Module b/metrics/metrics-lookout/src/main/resources/META-INF/services/sofa-rpc/com.alipay.sofa.rpc.module.Module
deleted file mode 100644
index 35bb4542d..000000000
--- a/metrics/metrics-lookout/src/main/resources/META-INF/services/sofa-rpc/com.alipay.sofa.rpc.module.Module
+++ /dev/null
@@ -1 +0,0 @@
-lookout=com.alipay.sofa.rpc.module.LookoutModule
\ No newline at end of file
diff --git a/metrics/metrics-lookout/src/test/java/com/alipay/sofa/rpc/module/ConsumerSubTest.java b/metrics/metrics-lookout/src/test/java/com/alipay/sofa/rpc/module/ConsumerSubTest.java
deleted file mode 100644
index 9d4bcc0ce..000000000
--- a/metrics/metrics-lookout/src/test/java/com/alipay/sofa/rpc/module/ConsumerSubTest.java
+++ /dev/null
@@ -1,71 +0,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.
- */
-package com.alipay.sofa.rpc.module;
-
-import com.alipay.lookout.api.Lookout;
-import com.alipay.lookout.api.NoopRegistry;
-import com.alipay.lookout.api.Registry;
-import com.alipay.lookout.core.DefaultRegistry;
-import com.alipay.lookout.core.InfoWrapper;
-import com.alipay.sofa.rpc.config.ConsumerConfig;
-import com.alipay.sofa.rpc.event.ConsumerSubEvent;
-import com.alipay.sofa.rpc.event.EventBus;
-import com.alipay.sofa.rpc.metrics.lookout.RpcLookoutId;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * @author zhiyuan.lzy
- */
-public class ConsumerSubTest {
-
- @Test
- public void testSubLookout() {
-
- Registry registry = new DefaultRegistry();
-
- if (Lookout.registry() == NoopRegistry.INSTANCE) {
- Lookout.setRegistry(registry);
- }
-
- LookoutModule lookoutModule = new LookoutModule();
- Assert.assertEquals(true, lookoutModule.needLoad());
-
- lookoutModule.install();
- ConsumerConfig consumerConfig = new ConsumerConfig();
- consumerConfig.setInterfaceId("a");
- EventBus.post(new ConsumerSubEvent(consumerConfig));
-
- try {
- TimeUnit.SECONDS.sleep(5);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- RpcLookoutId rpcLookoutId = new RpcLookoutId();
- InfoWrapper result = Lookout.registry().get(rpcLookoutId.fetchConsumerSubId());
- final Object value = result.value();
- Assert.assertTrue(value instanceof ConsumerConfig);
-
- consumerConfig = (ConsumerConfig) value;
-
- Assert.assertEquals("a", consumerConfig.getInterfaceId());
- }
-
-}
\ No newline at end of file
diff --git a/metrics/metrics-lookout/src/test/java/com/alipay/sofa/rpc/module/LookoutModuleTest.java b/metrics/metrics-lookout/src/test/java/com/alipay/sofa/rpc/module/LookoutModuleTest.java
deleted file mode 100644
index 6c2399622..000000000
--- a/metrics/metrics-lookout/src/test/java/com/alipay/sofa/rpc/module/LookoutModuleTest.java
+++ /dev/null
@@ -1,33 +0,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.
- */
-package com.alipay.sofa.rpc.module;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- *
- * @author LiWei.Liangen
- */
-public class LookoutModuleTest {
-
- @Test
- public void testNeedLoad() {
- LookoutModule lookoutModule = new LookoutModule();
- Assert.assertEquals(true, lookoutModule.needLoad());
- }
-}
\ No newline at end of file
diff --git a/metrics/metrics-lookout/src/test/java/com/alipay/sofa/rpc/module/ProviderPubTest.java b/metrics/metrics-lookout/src/test/java/com/alipay/sofa/rpc/module/ProviderPubTest.java
deleted file mode 100644
index dc50469dc..000000000
--- a/metrics/metrics-lookout/src/test/java/com/alipay/sofa/rpc/module/ProviderPubTest.java
+++ /dev/null
@@ -1,68 +0,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.
- */
-package com.alipay.sofa.rpc.module;
-
-import com.alipay.lookout.api.Lookout;
-import com.alipay.lookout.api.NoopRegistry;
-import com.alipay.lookout.api.Registry;
-import com.alipay.lookout.core.DefaultRegistry;
-import com.alipay.lookout.core.InfoWrapper;
-import com.alipay.sofa.rpc.config.ProviderConfig;
-import com.alipay.sofa.rpc.event.EventBus;
-import com.alipay.sofa.rpc.event.ProviderPubEvent;
-import com.alipay.sofa.rpc.metrics.lookout.RpcLookoutId;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * @author zhiyuan.lzy
- */
-public class ProviderPubTest {
-
- @Test
- public void testPubLookout() {
-
- Registry registry = new DefaultRegistry();
- if (Lookout.registry() == NoopRegistry.INSTANCE) {
- Lookout.setRegistry(registry);
- }
- LookoutModule lookoutModule = new LookoutModule();
- Assert.assertEquals(true, lookoutModule.needLoad());
-
- lookoutModule.install();
- ProviderConfig providerConfig = new ProviderConfig();
- providerConfig.setInterfaceId("a");
- EventBus.post(new ProviderPubEvent(providerConfig));
-
- try {
- TimeUnit.SECONDS.sleep(5);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- RpcLookoutId rpcLookoutId = new RpcLookoutId();
- InfoWrapper result = Lookout.registry().get(rpcLookoutId.fetchProviderPubId());
- final Object value = result.value();
- Assert.assertTrue(value instanceof ProviderConfig);
-
- providerConfig = (ProviderConfig) value;
-
- Assert.assertEquals("a", providerConfig.getInterfaceId());
- }
-}
\ No newline at end of file
diff --git a/metrics/pom.xml b/metrics/pom.xml
index e50d83a16..b960206d4 100644
--- a/metrics/pom.xml
+++ b/metrics/pom.xml
@@ -14,7 +14,6 @@
pom
- metrics-lookout
metrics-micrometer
metrics-prometheus
diff --git a/registry/registry-sofa/pom.xml b/registry/registry-sofa/pom.xml
index f1427cb07..122db11bc 100644
--- a/registry/registry-sofa/pom.xml
+++ b/registry/registry-sofa/pom.xml
@@ -47,11 +47,6 @@
commons-pool
-
- com.alipay.sofa.lookout
- lookout-api
-
-
com.alipay.sofa
registry-test
diff --git a/test/test-integration/pom.xml b/test/test-integration/pom.xml
index 5d78a8e48..87aef8ddc 100644
--- a/test/test-integration/pom.xml
+++ b/test/test-integration/pom.xml
@@ -131,11 +131,6 @@
sofa-rpc-log-common-tools
${project.parent.version}
-
- com.alipay.sofa
- sofa-rpc-metrics-lookout
- ${project.parent.version}
-
com.alipay.sofa
sofa-rpc-metrics-micrometer
@@ -256,13 +251,6 @@
-
-
- com.alipay.sofa.lookout
- lookout-core
- test
-
-
org.slf4j
slf4j-log4j12
diff --git a/test/test-integration/src/test/java/com/alipay/sofa/rpc/metrics/lookout/LookoutService.java b/test/test-integration/src/test/java/com/alipay/sofa/rpc/metrics/lookout/LookoutService.java
deleted file mode 100644
index c3501e83a..000000000
--- a/test/test-integration/src/test/java/com/alipay/sofa/rpc/metrics/lookout/LookoutService.java
+++ /dev/null
@@ -1,33 +0,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.
- */
-package com.alipay.sofa.rpc.metrics.lookout;
-
-/**
- *
- * @author LiWei.Liangen
- */
-public interface LookoutService {
-
- String saySync(String string) throws InterruptedException;
-
- String sayFuture(String string) throws InterruptedException;
-
- String sayCallback(String string) throws InterruptedException;
-
- String sayOneway(String string) throws InterruptedException;
-
-}
\ No newline at end of file
diff --git a/test/test-integration/src/test/java/com/alipay/sofa/rpc/metrics/lookout/LookoutServiceImpl.java b/test/test-integration/src/test/java/com/alipay/sofa/rpc/metrics/lookout/LookoutServiceImpl.java
deleted file mode 100644
index 1a51743b7..000000000
--- a/test/test-integration/src/test/java/com/alipay/sofa/rpc/metrics/lookout/LookoutServiceImpl.java
+++ /dev/null
@@ -1,72 +0,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.
- */
-package com.alipay.sofa.rpc.metrics.lookout;
-
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- *
- * @author LiWei.Liangen
- */
-public class LookoutServiceImpl implements LookoutService {
-
- private final AtomicInteger countSync = new AtomicInteger();
- private final AtomicInteger countFuture = new AtomicInteger();
- private final AtomicInteger countCallback = new AtomicInteger();
- private final AtomicInteger countOneway = new AtomicInteger();
-
- @Override
- public String saySync(String string) throws InterruptedException {
- if (countSync.incrementAndGet() == 3) {
- Thread.sleep(3500);
- throw new RuntimeException();
- } else {
- return string;
- }
- }
-
- @Override
- public String sayFuture(String string) throws InterruptedException {
- if (countFuture.incrementAndGet() == 4) {
- Thread.sleep(3500);
- throw new RuntimeException();
- } else {
- return string;
- }
- }
-
- @Override
- public String sayCallback(String string) throws InterruptedException {
- if (countCallback.incrementAndGet() == 5) {
- Thread.sleep(3500);
- throw new RuntimeException();
- } else {
- return string;
- }
- }
-
- @Override
- public String sayOneway(String string) throws InterruptedException {
- if (countOneway.incrementAndGet() == 6) {
- Thread.sleep(3500);
- throw new RuntimeException();
- } else {
- return string;
- }
- }
-
-}
\ No newline at end of file
diff --git a/test/test-integration/src/test/java/com/alipay/sofa/rpc/metrics/lookout/RpcLookoutTest.java b/test/test-integration/src/test/java/com/alipay/sofa/rpc/metrics/lookout/RpcLookoutTest.java
deleted file mode 100644
index 901da949a..000000000
--- a/test/test-integration/src/test/java/com/alipay/sofa/rpc/metrics/lookout/RpcLookoutTest.java
+++ /dev/null
@@ -1,637 +0,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.
- */
-package com.alipay.sofa.rpc.metrics.lookout;
-
-import com.alipay.lookout.api.Id;
-import com.alipay.lookout.api.Lookout;
-import com.alipay.lookout.api.Measurement;
-import com.alipay.lookout.api.Metric;
-import com.alipay.lookout.api.NoopRegistry;
-import com.alipay.lookout.api.Registry;
-import com.alipay.lookout.api.Tag;
-import com.alipay.lookout.core.DefaultRegistry;
-import com.alipay.sofa.rpc.api.future.SofaResponseFuture;
-import com.alipay.sofa.rpc.common.RpcConstants;
-import com.alipay.sofa.rpc.common.utils.StringUtils;
-import com.alipay.sofa.rpc.config.ApplicationConfig;
-import com.alipay.sofa.rpc.config.ConsumerConfig;
-import com.alipay.sofa.rpc.config.MethodConfig;
-import com.alipay.sofa.rpc.config.ProviderConfig;
-import com.alipay.sofa.rpc.config.ServerConfig;
-import com.alipay.sofa.rpc.context.RpcRunningState;
-import com.alipay.sofa.rpc.core.exception.SofaRpcException;
-import com.alipay.sofa.rpc.core.invoke.SofaResponseCallback;
-import com.alipay.sofa.rpc.core.request.RequestBase;
-import com.alipay.sofa.rpc.test.ActivelyDestroyTest;
-import java.util.Iterator;
-import java.util.concurrent.TimeUnit;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-/**
- * @author LiWei.Liangen
- */
-public class RpcLookoutTest extends ActivelyDestroyTest {
-
- static Field corePoolSize;
- static Field maxPoolSize;
- static Field queueSize;
-
- private ServerConfig serverConfig;
-
- private ProviderConfig providerConfig;
-
- private ConsumerConfig consumerConfig;
-
- private LookoutService lookoutService;
-
- private CountSofaResponseCallback onReturn;
-
- @BeforeClass
- public static void beforeClass() {
-
- RpcRunningState.setUnitTestMode(false);
-
- try {
- Class clazz = RpcLookout.class;
- Class[] innerClazzs = clazz.getDeclaredClasses();
- for (Class cls : innerClazzs) {
- if (cls.getName().contains("ThreadPoolConfig")) {
- corePoolSize = cls.getDeclaredField("corePoolSize");
- corePoolSize.setAccessible(true);
-
- maxPoolSize = cls.getDeclaredField("maxPoolSize");
- maxPoolSize.setAccessible(true);
-
- queueSize = cls.getDeclaredField("queueSize");
- queueSize.setAccessible(true);
- }
- }
- } catch (Exception e) {
- LOGGER.error("", e);
- }
-
- Registry registry = new DefaultRegistry();
- final Registry currentRegistry = Lookout.registry();
- if (currentRegistry == NoopRegistry.INSTANCE) {
- Lookout.setRegistry(registry);
- } else {
- //clear all metrics now
- Iterator itar = currentRegistry.iterator();
- while (itar.hasNext()) {
- Metric metric = itar.next();
- Id id = metric.id();
- currentRegistry.removeMetric(id);
-
- }
- }
- }
-
- @AfterClass
- public static void adAfterClass() {
- RpcRunningState.setUnitTestMode(true);
- ActivelyDestroyTest.adAfterClass();
- }
-
- private Metric fetchWithNameAndMethod(String name, String methodName) {
- Registry registry = Lookout.registry();
- for (Metric metric : registry) {
- LOGGER.info("metrics name is " + metric.id() + ",name=" + name + ",methodName=" + methodName);
- if (metric.id().name().equalsIgnoreCase(name)) {
- if (StringUtils.isEmpty(methodName)) {
- return metric;
- }
- if (matchTagFromMetrics(metric, methodName)) {
- return metric;
- }
- }
- }
- return null;
- }
-
- /**
- * invoke
- */
- @Before
- public void before() {
-
- final Registry currentRegistry = Lookout.registry();
- //clear all metrics now
- Iterator itar = currentRegistry.iterator();
- while (itar.hasNext()) {
- Metric metric = itar.next();
- Id id = metric.id();
- currentRegistry.removeMetric(id);
- }
-
- serverConfig = new ServerConfig()
- .setPort(12201)
- .setCoreThreads(30)
- .setMaxThreads(500)
- .setQueues(600)
- .setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT);
-
- providerConfig = new ProviderConfig()
- .setInterfaceId(LookoutService.class.getName())
- .setRef(new LookoutServiceImpl())
- .setServer(serverConfig)
- .setBootstrap("bolt")
- .setRegister(false)
- .setApplication(new ApplicationConfig().setAppName("TestLookOutServer"));
- providerConfig.export();
-
- MethodConfig methodConfigFuture = new MethodConfig()
- .setName("sayFuture")
- .setInvokeType("future");
- onReturn = new CountSofaResponseCallback();
- MethodConfig methodConfigCallback = new MethodConfig()
- .setName("sayCallback")
- .setInvokeType("callback")
- .setOnReturn(onReturn);
- MethodConfig methodConfigOneway = new MethodConfig()
- .setName("sayOneway")
- .setInvokeType("oneway");
- List methodConfigs = new ArrayList();
- methodConfigs.add(methodConfigFuture);
- methodConfigs.add(methodConfigCallback);
- methodConfigs.add(methodConfigOneway);
-
- consumerConfig = new ConsumerConfig()
- .setInterfaceId(LookoutService.class.getName())
- .setProtocol("bolt")
- .setBootstrap("bolt")
- .setMethods(methodConfigs)
- .setTimeout(3000)
- .setRegister(false)
- .setDirectUrl("bolt://127.0.0.1:12201?appName=TestLookOutServer")
- .setApplication(new ApplicationConfig().setAppName("TestLookOutClient"));
- lookoutService = consumerConfig.refer();
-
- }
-
- @After
- public void after() {
-
- final Registry currentRegistry = Lookout.registry();
- //clear all metrics now
- Iterator itar = currentRegistry.iterator();
- while (itar.hasNext()) {
- Metric metric = itar.next();
- Id id = metric.id();
- currentRegistry.removeMetric(id);
- }
-
- if (serverConfig != null) {
- serverConfig.destroy();
- }
- if (providerConfig != null) {
- providerConfig.unExport();
- }
- if (consumerConfig != null) {
- consumerConfig.unRefer();
- }
- }
-
- /**
- * test thread pool config
- *
- * @throws Exception Exception
- */
- @Test
- public void testThreadPoolConfig() throws Exception {
-
- Metric metric = fetchWithNameAndMethod("rpc.bolt.threadpool.config", "");
-
- Collection measurements = metric.measure().measurements();
- assertTrue(measurements.size() == 1);
- for (Measurement measurement : measurements) {
-
- // 判断ThreadPool启动配置
- Object obj = measurement.value();
-
- assertEquals(30, corePoolSize.get(obj));
- assertEquals(500, maxPoolSize.get(obj));
- assertEquals(600, queueSize.get(obj));
- }
- }
-
- /**
- * test thread pool active count
- *
- * @throws Exception Exception
- */
- @Test
- public void testThreadPoolActiveCount() throws Exception {
-
- Metric metric = fetchWithNameAndMethod("rpc.bolt.threadpool.active.count", "");
-
- Collection measurements = metric.measure().measurements();
- assertTrue(measurements.size() == 1);
- for (Measurement measurement : measurements) {
- assertEquals(0, ((Number) measurement.value()).intValue());
- }
- }
-
- /**
- * test thread pool idle count
- */
- @Test
- public void testThreadPoolIdleCount() {
-
- //sync invoke some time
- for (int i = 0; i < 3; i++) {
- try {
- lookoutService.saySync("lookout_sync");
- } catch (Exception e) {
- LOGGER.error("sync error", e);
- }
- }
-
- try {
- TimeUnit.SECONDS.sleep(10);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- Metric metric = fetchWithNameAndMethod("rpc.bolt.threadpool.idle.count", "");
-
- Collection measurements = metric.measure().measurements();
- assertTrue(measurements.size() == 1);
- for (Measurement measurement : measurements) {
- assertEquals(3, ((Number) measurement.value()).intValue());
- }
- }
-
- /**
- * test thread pool queue size
- */
- @Test
- public void testThreadPoolQueueSize() {
-
- Metric metric = fetchWithNameAndMethod("rpc.bolt.threadpool.queue.size", "");
-
- Collection measurements = metric.measure().measurements();
- assertTrue(measurements.size() == 1);
- for (Measurement measurement : measurements) {
- assertEquals(0, ((Number) measurement.value()).intValue());
- }
- }
-
- /**
- * test provider service stats
- */
- @Test
- public void testFutureServiceStats() {
-
- //future
- for (int i = 0; i < 4; i++) {
- try {
- lookoutService.sayFuture("lookout_future");
- SofaResponseFuture.getResponse(3000, true);
- } catch (Exception e) {
- LOGGER.error("future error", e);
- }
- }
-
- try {
- TimeUnit.SECONDS.sleep(10);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- String methodName = "sayFuture";
- Metric metric = fetchWithNameAndMethod("rpc.provider.service.stats", methodName);
- if (metric == null) {
- Assert.fail("no provider metric was found null");
- }
- assertMethod(metric, true, 4, methodName, 0, 0);
-
- Metric consumerMetric = fetchWithNameAndMethod("rpc.consumer.service.stats", methodName);
-
- if (consumerMetric == null) {
- Assert.fail("no consumer metric was found null");
- }
-
- assertMethod(consumerMetric, false, 4, methodName, 1620, 534);
-
- }
-
- /**
- * test provider service stats
- */
- @Test
- public void testCallbackServiceStats() {
-
- //callback
- for (int i = 0; i < 5; i++) {
- try {
- lookoutService.sayCallback("lookout_callback");
- } catch (Exception e) {
- LOGGER.error("callback error", e);
- }
- }
-
- for (int i = 0; i < 10; i++) {
- try {
- TimeUnit.SECONDS.sleep(3);
- } catch (InterruptedException e) {
- }
- if (onReturn.getSize() == 5) {
- break;
- }
- }
- String methodName = "sayCallback";
-
- Metric metric = fetchWithNameAndMethod("rpc.provider.service.stats", methodName);
-
- if (metric == null) {
- Assert.fail("no provider metric was found null");
- }
-
- assertMethod(metric, true, 5, methodName, 0, 0);
-
- Metric consumerMetric = fetchWithNameAndMethod("rpc.consumer.service.stats", methodName);
-
- if (consumerMetric == null) {
- Assert.fail("no consumer eetric was found null");
- }
-
- assertMethod(consumerMetric, false, 5, methodName, 2045, 720);
-
- }
-
- /**
- * test provider service stats
- */
- @Test
- public void testOnewayServiceStats() {
-
- //oneway
- for (int i = 0; i < 6; i++) {
- try {
- lookoutService.sayOneway("lookout_oneway");
- } catch (Exception e) {
- LOGGER.error("oneway error", e);
- }
- }
-
- try {
- TimeUnit.SECONDS.sleep(10);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- String methodName = "sayOneway";
- Metric metric = fetchWithNameAndMethod("rpc.provider.service.stats", methodName);
-
- if (metric == null) {
- Assert.fail("no provider metric was found null");
- }
-
- assertMethod(metric, true, 6, methodName, 0, 0);
-
- Metric consumerMetric = fetchWithNameAndMethod("rpc.consumer.service.stats", methodName);
-
- if (consumerMetric == null) {
- Assert.fail("no consumer metric was found null");
- }
-
- assertMethod(consumerMetric, false, 6, methodName, 2430, 0);
-
- }
-
- /**
- * test provider service stats
- */
- @Test
- public void testSyncServiceStats() {
- System.out.println("start where is the log");
-
- //sync
- for (int i = 0; i < 3; i++) {
- try {
- lookoutService.saySync("lookout_sync");
- System.out.println("lookout_sync invoke success");
- } catch (Exception e) {
- LOGGER.error("sync error", e);
- }
- }
-
- try {
- TimeUnit.SECONDS.sleep(10);
- } catch (InterruptedException e) {
- LOGGER.error("wait InterruptedException", e);
- }
- String methodName = "saySync";
- Metric metric = fetchWithNameAndMethod("rpc.provider.service.stats", methodName);
- Assert.assertNotEquals("metrics is null", null, metric);
-
- if (metric == null) {
- Assert.fail("no provider metric was found null");
- }
- assertMethod(metric, true, 3, methodName, 0, 0);
-
- Metric consumerMetric = fetchWithNameAndMethod("rpc.consumer.service.stats", methodName);
- if (consumerMetric == null) {
- Assert.fail("no consumer metric was found null");
- }
-
- assertMethod(consumerMetric, false, 3, methodName, 1203, 352);
-
- }
-
- /**
- * 通过methodName获取
- *
- * @param metric
- * @param methodName
- * @return
- */
- private boolean matchTagFromMetrics(Metric metric, String methodName) {
- for (Tag tag : metric.id().tags()) {
- if (tag.key().equalsIgnoreCase("method")) {
- String value = tag.value();
- if (StringUtils.equals(methodName, value)) {
- return true;
- }
- }
- }
- return false;
- }
-
- /**
- * assert method
- *
- * @param metric the metric
- * @param isProvider is it the provider
- * @param totalCount the total invoke count
- * @param method the method name
- * @param requestSize the request size
- * @param responseSize the response size
- */
- private void assertMethod(Metric metric, boolean isProvider, int totalCount, String method, int requestSize,
- int responseSize) {
- // tag
- boolean tagAssert = false;
- for (Tag tag : metric.id().tags()) {
- String key = tag.key();
- String value = tag.value();
- LOGGER.info(this.getClass().getName() + ",key=" + key + ",value=" + value);
- if (key.equals("service")) {
- assertEquals("service not equal", LookoutService.class.getCanonicalName() + ":1.0", value);
- tagAssert = true;
- }
- if (key.equals("protocol")) {
- assertEquals("protocol not equal", "bolt", value);
- tagAssert = true;
- }
- if (key.equals("method")) {
- assertEquals("method not equal", method, value);
- tagAssert = true;
- }
- if (isProvider) {
- if (key.equals("app")) {
- assertEquals("app not equal in provider", "TestLookOutServer", value);
- tagAssert = true;
- }
- if (key.equals("caller_app")) {
- assertEquals("caller_app not equal in provider", "TestLookOutClient", value);
- tagAssert = true;
- }
- } else {
- if (key.equals("app")) {
- assertEquals("app not equal in consumer", "TestLookOutClient", value);
- tagAssert = true;
- }
- if (key.equals("target_app")) {
- assertEquals("target_app not equal in consumer", "TestLookOutServer", value);
- tagAssert = true;
- }
- if (key.equals("invoke_type")) {
- assertEquals("invoke_type not equal in consumer", method.substring(3).toLowerCase(), value);
-
- }
- }
- }
- if (!tagAssert) {
- Assert.fail("tag assert not executed");
- }
-
- // invoke info
- Collection measurements = metric.measure().measurements();
- if (isProvider) {
- assertEquals("measurements size is not equal", 6, measurements.size());
- } else {
- if (method.equals("sayOneway")) {
- assertEquals("measurements is not equal in sayOneway", 5, measurements.size());
- } else {
- assertEquals("measurements is not equal in others", 10, measurements.size());
- }
- }
-
- boolean invokeInfoAssert = false;
- for (Measurement measurement : measurements) {
-
- String name = measurement.name();
- int value = ((Long) measurement.value()).intValue();
-
- LOGGER.info(this.getClass().getName() + ",name=" + name + ",value=" + value);
-
- if (name.equals("total_count")) {
- assertEquals("total_count is not equal", totalCount, value);
- invokeInfoAssert = true;
- }
- if (name.equals("total_time.totalTime")) {
- if (method.equals("sayOneway") && !isProvider) {
- assertTrue("totalTime is not equal in consumer", value < 3000);
- } else {
- assertTrue("totalTime is not equal in provider", value > 3000);
- }
- invokeInfoAssert = true;
- }
- if (name.equals("total_time.count")) {
- assertEquals("count is not equal", totalCount, value);
- invokeInfoAssert = true;
- }
- if (name.equals("fail_count")) {
- assertEquals("fail_count is not equal", 1, value);
- invokeInfoAssert = true;
- }
- if (name.equals("fail_time.totalTime")) {
- assertTrue("fail_time.totalTime is not equal", value > 3000);
- invokeInfoAssert = true;
- }
- if (name.equals("fail_time.count")) {
- assertEquals("fail_time.count is not equal", 1, value);
- invokeInfoAssert = true;
- }
- if (!isProvider) {
- if (name.equals("request_size.count")) {
- LOGGER.info("request_size.count,value={},requestSize={},totalCount={}", value, requestSize,
- totalCount);
- assertTrue("request_size.count is smaller than 0", requestSize > 0);
- invokeInfoAssert = true;
- }
- if (name.equals("response_size.count")) {
- LOGGER.info("response_size.count,value={},responseSize={},totalCount={}", value, responseSize,
- totalCount);
- assertTrue("response_size.count is smaller than 0", responseSize > 0);
- invokeInfoAssert = true;
- }
- }
- }
- if (!invokeInfoAssert) {
- Assert.fail("invoke assert not executed");
- }
- }
-
- public static class CountSofaResponseCallback implements SofaResponseCallback {
- private int size = 0;
-
- @Override
- public void onAppResponse(Object appResponse, String methodName, RequestBase request) {
- size++;
- }
-
- @Override
- public void onAppException(Throwable throwable, String methodName, RequestBase request) {
- size++;
- }
-
- @Override
- public void onSofaException(SofaRpcException sofaException, String methodName,
- RequestBase request) {
- size++;
- }
-
- public int getSize() {
- return size;
- }
- }
-}
\ No newline at end of file
diff --git a/test/test-integration/src/test/java/com/alipay/sofa/rpc/server/rest/RestLookoutTest.java b/test/test-integration/src/test/java/com/alipay/sofa/rpc/server/rest/RestLookoutTest.java
deleted file mode 100644
index 62c051623..000000000
--- a/test/test-integration/src/test/java/com/alipay/sofa/rpc/server/rest/RestLookoutTest.java
+++ /dev/null
@@ -1,354 +0,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.
- */
-package com.alipay.sofa.rpc.server.rest;
-
-import com.alipay.lookout.api.Id;
-import com.alipay.lookout.api.Lookout;
-import com.alipay.lookout.api.Measurement;
-import com.alipay.lookout.api.Metric;
-import com.alipay.lookout.api.NoopRegistry;
-import com.alipay.lookout.api.Registry;
-import com.alipay.lookout.api.Tag;
-import com.alipay.lookout.core.DefaultRegistry;
-import com.alipay.sofa.rpc.common.RpcConstants;
-import com.alipay.sofa.rpc.common.utils.StringUtils;
-import com.alipay.sofa.rpc.config.ApplicationConfig;
-import com.alipay.sofa.rpc.config.ConsumerConfig;
-import com.alipay.sofa.rpc.config.JAXRSProviderManager;
-import com.alipay.sofa.rpc.config.ProviderConfig;
-import com.alipay.sofa.rpc.config.ServerConfig;
-import com.alipay.sofa.rpc.context.RpcRunningState;
-import com.alipay.sofa.rpc.context.RpcRuntimeContext;
-import com.alipay.sofa.rpc.test.ActivelyDestroyTest;
-import java.util.Iterator;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import java.util.Collection;
-import java.util.concurrent.TimeUnit;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-/**
- * @author LiWei.Liangen
- */
-public class RestLookoutTest extends ActivelyDestroyTest {
-
- private ServerConfig serverConfig;
-
- private ProviderConfig providerConfig;
-
- private ConsumerConfig consumerConfig;
-
- private RestService helloService;
-
- private Metric fetchWithNameAndMethod(String name, String methodName) {
- Registry registry = Lookout.registry();
- for (Metric metric : registry) {
- LOGGER.info("metrics name is " + metric.id() + ",name=" + name + ",methodName=" + methodName);
- if (metric.id().name().equalsIgnoreCase(name)) {
-
- if (StringUtils.isEmpty(methodName)) {
- return metric;
- }
- if (matchTagFromMetrics(metric, methodName)) {
- return metric;
- }
- }
- }
- return null;
- }
-
- /**
- * 通过methodName获取
- *
- * @param metric
- * @param methodName
- * @return
- */
- private boolean matchTagFromMetrics(Metric metric, String methodName) {
- for (Tag tag : metric.id().tags()) {
- if (tag.key().equalsIgnoreCase("method")) {
- String value = tag.value();
- if (StringUtils.equals(methodName, value)) {
- return true;
- }
- }
- }
- return false;
- }
-
- @BeforeClass
- public static void beforeCurrentClass() {
-
- RpcRunningState.setUnitTestMode(false);
-
- JAXRSProviderManager.registerInternalProviderClass(LookoutRequestFilter.class);
-
- RpcRuntimeContext.putIfAbsent(RpcRuntimeContext.KEY_APPNAME, "TestLookOutServer");
-
- Registry registry = new DefaultRegistry();
- final Registry currentRegistry = Lookout.registry();
- if (currentRegistry == NoopRegistry.INSTANCE) {
- Lookout.setRegistry(registry);
- } else {
- //clear all metrics now
- Iterator itar = currentRegistry.iterator();
- while (itar.hasNext()) {
- Metric metric = itar.next();
- Id id = metric.id();
- currentRegistry.removeMetric(id);
- }
- }
- }
-
- @AfterClass
- public static void afterCurrentClass() {
-
- JAXRSProviderManager.removeInternalProviderClass(LookoutRequestFilter.class);
-
- RpcRunningState.setUnitTestMode(true);
- ActivelyDestroyTest.adAfterClass();
- }
-
- /**
- * invoke
- */
- @Before
- public void beforeMethod() {
-
- // 只有1个线程 执行
- serverConfig = new ServerConfig()
- .setStopTimeout(1000)
- .setPort(8802)
- .setProtocol(RpcConstants.PROTOCOL_TYPE_REST)
- .setContextPath("/xyz");
- //.setQueues(100).setCoreThreads(1).setMaxThreads(2);
-
- // 发布一个服务,每个请求要执行1秒
- ApplicationConfig serverApplication = new ApplicationConfig();
- serverApplication.setAppName("TestLookOutServer");
- providerConfig = new ProviderConfig()
- .setInterfaceId(RestService.class.getName())
- .setRef(new RestServiceImpl())
- .setServer(serverConfig)
- .setBootstrap("rest")
- //.setParameter(RpcConstants.CONFIG_HIDDEN_KEY_WARNING, "false")
- .setRegister(false)
- .setApplication(serverApplication);
- providerConfig.export();
-
- ApplicationConfig clientApplication = new ApplicationConfig();
- clientApplication.setAppName("TestLookOutClient");
- consumerConfig = new ConsumerConfig()
- .setInterfaceId(RestService.class.getName())
- .setDirectUrl(
- "rest://127.0.0.1:8802/xyz?uniqueId=&version=1"
- + ".0&timeout=0&delay=-1&id=rpc-cfg-0&dynamic=true&weight=100&accepts=100000"
- + "&startTime=1523240755024&appName="
- +
- serverApplication.getAppName() + "&pid=22385&language=java&rpcVer=50300")
- .setProtocol("rest")
- .setBootstrap("rest")
- .setTimeout(30000)
- .setConnectionNum(5)
- .setRegister(false)
- .setApplication(clientApplication);
- helloService = consumerConfig.refer();
-
- }
-
- @After
- public void afterMethod() {
-
- //clear all metrics now
- Registry currentRegistry = Lookout.registry();
- Iterator itar = currentRegistry.iterator();
- while (itar.hasNext()) {
- Metric metric = itar.next();
- Id id = metric.id();
- currentRegistry.removeMetric(id);
- }
-
- if (providerConfig != null) {
- providerConfig.unExport();
- }
- if (consumerConfig != null) {
- consumerConfig.unRefer();
- }
- if (serverConfig != null) {
- serverConfig.destroy();
- }
-
- }
-
- /**
- * test provider service stats
- */
- @Test
- public void testServiceStats() {
-
- Assert.assertEquals(helloService.query(11), "hello world !null");
-
- //wait metrics info
- try {
- TimeUnit.SECONDS.sleep(5);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- String methodName = "query";
-
- Metric metric = fetchWithNameAndMethod("rpc.provider.service.stats", methodName);
- if (metric == null) {
- Assert.fail("no provider metric was found null");
- }
-
- assertMethod(metric, true, 1, methodName, 0, 0);
-
- //metrics for consumer
- Metric consumerMetric = fetchWithNameAndMethod("rpc.consumer.service.stats", methodName);
- if (consumerMetric == null) {
- Assert.fail("no consumer metric was found null");
- }
-
- assertMethod(consumerMetric, false, 1, methodName, 1203, 352);
-
- }
-
- /**
- * assert method
- *
- * @param metric the metric
- * @param isProvider is it the provider
- * @param totalCount the total invoke count
- * @param method the method name
- * @param requestSize the request size
- * @param responseSize the response size
- */
- private void assertMethod(Metric metric, boolean isProvider, int totalCount, String method, int requestSize,
- int responseSize) {
- // tag
- boolean tagAssert = false;
- for (Tag tag : metric.id().tags()) {
-
- String key = tag.key();
- String value = tag.value();
- LOGGER.info(this.getClass().getName() + ",key=" + key + ",value=" + value);
- if (key.equals("service")) {
- assertEquals("service not equal", RestService.class.getCanonicalName() + ":1.0", value);
- tagAssert = true;
- }
- if (key.equals("protocol")) {
- assertEquals("protocol not equal", "rest", value);
- tagAssert = true;
- }
- if (key.equals("method")) {
- assertEquals("method not equal", method, value);
- tagAssert = true;
- }
- if (isProvider) {
- if (key.equals("app")) {
- assertEquals("app not equal in provider", "TestLookOutServer", value);
- tagAssert = true;
- }
- if (key.equals("caller_app")) {
- assertEquals("caller_app not equal in provider", "TestLookOutClient", value);
- tagAssert = true;
- }
- } else {
- if (key.equals("app")) {
- assertEquals("app not equal in consumer", "TestLookOutClient", value);
- tagAssert = true;
- }
- if (key.equals("target_app")) {
- assertEquals("target_app not equal in consumer", "TestLookOutServer", value);
- tagAssert = true;
- }
- if (key.equals("invoke_type")) {
- assertEquals("invoke_type not equal in consumer", "sync", value);
-
- }
- }
- }
- if (!tagAssert) {
- Assert.fail("no tag assert");
- }
-
- // invoke info
- Collection measurements = metric.measure().measurements();
- if (isProvider) {
- assertEquals("measurements is not equals in provider", 3, measurements.size());
- } else {
- assertEquals("measurements is not equals in consumer", 4, measurements.size());
- }
-
- boolean invokeInfoAssert = false;
- for (Measurement measurement : measurements) {
- String name = measurement.name();
- int value = ((Long) measurement.value()).intValue();
-
- LOGGER.info(this.getClass().getName() + ",name=" + name + ",value=" + value);
-
- if (name.equals("total_count")) {
- assertEquals("total_count is not equal", totalCount, value);
- invokeInfoAssert = true;
- }
- if (name.equals("total_time.totalTime")) {
- assertTrue("totalTime is not equal", value < 3000);
- invokeInfoAssert = true;
- }
- if (name.equals("total_time.count")) {
- assertEquals("count is not equal", totalCount, value);
- invokeInfoAssert = true;
- }
- if (name.equals("fail_count")) {
- assertEquals("fail_count is not equal", 1, value);
- invokeInfoAssert = true;
- }
- if (name.equals("fail_time.totalTime")) {
- assertTrue("fail_time.totalTime is not equal", value > 3000);
- invokeInfoAssert = true;
- }
- if (name.equals("fail_time.count")) {
- assertEquals("fail_time.count is not equal", 1, value);
- invokeInfoAssert = true;
- }
- if (!isProvider) {
- if (name.equals("request_size.count")) {
- LOGGER.info("request_size.count,value={},requestSize={},totalCount={}", value, requestSize,
- totalCount);
- assertTrue("request_size.count is smaller than 0", requestSize > 0);
- invokeInfoAssert = true;
- }
- if (name.equals("response_size.count")) {
- LOGGER.info("response_size.count,value={},responseSize={},totalCount={}", value, responseSize,
- totalCount);
- assertTrue("response_size.count is smaller than 0", requestSize > 0);
- invokeInfoAssert = true;
- }
- }
- }
- if (!invokeInfoAssert) {
- Assert.fail("no invoke info assert");
- }
- }
-}
\ No newline at end of file