Skip to content

Commit

Permalink
feat: API 度量指标 histogram 配置优化 TencentBlueKing#2599
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu096 committed Nov 8, 2023
1 parent 819e059 commit f390b97
Show file tree
Hide file tree
Showing 12 changed files with 195 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
};
}
}
Original file line number Diff line number Diff line change
@@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -356,7 +357,7 @@ public <R> EsbResp<R> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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请求过程
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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依赖版本
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -362,7 +363,7 @@ private AgentStatusResponse queryAgentStatusFromCacheApi(Collection<String> 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();
Expand Down Expand Up @@ -820,7 +821,7 @@ private <T> T sendCmd(GseApiCallback<T> 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次
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -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]
Expand Down

0 comments on commit f390b97

Please sign in to comment.