diff --git a/.github/actions/scenarios/backend/memory/action.yml b/.github/actions/scenarios/backend/memory/action.yml index 8575f4bf62..5e83f867bd 100644 --- a/.github/actions/scenarios/backend/memory/action.yml +++ b/.github/actions/scenarios/backend/memory/action.yml @@ -65,7 +65,7 @@ runs: - name: start test shell: bash run: | - python -m unittest ./sermant-integration-tests/scripts/testBackend.py + python -m unittest ./sermant-integration-tests/scripts/test_backend.py - name: stop backend shell: bash run: | diff --git a/.github/actions/scenarios/backend/redis/action.yml b/.github/actions/scenarios/backend/redis/action.yml index 053b521b4d..42ed2f3026 100644 --- a/.github/actions/scenarios/backend/redis/action.yml +++ b/.github/actions/scenarios/backend/redis/action.yml @@ -44,7 +44,7 @@ runs: - name: start test shell: bash run: | - python -m unittest ./sermant-integration-tests/scripts/testBackend.py + python -m unittest ./sermant-integration-tests/scripts/test_backend.py - name: if failure then upload error log uses: actions/upload-artifact@v3 if: ${{ failure() || cancelled() }} diff --git a/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/webhook/feishu/FeiShuHookConfig.java b/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/webhook/feishu/FeiShuHookConfig.java index ec75fa78e7..abe90eda8d 100644 --- a/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/webhook/feishu/FeiShuHookConfig.java +++ b/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/webhook/feishu/FeiShuHookConfig.java @@ -32,6 +32,11 @@ public class FeiShuHookConfig extends WebhookConfigImpl { private FeiShuHookConfig() { } + /** + * 获取飞书的webhook配置 + * + * @return 飞书的webhook配置 + */ public static WebHookConfig getInstance() { return CONFIG; } diff --git a/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/webhook/welink/WelinkHookClient.java b/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/webhook/welink/WelinkHookClient.java index 17ca33c983..b2b522f422 100644 --- a/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/webhook/welink/WelinkHookClient.java +++ b/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/webhook/welink/WelinkHookClient.java @@ -45,7 +45,7 @@ public WelinkHookClient() { * webhook 事件推送 * * @param events 事件信息 - * @return + * @return 推送是否成功 */ @Override public boolean doNotify(List events) { diff --git a/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/webhook/welink/WelinkHookConfig.java b/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/webhook/welink/WelinkHookConfig.java index d56c63849c..15e852d42e 100644 --- a/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/webhook/welink/WelinkHookConfig.java +++ b/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/webhook/welink/WelinkHookConfig.java @@ -32,6 +32,11 @@ public class WelinkHookConfig extends WebhookConfigImpl { private WelinkHookConfig() { } + /** + * 获取Welink的webhook配置 + * + * @return Welink的webhook配置 + */ public static WebHookConfig getInstance() { return CONFIG; } diff --git a/sermant-injector/src/main/java/com/huaweicloud/sermant/injection/controller/SermantInjectorController.java b/sermant-injector/src/main/java/com/huaweicloud/sermant/injection/controller/SermantInjectorController.java index 75242ac32f..444625d395 100644 --- a/sermant-injector/src/main/java/com/huaweicloud/sermant/injection/controller/SermantInjectorController.java +++ b/sermant-injector/src/main/java/com/huaweicloud/sermant/injection/controller/SermantInjectorController.java @@ -295,7 +295,10 @@ private Optional inject(ObjectNode body) { * env.sermant.io/[key2]:[value2] * 则在环境变量map中添加 key1:value1 和 key2:value2,共两个环境变量 * 本函数本真不强制是否使用labels还是annotations,只需要srcMap代表label/annotations下的map即可。 - */ + * + * @param srcMap 源环境变量kv + * @param tgtEnv 处理后的环境变量kv + */ private void setEnvByMap(JsonNode srcMap, Map tgtEnv) { Iterator labelIter = srcMap.fieldNames(); int prefixLength = SERMANT_ENV_PREFIX.length(); @@ -363,7 +366,7 @@ private void injectVolumes(ArrayNode arrayNode, JsonNode specPath) { } private void injectLifecycle(ArrayNode arrayNode, Map env, JsonNode containerNode, - String containerPath) { + String containerPath) { boolean enableSpring = getNotEmptyValue(env, ENABLE_SPRING_KEY, true, Boolean::parseBoolean); boolean enableGraceShutDown = getNotEmptyValue(env, ENABLE_GRACE_SHUTDOWN_KEY, true, Boolean::parseBoolean); @@ -401,7 +404,7 @@ private void injectLifecycle(ArrayNode arrayNode, Map env, JsonN } private void injectReadinessProbe(ArrayNode arrayNode, Map env, JsonNode containerNode, - String containerPath) { + String containerPath) { int periodSeconds = getNotEmptyValue(env, K8S_READINESS_WAIT_TIME_KEY, 1, Integer::parseInt); boolean enableSpring = getNotEmptyValue(env, ENABLE_SPRING_KEY, true, Boolean::parseBoolean); boolean enableHealthCheck = getNotEmptyValue(env, ENABLE_HEALTH_CHECK_KEY, false, Boolean::parseBoolean); @@ -428,7 +431,7 @@ private void injectReadinessProbe(ArrayNode arrayNode, Map env, } private void injectEnvFrom(ArrayNode arrayNode, Map env, JsonNode containerNode, - String containerPath) { + String containerPath) { String configMap = getNotEmptyValue(env, ENV_CONFIG_MAP_REF_KEY, envFrom, value -> value); if (!StringUtils.hasText(configMap)) { return; @@ -444,7 +447,7 @@ private void injectEnvFrom(ArrayNode arrayNode, Map env, JsonNod } private void injectEnv(ArrayNode arrayNode, Map env, JsonNode containerNode, String containerPath, - Map annotationEnv) { + Map annotationEnv) { // 覆盖容器的env节点 ObjectNode envNode = arrayNode.addObject(); envNode.put(JSON_OPERATION_KEY, JSON_OPERATION_ADD); @@ -508,7 +511,7 @@ private String getJavaToolOptions(String injectOptions, String originOptions) { } private void injectVolumeMounts(ArrayNode arrayNode, Map env, JsonNode containerNode, - String containerPath) { + String containerPath) { // 向容器新增volumeMounts节点 ObjectNode containerVolumeNode = putOrAddObject(arrayNode, containerNode, VOLUME_MOUNTS_PATH, containerPath + VOLUME_MOUNTS_PATH); diff --git a/sermant-integration-tests/scripts/AgentLoader.java b/sermant-integration-tests/scripts/AgentLoader.java index 033fe39ecd..217c86f268 100644 --- a/sermant-integration-tests/scripts/AgentLoader.java +++ b/sermant-integration-tests/scripts/AgentLoader.java @@ -14,6 +14,8 @@ * limitations under the License. */ +package com.huaweicloud.sermant.script; + import com.sun.tools.attach.AgentInitializationException; import com.sun.tools.attach.AgentLoadException; import com.sun.tools.attach.AttachNotSupportedException; @@ -22,6 +24,8 @@ import java.io.IOException; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; /** * AgentLoader mainClass @@ -30,6 +34,8 @@ * @since 2023-09-26 */ public class AgentLoader { + private static Logger logger = Logger.getLogger("com.huaweicloud.sermant.script.AgentLoader"); + private AgentLoader() { } @@ -58,8 +64,8 @@ public static void main(String[] args) { virtualMachine.detach(); } } - } catch (AgentInitializationException | IOException | AgentLoadException | AttachNotSupportedException ignore) { - // ignore + } catch (AgentInitializationException | IOException | AgentLoadException | AttachNotSupportedException e) { + logger.log(Level.WARNING, "Load sermant agent fail, exception", e); } } } diff --git a/sermant-integration-tests/scripts/testBackend.py b/sermant-integration-tests/scripts/test_backend.py similarity index 100% rename from sermant-integration-tests/scripts/testBackend.py rename to sermant-integration-tests/scripts/test_backend.py diff --git a/sermant-plugins/sermant-dynamic-config/dynamic-config-plugin/src/main/java/com/huawei/dynamic/config/DefaultDynamicConfigSource.java b/sermant-plugins/sermant-dynamic-config/dynamic-config-plugin/src/main/java/com/huawei/dynamic/config/DefaultDynamicConfigSource.java index 94a99238e2..f1fc1ff0b4 100644 --- a/sermant-plugins/sermant-dynamic-config/dynamic-config-plugin/src/main/java/com/huawei/dynamic/config/DefaultDynamicConfigSource.java +++ b/sermant-plugins/sermant-dynamic-config/dynamic-config-plugin/src/main/java/com/huawei/dynamic/config/DefaultDynamicConfigSource.java @@ -97,7 +97,7 @@ private void updateConfigSources() { private void updateAllConfigSources(Map changeConfigs, String eventKey) { final Map configMap = allConfigSources - .getOrDefault(eventKey, new HashMap<>(changeConfigs.size())); + .getOrDefault(eventKey, new HashMap<>(changeConfigs.size())); configMap.putAll(changeConfigs); allConfigSources.put(eventKey, configMap); sortedKeys.removeIf(timestampKey -> timestampKey.key.equals(eventKey)); @@ -126,6 +126,16 @@ public int compareTo(TimestampKey target) { } return Long.compare(this.timestamp, target.timestamp); } + + @Override + public boolean equals(Object obj) { + return super.equals(obj); + } + + @Override + public int hashCode() { + return super.hashCode(); + } } @Override diff --git a/sermant-plugins/sermant-dynamic-config/dynamic-config-plugin/src/main/java/com/huawei/dynamic/config/closer/NacosConfigCenterCloser.java b/sermant-plugins/sermant-dynamic-config/dynamic-config-plugin/src/main/java/com/huawei/dynamic/config/closer/NacosConfigCenterCloser.java index d206a114de..608dace5b1 100644 --- a/sermant-plugins/sermant-dynamic-config/dynamic-config-plugin/src/main/java/com/huawei/dynamic/config/closer/NacosConfigCenterCloser.java +++ b/sermant-plugins/sermant-dynamic-config/dynamic-config-plugin/src/main/java/com/huawei/dynamic/config/closer/NacosConfigCenterCloser.java @@ -83,6 +83,6 @@ private void shutdownConfigService() { return; } final Optional configService = ReflectUtils.getFieldValue(nacosContextRefresher, "configService"); - configService.ifPresent(o -> ReflectUtils.invokeMethod(o, "shutDown", null, null)); + configService.ifPresent(object -> ReflectUtils.invokeMethod(object, "shutDown", null, null)); } } diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/core/match/MatchedCache.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/core/match/MatchedCache.java index d71918c9e8..37264cb6c5 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/core/match/MatchedCache.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/core/match/MatchedCache.java @@ -42,7 +42,7 @@ * @since 2022-07-21 */ public class MatchedCache { - private Cache> cache; + private volatile Cache> cache; /** * 构造器 diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/core/rule/AbstractRule.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/core/rule/AbstractRule.java index 11c1cc78fe..144fd403bd 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/core/rule/AbstractRule.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/core/rule/AbstractRule.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (C) 2021-2022 Huawei Technologies Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,6 +48,16 @@ public abstract class AbstractRule extends Configurable implements Rule, Compara */ protected int order = 0; + @Override + public boolean equals(Object obj) { + return super.equals(obj); + } + + @Override + public int hashCode() { + return super.hashCode(); + } + @Override public int compareTo(AbstractRule target) { return order - target.order; @@ -69,7 +79,7 @@ public boolean isInValid() { /** * 字符串转long类型毫秒 * - * @param time 时间字符串 1000 -> 1000毫秒 -1000 -> 负1000毫秒 1000S(s) 1000秒 -> 1000000毫秒 + * @param time 时间字符串 1000->1000毫秒 -1000->负1000毫秒 1000S(s) 1000秒->1000000毫秒 * @param defaultValue 默认值 * @return 转换值 * @throws IllegalArgumentException 参数不合法抛出 @@ -100,7 +110,7 @@ private Optional tryParseWithDuration(String time) { return Optional.of(Duration.parse(DURATION_PREFIX + time)); } catch (DateTimeException ex) { LoggerFactory.getLogger().warning(String.format(Locale.ENGLISH, - "Parsed time [%s] to duration failed!", time)); + "Parsed time [%s] to duration failed!", time)); } return Optional.empty(); } diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/core/rule/fault/AbstractFault.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/core/rule/fault/AbstractFault.java index 5a756caf57..333255d38a 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/core/rule/fault/AbstractFault.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/core/rule/fault/AbstractFault.java @@ -71,6 +71,7 @@ private boolean isNeedFault(long curReqCount) { /** * 朴素贝叶斯概率模型 * + * @param curReqCount 当前请求数量 * @return 核对触发概率 */ private boolean checkPercent(long curReqCount) { diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/entity/HttpRequestEntity.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/entity/HttpRequestEntity.java index 9655c1c0b8..35b777539d 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/entity/HttpRequestEntity.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/entity/HttpRequestEntity.java @@ -39,12 +39,6 @@ public class HttpRequestEntity extends AbstractRequestEntity { private String method; - /** - * 空请求构造 - */ - public HttpRequestEntity() { - } - private void setPathInfo(String pathInfo) { this.pathInfo = pathInfo; } diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/handler/retry/AbstractRetry.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/handler/retry/AbstractRetry.java index 236954a98b..9571f52fc5 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/handler/retry/AbstractRetry.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/handler/retry/AbstractRetry.java @@ -36,6 +36,9 @@ * @since 2022-02-10 */ public abstract class AbstractRetry extends ReflectMethodCacheSupport implements Retry { + /** + * 重试异常类 + */ protected Class[] classes; /** @@ -54,7 +57,7 @@ protected final Class[] findClass(String[] classNames) { result.add(Class.forName(className, false, Thread.currentThread().getContextClassLoader())); } catch (ClassNotFoundException exception) { LoggerFactory.getLogger().info(String.format(Locale.ENGLISH, - "Can not find retry exception class %s", className)); + "Can not find retry exception class %s", className)); } } return result.toArray(new Class[0]); diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/handler/retry/RetryContext.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/handler/retry/RetryContext.java index dcd0bfb867..cc453f834f 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/handler/retry/RetryContext.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/com/huawei/flowcontrol/common/handler/retry/RetryContext.java @@ -42,6 +42,11 @@ public enum RetryContext { private final ThreadLocal policyThreadLocal = new ThreadLocal<>(); + /** + * 获取当前线程的重试机制 + * + * @return 当前线程的重试机制 + */ public Retry getRetry() { return retryThreadLocal.get(); } @@ -85,6 +90,11 @@ public boolean isPolicyNeedRetry() { return retryPolicy.isRetry() && retryPolicy.needRetry(); } + /** + * 获取当前线程的重试策略 + * + * @return 当前线程的重试策略 + */ public RetryPolicy getRetryPolicy() { return policyThreadLocal.get(); } diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/DispatcherServletInterceptor.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/DispatcherServletInterceptor.java index e3d47021f5..62ce0c0970 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/DispatcherServletInterceptor.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/DispatcherServletInterceptor.java @@ -53,10 +53,11 @@ private Optional convertToHttpEntity(HttpServletRequest reque if (request == null) { return Optional.empty(); } + String uri = request.getRequestURI(); return Optional.of(new HttpRequestEntity.Builder() .setRequestType(RequestType.SERVER) .setPathInfo(request.getPathInfo()) - .setServletPath(request.getRequestURI()) + .setServletPath(uri) .setHeaders(getHeaders(request)) .setMethod(request.getMethod()) .setServiceName(request.getHeader(ConfigConst.FLOW_REMOTE_SERVICE_NAME_HEADER_KEY)) diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/config/AlibabaDubboConfigInterceptor.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/config/AlibabaDubboConfigInterceptor.java index bba610a930..34d9155d3e 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/config/AlibabaDubboConfigInterceptor.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/config/AlibabaDubboConfigInterceptor.java @@ -16,9 +16,9 @@ package com.huawei.flowcontrol.config; +import com.huawei.flowcontrol.common.config.FlowControlConfig; import com.huawei.flowcontrol.common.core.constants.CseConstants; import com.huawei.flowcontrol.common.entity.FlowControlServiceMeta; -import com.huawei.flowcontrol.common.config.FlowControlConfig; import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext; import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor; @@ -34,6 +34,10 @@ public class AlibabaDubboConfigInterceptor extends AbstractInterceptor { /** * 此处代码与{@link ApacheDubboConfigInterceptor}相同 *

由于使用的是不同的权限定名框架,因此

不可抽出,且不可放在除拦截器之外的类执行该段逻辑(类加载器问题)

+ * + * @param context 执行上下文 + * @return 执行上下文 + * @throws Exception 执行异常 */ @Override public ExecuteContext before(ExecuteContext context) throws Exception { @@ -43,26 +47,26 @@ public ExecuteContext before(ExecuteContext context) throws Exception { return context; } FlowControlServiceMeta.getInstance().setVersion(com.alibaba.dubbo.common.utils.ConfigUtils.getProperty( - CseConstants.KEY_DUBBO_VERSION, - CseConstants.DEFAULT_DUBBO_VERSION)); + CseConstants.KEY_DUBBO_VERSION, + CseConstants.DEFAULT_DUBBO_VERSION)); FlowControlServiceMeta.getInstance().setProject(com.alibaba.dubbo.common.utils.ConfigUtils.getProperty( - CseConstants.KEY_DUBBO_KIE_PROJECT, - CseConstants.DEFAULT_PROJECT)); + CseConstants.KEY_DUBBO_KIE_PROJECT, + CseConstants.DEFAULT_PROJECT)); FlowControlServiceMeta.getInstance().setServiceName(com.alibaba.dubbo.common.utils.ConfigUtils.getProperty( - CseConstants.KEY_DUBBO_SERVICE_NAME, - CseConstants.DEFAULT_DUBBO_SERVICE_NAME)); + CseConstants.KEY_DUBBO_SERVICE_NAME, + CseConstants.DEFAULT_DUBBO_SERVICE_NAME)); FlowControlServiceMeta.getInstance().setEnvironment(com.alibaba.dubbo.common.utils.ConfigUtils.getProperty( - CseConstants.KEY_DUBBO_ENVIRONMENT, - CseConstants.DEFAULT_DUBBO_ENVIRONMENT)); + CseConstants.KEY_DUBBO_ENVIRONMENT, + CseConstants.DEFAULT_DUBBO_ENVIRONMENT)); FlowControlServiceMeta.getInstance().setApp(com.alibaba.dubbo.common.utils.ConfigUtils.getProperty( - CseConstants.KEY_DUBBO_APP_NAME, - CseConstants.DEFAULT_DUBBO_APP_NAME)); + CseConstants.KEY_DUBBO_APP_NAME, + CseConstants.DEFAULT_DUBBO_APP_NAME)); FlowControlServiceMeta.getInstance().setCustomLabel(com.alibaba.dubbo.common.utils.ConfigUtils.getProperty( - CseConstants.KEY_DUBBO_CUSTOM_LABEL, - CseConstants.DEFAULT_CUSTOM_LABEL)); + CseConstants.KEY_DUBBO_CUSTOM_LABEL, + CseConstants.DEFAULT_CUSTOM_LABEL)); FlowControlServiceMeta.getInstance().setCustomLabelValue(com.alibaba.dubbo.common.utils.ConfigUtils.getProperty( - CseConstants.KEY_DUBBO_CUSTOM_LABEL_VALUE, - CseConstants.DEFAULT_CUSTOM_LABEL_VALUE)); + CseConstants.KEY_DUBBO_CUSTOM_LABEL_VALUE, + CseConstants.DEFAULT_CUSTOM_LABEL_VALUE)); return context; } diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/inject/DefaultClientHttpResponse.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/inject/DefaultClientHttpResponse.java index e5bb190aed..c0f920a68d 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/inject/DefaultClientHttpResponse.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/inject/DefaultClientHttpResponse.java @@ -20,6 +20,8 @@ import com.huawei.flowcontrol.common.entity.FlowControlResponse; import com.huawei.flowcontrol.common.entity.FlowControlResult; +import com.huaweicloud.sermant.core.common.LoggerFactory; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.client.ClientHttpResponse; @@ -28,6 +30,8 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.util.logging.Level; +import java.util.logging.Logger; /** * 默认响应, 在接管RestTemplate请求,触发治理策略后的默认响应 @@ -36,6 +40,8 @@ * @since 2022-07-21 */ public class DefaultClientHttpResponse implements ClientHttpResponse { + private static final Logger LOGGER = LoggerFactory.getLogger(); + private final FlowControlResult flowControlResult; private final String contentType; @@ -80,8 +86,8 @@ public void close() { if (responseStream != null) { try { responseStream.close(); - } catch (IOException ignored) { - // ignored + } catch (IOException e) { + LOGGER.log(Level.WARNING, "Close exception: ", e.getMessage()); } } } diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/retry/ApacheDubboInvokerInterceptor.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/retry/ApacheDubboInvokerInterceptor.java index e7c28f4572..a8bbeabb4c 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/retry/ApacheDubboInvokerInterceptor.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/retry/ApacheDubboInvokerInterceptor.java @@ -65,7 +65,7 @@ public class ApacheDubboInvokerInterceptor extends InterceptorSupporter { * 黑名单,该名单内的类不拦截 */ private final List backList = Collections - .singletonList("org.apache.dubbo.rpc.cluster.support.registry.ZoneAwareClusterInvoker"); + .singletonList("org.apache.dubbo.rpc.cluster.support.registry.ZoneAwareClusterInvoker"); /** * 转换apache dubbo 注意,该方法不可抽出,由于宿主依赖仅可由该拦截器加载,因此抽出会导致找不到类 @@ -100,14 +100,15 @@ private DubboRequestEntity convertToApacheDubboEntity(Invocation invocation) { *

不可抽出

* 由于两个框架类权限定名不同, 且仅当当前的拦截器才可加载宿主类 * - * @param obj 增强对象 + * @param obj 增强对象 * @param allArguments 方法参数 - * @param ret 响应结果 - * @param isNeedThrow 是否需抛出异常 + * @param ret 响应结果 + * @param isNeedThrow 是否需抛出异常 + * @param isRetry 是否需要重试 * @return 方法调用器 */ private Object invokeRetryMethod(Object obj, Object[] allArguments, Object ret, boolean isNeedThrow, - boolean isRetry) { + boolean isRetry) { try { if (obj instanceof AbstractClusterInvoker) { final Invocation invocation = (Invocation) allArguments[0]; @@ -116,7 +117,7 @@ private Object invokeRetryMethod(Object obj, Object[] allArguments, Object ret, final Optional selectOption = getMethodSelect(); if (!checkInvokersOption.isPresent() || !selectOption.isPresent()) { LOGGER.warning(String.format(Locale.ENGLISH, "It does not support retry for class %s", - obj.getClass().getCanonicalName())); + obj.getClass().getCanonicalName())); return ret; } if (isRetry) { @@ -129,7 +130,7 @@ private Object invokeRetryMethod(Object obj, Object[] allArguments, Object ret, // 选择invoker final Invoker invoke = (Invoker) selectOption.get() - .invoke(obj, loadBalance, invocation, invokers, null); + .invoke(obj, loadBalance, invocation, invokers, null); // 执行调用 final Result result = invoke.invoke(invocation); @@ -157,7 +158,7 @@ private Optional getMethodSelect() { return getInvokerMethod("select", func -> { try { final Method method = AbstractClusterInvoker.class - .getDeclaredMethod("select", LoadBalance.class, Invocation.class, List.class, List.class); + .getDeclaredMethod("select", LoadBalance.class, Invocation.class, List.class, List.class); method.setAccessible(true); return method; } catch (NoSuchMethodException ex) { @@ -171,7 +172,7 @@ private Optional getMethodCheckInvokers() { return getInvokerMethod("checkInvokers", func -> { try { final Method method = AbstractClusterInvoker.class - .getDeclaredMethod("checkInvokers", List.class, Invocation.class); + .getDeclaredMethod("checkInvokers", List.class, Invocation.class); method.setAccessible(true); return method; } catch (NoSuchMethodException ex) { @@ -202,12 +203,12 @@ protected final ExecuteContext doAfter(ExecuteContext context) { RetryContext.INSTANCE.markRetry(retry); result = invokeRetryMethod(context.getObject(), allArguments, result, false, false); final List handlers = getRetryHandler() - .getHandlers(convertToApacheDubboEntity(invocation)); + .getHandlers(convertToApacheDubboEntity(invocation)); if (!handlers.isEmpty() && needRetry(handlers.get(0), result, ((AsyncRpcResult) result).getException())) { RetryContext.INSTANCE.markRetry(retry); result = handlers.get(0) - .executeCheckedSupplier(() -> invokeRetryMethod(context.getObject(), allArguments, - context.getResult(), true, true)); + .executeCheckedSupplier(() -> invokeRetryMethod(context.getObject(), allArguments, + context.getResult(), true, true)); invocation.getAttachments().remove(RETRY_KEY); } } catch (Throwable throwable) { @@ -228,7 +229,7 @@ private Object buildErrorResponse(Throwable throwable, Invocation invocation) { } result = AsyncRpcResult.newDefaultAsyncResult(realException, invocation); LOGGER.warning(String.format(Locale.ENGLISH, "Invoking method [%s] failed, reason : %s", - invocation.getMethodName(), realException.getMessage())); + invocation.getMethodName(), realException.getMessage())); return result; } diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/retry/FeignRequestInterceptor.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/retry/FeignRequestInterceptor.java index 5ed607980c..eb50cbaaea 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/retry/FeignRequestInterceptor.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/retry/FeignRequestInterceptor.java @@ -47,6 +47,7 @@ import java.util.Locale; import java.util.Optional; import java.util.function.Supplier; +import java.util.logging.Level; import java.util.logging.Logger; /** @@ -85,8 +86,8 @@ private Optional convertToHttpEntity(Request request) { .setMethod(request.method()) .setServiceName(url.getHost()) .build()); - } catch (MalformedURLException ignored) { - // ignored + } catch (MalformedURLException e) { + LOGGER.log(Level.WARNING, "Fail to convert Request to HttpRequestEntity, exception", e); } return Optional.of(new HttpRequestEntity()); } diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/retry/cluster/AlibabaDubboClusterInvoker.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/retry/cluster/AlibabaDubboClusterInvoker.java index c279772767..6a53ca9e44 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/retry/cluster/AlibabaDubboClusterInvoker.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/retry/cluster/AlibabaDubboClusterInvoker.java @@ -164,6 +164,7 @@ private void checkThrowEx(Result result) throws Throwable { * 转换apache dubbo 注意,该方法不可抽出,由于宿主依赖仅可由该拦截器加载,因此抽出会导致找不到类 * * @param invocation 调用信息 + * @param invoker 调用者 * @return DubboRequestEntity */ private DubboRequestEntity convertToAlibabaDubboEntity(Invocation invocation, Invoker invoker) { diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/retry/cluster/ApacheDubboClusterInvoker.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/retry/cluster/ApacheDubboClusterInvoker.java index f704b83358..63cf3ace48 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/retry/cluster/ApacheDubboClusterInvoker.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/retry/cluster/ApacheDubboClusterInvoker.java @@ -174,6 +174,7 @@ private void checkThrowEx(Result result) throws Throwable { * 转换apache dubbo 注意,该方法不可抽出,由于宿主依赖仅可由该拦截器加载,因此抽出会导致找不到类 * * @param invocation 调用信息 + * @param invoker 调用者 * @return DubboRequestEntity */ private DubboRequestEntity convertToApacheDubboEntity(Invocation invocation, Invoker invoker) { diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/service/InterceptorSupporter.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/service/InterceptorSupporter.java index 23cb2cb86e..d477bec8a5 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/service/InterceptorSupporter.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/com/huawei/flowcontrol/service/InterceptorSupporter.java @@ -56,16 +56,28 @@ public abstract class InterceptorSupporter extends ReflectMethodCacheSupport imp */ protected static final String RETRY_KEY = "$$$$RETRY$$$"; + /** + * 标记当前请求重试中 + */ protected static final String RETRY_VALUE = "$$$$RETRY_VALUE$$$"; + /** + * Apache Dubbo的Cluster类名 + */ protected static final String APACHE_DUBBO_CLUSTER_CLASS_NAME = "org.apache.dubbo.rpc.cluster.Cluster"; + /** + * Alibaba Dubbo的Cluster类名 + */ protected static final String ALIBABA_DUBBO_CLUSTER_CLASS_NAME = "com.alibaba.dubbo.rpc.cluster.Cluster"; private static final String REFUSE_REPLACE_INVOKER = "close"; private static final Logger LOGGER = LoggerFactory.getLogger(); + /** + * 流控配置 + */ protected final FlowControlConfig flowControlConfig; private final ReentrantLock lock = new ReentrantLock(); @@ -150,6 +162,7 @@ protected final HttpService chooseHttpService() { * @param allArguments 方法参数 * @param result 默认结果 * @return 方法 + * @throws InvokerWrapperException 调用包装异常 */ protected final Supplier createRetryFunc(Object obj, Method method, Object[] allArguments, Object result) { return () -> { @@ -182,8 +195,8 @@ protected final boolean needRetry(io.github.resilience4j.retry.Retry retry, Obje try { // 按照第一次等待时间等待 Thread.sleep(interval); - } catch (InterruptedException ignored) { - // ignored + } catch (InterruptedException e) { + LOGGER.log(Level.WARNING, "Interruption error:", e); } } return isNeedRetry; diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-service/src/main/java/com/huawei/flowcontrol/res4j/chain/AbstractChainHandler.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-service/src/main/java/com/huawei/flowcontrol/res4j/chain/AbstractChainHandler.java index e9c3d7c5ed..4e4fe46b9a 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-service/src/main/java/com/huawei/flowcontrol/res4j/chain/AbstractChainHandler.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-service/src/main/java/com/huawei/flowcontrol/res4j/chain/AbstractChainHandler.java @@ -34,6 +34,7 @@ public abstract class AbstractChainHandler implements RequestHandler, Comparable private AbstractChainHandler next; + @Override public void onBefore(RequestContext context, Set businessNames) { AbstractChainHandler cur = getNextHandler(context, businessNames); @@ -89,7 +90,7 @@ private String skipCacheKey(AbstractChainHandler tmp) { // 初始化StringBuilder的长度是为了性能 StringBuilder sb = - new StringBuilder(className.length() + direct.name().length() + EXTRA_LENGTH_FOR_METHOD_CACHE_KEY); + new StringBuilder(className.length() + direct.name().length() + EXTRA_LENGTH_FOR_METHOD_CACHE_KEY); sb.append(direct).append("_").append(className).append("_skip_flag"); return sb.toString(); } @@ -119,6 +120,16 @@ public int compareTo(AbstractChainHandler handler) { return getOrder() - handler.getOrder(); } + @Override + public boolean equals(Object obj) { + return super.equals(obj); + } + + @Override + public int hashCode() { + return super.hashCode(); + } + public void setNext(AbstractChainHandler processor) { this.next = processor; } diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-service/src/main/java/com/huawei/flowcontrol/res4j/chain/handler/BulkheadRequestHandler.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-service/src/main/java/com/huawei/flowcontrol/res4j/chain/handler/BulkheadRequestHandler.java index 9f3850a23d..d7f14de168 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-service/src/main/java/com/huawei/flowcontrol/res4j/chain/handler/BulkheadRequestHandler.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-service/src/main/java/com/huawei/flowcontrol/res4j/chain/handler/BulkheadRequestHandler.java @@ -68,6 +68,7 @@ public void onResult(RequestContext context, Set businessNames, Object r /** * 是否触发隔离仓策略 * + * @param sourceName 线程变量的名称 * @return 若触发隔离仓则无需释放资源 */ private boolean isOccurBulkheadLimit(String sourceName) { diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-service/src/main/java/com/huawei/flowcontrol/res4j/handler/CircuitBreakerHandler.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-service/src/main/java/com/huawei/flowcontrol/res4j/handler/CircuitBreakerHandler.java index 99b9b11d1b..83a000c7ca 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-service/src/main/java/com/huawei/flowcontrol/res4j/handler/CircuitBreakerHandler.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-service/src/main/java/com/huawei/flowcontrol/res4j/handler/CircuitBreakerHandler.java @@ -68,7 +68,7 @@ protected final Optional createProcessor(String businessName, Ci */ private static void addEventConsumers(CircuitBreaker circuitBreaker) { Map monitors = ServiceCollectorService.MONITORS; - MetricEntity metricEntity = monitors.computeIfAbsent(circuitBreaker.getName(), s -> new MetricEntity()); + MetricEntity metricEntity = monitors.computeIfAbsent(circuitBreaker.getName(), str -> new MetricEntity()); metricEntity.setName(circuitBreaker.getName()); circuitBreaker.getEventPublisher().onError(event -> { metricEntity.getFailedFuseRequest().getAndIncrement(); diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-service/src/main/java/com/huawei/flowcontrol/res4j/windows/SystemStatus.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-service/src/main/java/com/huawei/flowcontrol/res4j/windows/SystemStatus.java index 6e11de6598..dd0d2440fb 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-service/src/main/java/com/huawei/flowcontrol/res4j/windows/SystemStatus.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-service/src/main/java/com/huawei/flowcontrol/res4j/windows/SystemStatus.java @@ -40,12 +40,12 @@ public class SystemStatus { /** * qps */ - private double qps = 0; + private double qps = 0d; /** * 平均响应时间 */ - private double aveRt = 0; + private double aveRt = 0d; /** * 最小响应时间 diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-service/src/main/java/com/huawei/flowcontrol/res4j/windows/WindowsArray.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-service/src/main/java/com/huawei/flowcontrol/res4j/windows/WindowsArray.java index fa9c089081..83a91b4f72 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-service/src/main/java/com/huawei/flowcontrol/res4j/windows/WindowsArray.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-service/src/main/java/com/huawei/flowcontrol/res4j/windows/WindowsArray.java @@ -51,8 +51,8 @@ public enum WindowsArray { */ public void initWindowsArray() { windowsArray = new AtomicReferenceArray<>(DEFAULT_WINDOWS_SIZE); - Stream.iterate(0, n -> n + 1).limit(DEFAULT_WINDOWS_SIZE) - .forEach(a -> windowsArray.set(a, new WindowsBucket())); + Stream.iterate(0, num -> num + 1).limit(DEFAULT_WINDOWS_SIZE) + .forEach(index -> windowsArray.set(index, new WindowsBucket())); } /** diff --git a/sermant-plugins/sermant-loadbalancer/loadbalancer-common/src/main/java/com/huaweicloud/loadbalancer/config/RibbonLoadbalancerType.java b/sermant-plugins/sermant-loadbalancer/loadbalancer-common/src/main/java/com/huaweicloud/loadbalancer/config/RibbonLoadbalancerType.java index bd955ec4d8..a1c2036ede 100644 --- a/sermant-plugins/sermant-loadbalancer/loadbalancer-common/src/main/java/com/huaweicloud/loadbalancer/config/RibbonLoadbalancerType.java +++ b/sermant-plugins/sermant-loadbalancer/loadbalancer-common/src/main/java/com/huaweicloud/loadbalancer/config/RibbonLoadbalancerType.java @@ -53,6 +53,8 @@ public enum RibbonLoadbalancerType { /** * 响应时间加权重策略 + * + * @deprecated Use {@link #WEIGHTED_RESPONSE_TIME} instead. */ @Deprecated RESPONSE_TIME_WEIGHTED("ResponseTimeWeighted", "com.netflix.loadbalancer.ResponseTimeWeightedRule"), diff --git a/sermant-plugins/sermant-loadbalancer/loadbalancer-common/src/main/java/com/huaweicloud/loadbalancer/rule/LoadbalancerRuleResolver.java b/sermant-plugins/sermant-loadbalancer/loadbalancer-common/src/main/java/com/huaweicloud/loadbalancer/rule/LoadbalancerRuleResolver.java index 6bb7995583..9ff925f8c5 100644 --- a/sermant-plugins/sermant-loadbalancer/loadbalancer-common/src/main/java/com/huaweicloud/loadbalancer/rule/LoadbalancerRuleResolver.java +++ b/sermant-plugins/sermant-loadbalancer/loadbalancer-common/src/main/java/com/huaweicloud/loadbalancer/rule/LoadbalancerRuleResolver.java @@ -144,6 +144,8 @@ private boolean isTargetConfig(String key) { /** * 组合matchGroup serviceName与loadbalancer rule,并返回变更的规则 + * + * @return 负载均衡规则 */ private Optional combine() { final Map newRules = new ConcurrentHashMap<>(ruleCache.size()); diff --git a/sermant-plugins/sermant-loadbalancer/spring-cloud-loadbalancer-plugin/src/main/java/com/huaweicloud/loadbalancer/cache/RibbonLoadbalancerCache.java b/sermant-plugins/sermant-loadbalancer/spring-cloud-loadbalancer-plugin/src/main/java/com/huaweicloud/loadbalancer/cache/RibbonLoadbalancerCache.java index 1b0509d34c..1d13bfe171 100644 --- a/sermant-plugins/sermant-loadbalancer/spring-cloud-loadbalancer-plugin/src/main/java/com/huaweicloud/loadbalancer/cache/RibbonLoadbalancerCache.java +++ b/sermant-plugins/sermant-loadbalancer/spring-cloud-loadbalancer-plugin/src/main/java/com/huaweicloud/loadbalancer/cache/RibbonLoadbalancerCache.java @@ -100,6 +100,10 @@ private void processModify(LoadbalancerRule rule) { if (!result) { return; } + if (!(rule instanceof ChangedLoadbalancerRule)) { + LOGGER.warning("LoadbalancerRule can not be cast to ChangedLoadbalancerRule"); + return; + } ChangedLoadbalancerRule changedLoadbalancerRule = (ChangedLoadbalancerRule) rule; final LoadbalancerRule oldRule = changedLoadbalancerRule.getOldRule(); final LoadbalancerRule newRule = changedLoadbalancerRule.getNewRule(); diff --git a/sermant-plugins/sermant-loadbalancer/spring-cloud-loadbalancer-plugin/src/main/java/com/huaweicloud/loadbalancer/cache/SpringLoadbalancerCache.java b/sermant-plugins/sermant-loadbalancer/spring-cloud-loadbalancer-plugin/src/main/java/com/huaweicloud/loadbalancer/cache/SpringLoadbalancerCache.java index 303caaa764..40d26cc9bb 100644 --- a/sermant-plugins/sermant-loadbalancer/spring-cloud-loadbalancer-plugin/src/main/java/com/huaweicloud/loadbalancer/cache/SpringLoadbalancerCache.java +++ b/sermant-plugins/sermant-loadbalancer/spring-cloud-loadbalancer-plugin/src/main/java/com/huaweicloud/loadbalancer/cache/SpringLoadbalancerCache.java @@ -102,6 +102,10 @@ private void processModify(LoadbalancerRule rule) { if (!result) { return; } + if (!(rule instanceof ChangedLoadbalancerRule)) { + LOGGER.warning("LoadbalancerRule can not be cast to ChangedLoadbalancerRule"); + return; + } ChangedLoadbalancerRule changedLoadbalancerRule = (ChangedLoadbalancerRule) rule; final LoadbalancerRule oldRule = changedLoadbalancerRule.getOldRule(); final LoadbalancerRule newRule = changedLoadbalancerRule.getNewRule(); diff --git a/sermant-plugins/sermant-loadbalancer/spring-cloud-loadbalancer-plugin/src/main/java/com/huaweicloud/loadbalancer/declarer/RoundRobinDeclarer.java b/sermant-plugins/sermant-loadbalancer/spring-cloud-loadbalancer-plugin/src/main/java/com/huaweicloud/loadbalancer/declarer/RoundRobinDeclarer.java index f8c4920ced..8004ce82e9 100644 --- a/sermant-plugins/sermant-loadbalancer/spring-cloud-loadbalancer-plugin/src/main/java/com/huaweicloud/loadbalancer/declarer/RoundRobinDeclarer.java +++ b/sermant-plugins/sermant-loadbalancer/spring-cloud-loadbalancer-plugin/src/main/java/com/huaweicloud/loadbalancer/declarer/RoundRobinDeclarer.java @@ -21,7 +21,6 @@ import net.bytebuddy.matcher.ElementMatchers; - /** * RoundRobinLoadBalancer增强类 * diff --git a/sermant-plugins/sermant-monitor/monitor-plugin/src/main/java/com/huawei/monitor/interceptor/DispatcherServletInterceptor.java b/sermant-plugins/sermant-monitor/monitor-plugin/src/main/java/com/huawei/monitor/interceptor/DispatcherServletInterceptor.java index 513f89da91..3f8edcd52b 100644 --- a/sermant-plugins/sermant-monitor/monitor-plugin/src/main/java/com/huawei/monitor/interceptor/DispatcherServletInterceptor.java +++ b/sermant-plugins/sermant-monitor/monitor-plugin/src/main/java/com/huawei/monitor/interceptor/DispatcherServletInterceptor.java @@ -51,8 +51,8 @@ public ExecuteContext after(ExecuteContext context) { LogUtils.printHttpRequestAfterPoint(context); return context; } - HttpServletRequest request = (HttpServletRequest) context.getArguments()[0]; - MetricCalEntity metricCalEntity = MonitorCacheUtil.getMetricCalEntity(request.getRequestURI()); + String uri = ((HttpServletRequest) context.getArguments()[0]).getRequestURI(); + MetricCalEntity metricCalEntity = MonitorCacheUtil.getMetricCalEntity(uri); metricCalEntity.getReqNum().incrementAndGet(); long startTime = (Long) context.getExtMemberFieldValue(START_TIME); metricCalEntity.getConsumeReqTimeNum().addAndGet(System.currentTimeMillis() - startTime); @@ -71,8 +71,8 @@ public ExecuteContext onThrow(ExecuteContext context) { LogUtils.printHttpRequestOnThrowPoint(context); return context; } - HttpServletRequest request = (HttpServletRequest) context.getArguments()[0]; - MetricCalEntity metricCalEntity = MonitorCacheUtil.getMetricCalEntity(request.getRequestURI()); + String uri = ((HttpServletRequest) context.getArguments()[0]).getRequestURI(); + MetricCalEntity metricCalEntity = MonitorCacheUtil.getMetricCalEntity(uri); metricCalEntity.getReqNum().incrementAndGet(); metricCalEntity.getFailedReqNum().incrementAndGet(); LogUtils.printHttpRequestOnThrowPoint(context); diff --git a/sermant-plugins/sermant-monitor/monitor-plugin/src/main/java/com/huawei/monitor/util/MonitorCacheUtil.java b/sermant-plugins/sermant-monitor/monitor-plugin/src/main/java/com/huawei/monitor/util/MonitorCacheUtil.java index f825a463da..baebf31b38 100644 --- a/sermant-plugins/sermant-monitor/monitor-plugin/src/main/java/com/huawei/monitor/util/MonitorCacheUtil.java +++ b/sermant-plugins/sermant-monitor/monitor-plugin/src/main/java/com/huawei/monitor/util/MonitorCacheUtil.java @@ -43,7 +43,7 @@ private MonitorCacheUtil() { * @return MetricCalEntity 监控数据 */ public static MetricCalEntity getMetricCalEntity(String key) { - return CONCURRENT_MAP.computeIfAbsent(key, s -> new MetricCalEntity()); + return CONCURRENT_MAP.computeIfAbsent(key, str -> new MetricCalEntity()); } /** diff --git a/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/CommandExecutor.java b/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/CommandExecutor.java index facd772006..4c432527b4 100644 --- a/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/CommandExecutor.java +++ b/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/CommandExecutor.java @@ -29,6 +29,7 @@ import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import java.util.logging.Level; import java.util.logging.Logger; /** @@ -39,7 +40,6 @@ * @since 2022-08-02 */ public class CommandExecutor { - private static final Logger LOGGER = LoggerFactory.getLogger(); private static final Runtime RUNTIME = Runtime.getRuntime(); @@ -54,7 +54,7 @@ private CommandExecutor() { * 命令执行 * * @param command 命令 - * @param 结果信息 + * @param 结果信息 * @return 执行结果 */ public static Optional execute(final MonitorCommand command) { @@ -93,16 +93,16 @@ private static void closeStream(InputStream inputStream) { try { inputStream.close(); } catch (IOException e) { - // ignored + LOGGER.log(Level.WARNING, "Fail to close stream, exception", e); } } /** * 结果解析 * - * @param command 命令 + * @param command 命令 * @param inputStream 读流 - * @param 结果信息 + * @param 结果信息 * @return 执行结果 */ private static Future parseResult(final MonitorCommand command, final InputStream inputStream) { @@ -112,13 +112,13 @@ private static Future parseResult(final MonitorCommand command, final /** * 错误解析 * - * @param command 命令 + * @param command 命令 * @param errorStream 错误流 - * @param latch 定时任务 - * @param 结果 + * @param latch 定时任务 + * @param 结果 */ private static void handleErrorStream(final MonitorCommand command, final InputStream errorStream, - final CountDownLatch latch) { + final CountDownLatch latch) { POOL.execute(new ErrorHandleTask(inputStream -> { command.handleError(inputStream); latch.countDown(); @@ -132,7 +132,6 @@ private static void handleErrorStream(final MonitorCommand command, final * @since 2022-08-02 */ private static class InputHandleTask implements Callable { - private final StreamHandler handler; private final InputStream inputStream; @@ -140,7 +139,7 @@ private static class InputHandleTask implements Callable { /** * 构造 * - * @param handler 前置处理 + * @param handler 前置处理 * @param inputStream 读入 */ InputHandleTask(StreamHandler handler, InputStream inputStream) { @@ -160,7 +159,6 @@ public T call() { * @since 2022-08-02 */ private static class ErrorHandleTask implements Runnable { - private final VoidStreamHandler handler; private final InputStream inputStream; @@ -168,7 +166,7 @@ private static class ErrorHandleTask implements Runnable { /** * 构造方法 * - * @param handler 前置处理 + * @param handler 前置处理 * @param inputStream 流 */ ErrorHandleTask(VoidStreamHandler handler, InputStream inputStream) { @@ -198,7 +196,6 @@ private interface StreamHandler { * @since 2022-08-02 */ private interface VoidStreamHandler { - /** * 前置处理 * diff --git a/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/CpuCommand.java b/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/CpuCommand.java index db4247b2e3..95fe73bd02 100644 --- a/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/CpuCommand.java +++ b/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/CpuCommand.java @@ -32,7 +32,6 @@ * @since 2022-08-02 */ public class CpuCommand extends CommonMonitorCommand { - private static final Logger LOGGER = LoggerFactory.getLogger(); private static final String COMMAND = "cat /proc/stat"; @@ -46,9 +45,13 @@ public class CpuCommand extends CommonMonitorCommand { * 各状态列索引 */ private static final int USER_INDEX = 1; + private static final int NICE_INDEX = 2; + private static final int SYSTEM_INDEX = 3; + private static final int IDLE_INDEX = 4; + private static final int IO_WAIT_INDEX = 5; @Override @@ -58,6 +61,9 @@ public String getCommand() { /** * 重构泛PaaS类:com.huawei.sermant.plugin.collection.util.CpuParser parse方法 + * + * @param inputStream 外部进程输出流 + * @return 解析后的结果 */ @Override public CpuStat parseResult(InputStream inputStream) { @@ -82,7 +88,6 @@ public CpuStat parseResult(InputStream inputStream) { * @since 2022-08-02 */ public static class CpuStat { - /** * 用户态 */ @@ -111,10 +116,10 @@ public static class CpuStat { /** * 构造方法 * - * @param user 用户态 - * @param nice nice信息 + * @param user 用户态 + * @param nice nice信息 * @param system 系统占用CPU - * @param idle CPU空闲情况 + * @param idle CPU空闲情况 * @param ioWait CPU等待时间 */ public CpuStat(long user, long nice, long system, long idle, long ioWait) { @@ -145,6 +150,11 @@ public long getIoWait() { return ioWait; } + /** + * 获取总的CPU占用率 + * + * @return CPU占用率之和 + */ public long getTotal() { return system + user + nice + idle + ioWait; } diff --git a/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/CpuInfoCommand.java b/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/CpuInfoCommand.java index 1dedd37847..592f4148f9 100644 --- a/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/CpuInfoCommand.java +++ b/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/CpuInfoCommand.java @@ -49,6 +49,9 @@ public String getCommand() { /** * 重构泛PaaS类:com.huawei.sermant.plugin.collection.util.CpuParser parse方法 + * + * @param inputStream 外部进程输出流 + * @return 解析后的结果 */ @Override public CpuInfoStat parseResult(InputStream inputStream) { diff --git a/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/DiskCommand.java b/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/DiskCommand.java index 0dbe64b4a9..1ed5daf11c 100644 --- a/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/DiskCommand.java +++ b/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/DiskCommand.java @@ -45,6 +45,9 @@ public String getCommand() { /** * 重构泛PaaS类:com.huawei.sermant.plugin.collection.util.DiskParser parse方法 + * + * @param inputStream 外部进程输出流 + * @return 解析后的结果 */ @Override public List parseResult(InputStream inputStream) { diff --git a/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/MemoryCommand.java b/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/MemoryCommand.java index 3c376d5172..1e03ed4c8f 100644 --- a/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/MemoryCommand.java +++ b/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/MemoryCommand.java @@ -45,6 +45,9 @@ public String getCommand() { /** * 原泛PaaS类:com.huawei.sermant.plugin.collection.util.MemoryParser parse方法 + * + * @param inputStream 外部进程输出流 + * @return 解析后的结果 */ @Override public MemInfo parseResult(InputStream inputStream) { diff --git a/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/NetworkCommand.java b/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/NetworkCommand.java index caf51d4795..d8a35c0fe9 100644 --- a/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/NetworkCommand.java +++ b/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/command/NetworkCommand.java @@ -46,6 +46,9 @@ public String getCommand() { /** * 重构泛PaaS类:com.huawei.sermant.plugin.collection.util.NetWorkParser parse方法 + * + * @param inputStream 外部进程输出流 + * @return 解析后的结果 */ @Override public NetDev parseResult(InputStream inputStream) { diff --git a/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/common/MetricFamilyBuild.java b/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/common/MetricFamilyBuild.java index 2f5a13acac..59a55082d1 100644 --- a/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/common/MetricFamilyBuild.java +++ b/sermant-plugins/sermant-monitor/monitor-service/src/main/java/com/huawei/monitor/common/MetricFamilyBuild.java @@ -28,7 +28,6 @@ * @since 2022-08-02 */ public class MetricFamilyBuild { - /** * 构造方法 */ @@ -56,7 +55,7 @@ public static GaugeMetricFamily buildGaugeMetric(MetricEnum metricEnum, double v * @return 创建的收集指标 */ public static GaugeMetricFamily buildGaugeMetric(MetricEnum metricEnum, double value, String labelName, - String labelValue) { + String labelValue) { GaugeMetricFamily gaugeMetricFamily = new GaugeMetricFamily(metricEnum.getName(), metricEnum.getDisc(), Collections.singletonList(labelName)); return gaugeMetricFamily.addMetric(Collections.singletonList(labelValue), value);