diff --git a/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/config/CmdbMetricsAutoConfiguration.java b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/config/CmdbMetricsAutoConfiguration.java new file mode 100644 index 0000000000..0c1be7fc0c --- /dev/null +++ b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/config/CmdbMetricsAutoConfiguration.java @@ -0,0 +1,56 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.common.cc.config; + +import com.tencent.bk.job.common.cc.constants.CmdbMetricNames; +import io.micrometer.core.instrument.Meter; +import io.micrometer.core.instrument.config.MeterFilter; +import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * cmdb 监控指标配置 + */ +@Configuration +public class CmdbMetricsAutoConfiguration { + @Bean("cmdbMeterFilter") + public MeterFilter distributionMeterFilter() { + return new MeterFilter() { + @Override + public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) { + String metricName = id.getName(); + if (metricName.startsWith(CmdbMetricNames.CMDB_API_PREFIX)) { + return DistributionStatisticConfig.builder().percentilesHistogram(true) + // [10ms,1s] + .minimumExpectedValue(10_000_000.0).maximumExpectedValue(1_000_000_000.0) + .build().merge(config); + } else { + return config; + } + } + }; + } +} diff --git a/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/constants/CmdbMetricNames.java b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/constants/CmdbMetricNames.java new file mode 100644 index 0000000000..85c4050fae --- /dev/null +++ b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/constants/CmdbMetricNames.java @@ -0,0 +1,30 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.common.cc.constants; + +public interface CmdbMetricNames { + + String CMDB_API_PREFIX = "job.client.cmdb.api"; +} diff --git a/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizCmdbClient.java b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizCmdbClient.java index 71dbc171f7..d1dd86280a 100644 --- a/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizCmdbClient.java +++ b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizCmdbClient.java @@ -30,6 +30,7 @@ import com.google.common.cache.LoadingCache; import com.google.common.util.concurrent.UncheckedExecutionException; import com.tencent.bk.job.common.cc.config.CmdbConfig; +import com.tencent.bk.job.common.cc.constants.CmdbMetricNames; import com.tencent.bk.job.common.cc.exception.CmdbException; import com.tencent.bk.job.common.cc.model.AppRoleDTO; import com.tencent.bk.job.common.cc.model.BaseRuleDTO; @@ -356,7 +357,7 @@ public EsbResp requestCmdbApi(String method, } finally { HttpMetricUtil.clearHttpMetric(); long end = System.nanoTime(); - meterRegistry.timer(CommonMetricNames.ESB_CMDB_API, "api_name", uri, "status", status) + meterRegistry.timer(CmdbMetricNames.CMDB_API_PREFIX, "api_name", uri, "status", status) .record(end - start, TimeUnit.NANOSECONDS); } } diff --git a/src/backend/commons/cmdb-sdk/src/main/resources/META-INF/spring.factories b/src/backend/commons/cmdb-sdk/src/main/resources/META-INF/spring.factories index ce321e8b02..efaa584316 100644 --- a/src/backend/commons/cmdb-sdk/src/main/resources/META-INF/spring.factories +++ b/src/backend/commons/cmdb-sdk/src/main/resources/META-INF/spring.factories @@ -1,3 +1,4 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.tencent.bk.job.common.cc.config.CmdbAutoConfiguration,\ -com.tencent.bk.job.common.cc.config.CmdbFlowControlAutoConfiguration +com.tencent.bk.job.common.cc.config.CmdbFlowControlAutoConfiguration,\ +com.tencent.bk.job.common.cc.config.CmdbMetricsAutoConfiguration diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/metrics/CommonMetricNames.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/metrics/CommonMetricNames.java index c011b87474..4f54593d53 100644 --- a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/metrics/CommonMetricNames.java +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/metrics/CommonMetricNames.java @@ -52,11 +52,6 @@ public class CommonMetricNames { * 仅统计调用ESB CMDB API的HTTP请求过程 */ public static final String ESB_CMDB_API_HTTP = "job.client.cmdb.api.http"; - /** - * 统计调用CMDB API整个过程,含反序列化 - */ - public static final String ESB_CMDB_API = "job.client.cmdb.api"; - /** * 仅统计调用制品库 API的HTTP请求过程 diff --git a/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/config/GseMetricsAutoConfiguration.java b/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/config/GseMetricsAutoConfiguration.java new file mode 100644 index 0000000000..ee377fb6d6 --- /dev/null +++ b/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/config/GseMetricsAutoConfiguration.java @@ -0,0 +1,57 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.common.gse.config; + +import com.tencent.bk.job.common.gse.constants.GseMetricNames; +import io.micrometer.core.instrument.Meter; +import io.micrometer.core.instrument.config.MeterFilter; +import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * GSE 监控指标配置 + */ +@Configuration +public class GseMetricsAutoConfiguration { + @Bean("gseApiMeterFilter") + public MeterFilter distributionMeterFilter() { + return new MeterFilter() { + @Override + public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) { + String metricName = id.getName(); + if (metricName.startsWith(GseMetricNames.GSE_API_METRICS_NAME_PREFIX) + || metricName.startsWith(GseMetricNames.GSE_V2_API_METRICS_NAME_PREFIX)) { + return DistributionStatisticConfig.builder().percentilesHistogram(true) + // [10ms,1s] + .minimumExpectedValue(10_000_000.0).maximumExpectedValue(1_000_000_000.0) + .build().merge(config); + } else { + return config; + } + } + }; + } +} diff --git a/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/constants/GseConstants.java b/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/constants/GseConstants.java index 3e9fe1720e..515283a497 100644 --- a/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/constants/GseConstants.java +++ b/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/constants/GseConstants.java @@ -30,16 +30,6 @@ public interface GseConstants { */ int DEFAULT_CLOUD_ID = 0; - /** - * GSE API 度量指标名称前缀 - */ - String GSE_API_METRICS_NAME_PREFIX = "job.client.gse.api"; - - /** - * GSE V2 API 度量指标名称前缀 - */ - String GSE_V2_API_METRICS_NAME_PREFIX = "job.client.gse.v2.api"; - /** * GSE 获取文件任务执行结果协议版本V2 - 解除valuekey依赖版本 */ diff --git a/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/constants/GseMetricNames.java b/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/constants/GseMetricNames.java new file mode 100644 index 0000000000..cc0815f989 --- /dev/null +++ b/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/constants/GseMetricNames.java @@ -0,0 +1,37 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.common.gse.constants; + +public interface GseMetricNames { + /** + * GSE V1 API 度量指标名称前缀 + */ + String GSE_API_METRICS_NAME_PREFIX = "job.client.gse.api"; + + /** + * GSE V2 API 度量指标名称前缀 + */ + String GSE_V2_API_METRICS_NAME_PREFIX = "job.client.gse.v2.api"; +} diff --git a/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/v1/GseV1ApiClient.java b/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/v1/GseV1ApiClient.java index d0001484f2..58b03b5a79 100644 --- a/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/v1/GseV1ApiClient.java +++ b/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/v1/GseV1ApiClient.java @@ -27,6 +27,7 @@ import com.tencent.bk.job.common.gse.constants.AgentStateStatusEnum; import com.tencent.bk.job.common.gse.constants.FileDistModeEnum; import com.tencent.bk.job.common.gse.constants.GseConstants; +import com.tencent.bk.job.common.gse.constants.GseMetricNames; import com.tencent.bk.job.common.gse.constants.GseTaskTypeEnum; import com.tencent.bk.job.common.gse.util.WindowsHelper; import com.tencent.bk.job.common.gse.v1.model.AgentStatusDTO; @@ -362,7 +363,7 @@ private AgentStatusResponse queryAgentStatusFromCacheApi(Collection agen long end = System.currentTimeMillis(); log.info("BatchGetAgentStatus {} agentIds, cost: {}ms", agentIds.size(), (end - start)); if (this.meterRegistry != null) { - meterRegistry.timer(GseConstants.GSE_API_METRICS_NAME_PREFIX, "api_name", "quireAgentStatus", + meterRegistry.timer(GseMetricNames.GSE_API_METRICS_NAME_PREFIX, "api_name", "quireAgentStatus", "status", status).record(end - start, TimeUnit.MICROSECONDS); } gseClient.tearDown(); @@ -820,7 +821,7 @@ private T sendCmd(GseApiCallback caller) { status = "error"; } finally { long end = System.nanoTime(); - meterRegistry.timer(GseConstants.GSE_API_METRICS_NAME_PREFIX, "api_name", caller.getApiName(), + meterRegistry.timer(GseMetricNames.GSE_API_METRICS_NAME_PREFIX, "api_name", caller.getApiName(), "status", status).record(end - start, TimeUnit.NANOSECONDS); } } while (retry-- > 0); //重试1次 diff --git a/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/v2/GseV2ApiClient.java b/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/v2/GseV2ApiClient.java index 6d9ab51f92..8e57558adb 100644 --- a/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/v2/GseV2ApiClient.java +++ b/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/v2/GseV2ApiClient.java @@ -9,6 +9,7 @@ import com.tencent.bk.job.common.esb.sdk.BkApiLogStrategy; import com.tencent.bk.job.common.gse.IGseClient; import com.tencent.bk.job.common.gse.constants.GseConstants; +import com.tencent.bk.job.common.gse.constants.GseMetricNames; import com.tencent.bk.job.common.gse.v2.model.AsyncGseTaskResult; import com.tencent.bk.job.common.gse.v2.model.ExecuteScriptRequest; import com.tencent.bk.job.common.gse.v2.model.FileTaskResult; @@ -42,7 +43,7 @@ public GseV2ApiClient(MeterRegistry meterRegistry, AppProperties appProperties, BkApiGatewayProperties bkApiGatewayProperties) { super(meterRegistry, - GseConstants.GSE_V2_API_METRICS_NAME_PREFIX, + GseMetricNames.GSE_V2_API_METRICS_NAME_PREFIX, bkApiGatewayProperties.getGse().getUrl(), appProperties.getCode(), appProperties.getSecret()); diff --git a/src/backend/commons/gse-sdk/src/main/resources/META-INF/spring.factories b/src/backend/commons/gse-sdk/src/main/resources/META-INF/spring.factories index 94269d7564..93749a4152 100644 --- a/src/backend/commons/gse-sdk/src/main/resources/META-INF/spring.factories +++ b/src/backend/commons/gse-sdk/src/main/resources/META-INF/spring.factories @@ -1,2 +1,3 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -com.tencent.bk.job.common.gse.config.GseAutoConfiguration +com.tencent.bk.job.common.gse.config.GseAutoConfiguration,\ +com.tencent.bk.job.common.gse.config.GseMetricsAutoConfiguration diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/config/MetricsAutoConfig.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/config/MetricsConfiguration.java similarity index 89% rename from src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/config/MetricsAutoConfig.java rename to src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/config/MetricsConfiguration.java index a68d2335e9..8d0025d4cf 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/config/MetricsAutoConfig.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/config/MetricsConfiguration.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.execute.config; -import com.tencent.bk.job.common.gse.constants.GseConstants; import com.tencent.bk.job.common.metrics.CommonMetricNames; import com.tencent.bk.job.execute.monitor.ExecuteMetricNames; import com.tencent.bk.job.execute.monitor.ExecuteMetricTags; @@ -36,8 +35,11 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +/** + * 监控指标配置 + */ @Configuration -public class MetricsAutoConfig { +public class MetricsConfiguration { @Bean public MeterFilter distributionMeterFilter() { return new MeterFilter() { @@ -49,11 +51,6 @@ public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticC // [10ms,3s] .minimumExpectedValue(10_000_000.0).maximumExpectedValue(3_000_000_000.0) .build().merge(config); - } else if (metricName.startsWith(GseConstants.GSE_API_METRICS_NAME_PREFIX)) { - return DistributionStatisticConfig.builder().percentilesHistogram(true) - // [10ms,1s] - .minimumExpectedValue(10_000_000.0).maximumExpectedValue(1_000_000_000.0) - .build().merge(config); } else if (metricName.startsWith(ExecuteMetricNames.RESULT_HANDLE_TASK_SCHEDULE_PREFIX)) { return DistributionStatisticConfig.builder().percentilesHistogram(true) // [10ms,5s]