From f76b01ed7269138a62d5b213070c89d755e7fbf9 Mon Sep 17 00:00:00 2001 From: yuzhongyu Date: Fri, 1 Apr 2022 16:31:27 +0800 Subject: [PATCH 1/6] add SAMPLE_AVG_CPU_LOAD_LIMIT config --- .../apm/agent/core/conf/Config.java | 2 ++ .../agent/core/sampling/SamplingService.java | 33 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java index d9a191f427..6590fa8b67 100755 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java @@ -87,6 +87,8 @@ public static class Agent { */ public static int SAMPLE_N_PER_3_SECS = -1; + public static double SAMPLE_AVG_CPU_LOAD_LIMIT = -1; + /** * If the operation name of the first span is included in this set, this segment should be ignored. Multiple * values should be separated by `,`. diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/sampling/SamplingService.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/sampling/SamplingService.java index 83c29718a4..8ce9e28016 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/sampling/SamplingService.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/sampling/SamplingService.java @@ -18,6 +18,8 @@ package org.apache.skywalking.apm.agent.core.sampling; +import java.lang.management.ManagementFactory; +import java.lang.management.OperatingSystemMXBean; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; @@ -52,6 +54,14 @@ public class SamplingService implements BootService { private SamplingRateWatcher samplingRateWatcher; + private volatile boolean avgCpuLoadLimitOn = false; + + private volatile OperatingSystemMXBean operatingSystemMXBean; + + private volatile int processorNum; + + private volatile double avgCpuLoad; + @Override public void prepare() { } @@ -63,6 +73,16 @@ public void boot() { .registerAgentConfigChangeWatcher(samplingRateWatcher); handleSamplingRateChanged(); + + // todo CDS + if (Config.Agent.SAMPLE_AVG_CPU_LOAD_LIMIT > 0) { + avgCpuLoadLimitOn = true; + operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); + processorNum = operatingSystemMXBean.getAvailableProcessors(); + Executors.newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("SamplingService refreshAvgCpuLoad")) + .scheduleAtFixedRate(new RunnableWithExceptionProtection(this::refreshAvgCpuLoad, t -> LOGGER.error("SamplingService refreshAvgCpuLoad unexpected exception.", t)), + 0, 1, TimeUnit.SECONDS); + } } @Override @@ -85,6 +105,12 @@ public void shutdown() { * @return true if should sample this trace segment. When sampling mechanism is on, return true if sample limited is not reached. */ public boolean trySampling(String operationName) { + if (avgCpuLoadLimitOn) { + if (avgCpuLoad > Config.Agent.SAMPLE_AVG_CPU_LOAD_LIMIT) { + return false; + } + } + if (on) { int factor = samplingFactorHolder.get(); if (factor < samplingRateWatcher.getSamplingRate()) { @@ -136,4 +162,9 @@ public void handleSamplingRateChanged() { } } } -} \ No newline at end of file + + private void refreshAvgCpuLoad() { + avgCpuLoad = operatingSystemMXBean.getSystemLoadAverage() / processorNum; + } + +} From 119c9fb98a592aaf0bfa4ba46200f681367602a2 Mon Sep 17 00:00:00 2001 From: yuzhongyu Date: Sat, 2 Apr 2022 16:19:44 +0800 Subject: [PATCH 2/6] change to cpu limit optional plugin, and reuse JVMService to get cpu usage percent --- .../apm/agent/core/conf/Config.java | 2 - .../apm/agent/core/jvm/JVMService.java | 10 ++ .../agent/core/sampling/SamplingService.java | 31 ------- .../config/apm-trace-cpu-limit-plugin.config | 23 +++++ apm-sniffer/optional-plugins/pom.xml | 1 + .../trace-cpu-limit-plugin/pom.xml | 45 +++++++++ .../cpu/limit/TraceCpuLimitExtendService.java | 78 ++++++++++++++++ .../trace/cpu/limit/conf/CpuLimitConfig.java | 26 ++++++ .../limit/conf/CpuLimitConfigInitializer.java | 92 +++++++++++++++++++ ...skywalking.apm.agent.core.boot.BootService | 19 ++++ ...skywalking.apm.agent.core.boot.BootService | 19 ++++ 11 files changed, 313 insertions(+), 33 deletions(-) create mode 100644 apm-sniffer/config/apm-trace-cpu-limit-plugin.config create mode 100644 apm-sniffer/optional-plugins/trace-cpu-limit-plugin/pom.xml create mode 100644 apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/TraceCpuLimitExtendService.java create mode 100644 apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/conf/CpuLimitConfig.java create mode 100644 apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/conf/CpuLimitConfigInitializer.java create mode 100644 apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService create mode 100644 apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/test/resources/org.apache.skywalking.apm.agent.core.boot.BootService diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java index 6590fa8b67..d9a191f427 100755 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java @@ -87,8 +87,6 @@ public static class Agent { */ public static int SAMPLE_N_PER_3_SECS = -1; - public static double SAMPLE_AVG_CPU_LOAD_LIMIT = -1; - /** * If the operation name of the first span is included in this set, this segment should be ignored. Multiple * values should be separated by `,`. diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/JVMService.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/JVMService.java index 4c9b25ddbb..24e74573d6 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/JVMService.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/JVMService.java @@ -48,6 +48,8 @@ public class JVMService implements BootService, Runnable { private volatile ScheduledFuture sendMetricFuture; private JVMMetricsSender sender; + private volatile double cpuUsagePercent; + @Override public void prepare() throws Throwable { sender = ServiceManager.INSTANCE.findService(JVMMetricsSender.class); @@ -104,8 +106,16 @@ public void run() { jvmBuilder.setClazz(ClassProvider.INSTANCE.getClassMetrics()); sender.offer(jvmBuilder.build()); + + // refresh cpu usage percent + cpuUsagePercent = jvmBuilder.getCpu().getUsagePercent(); } catch (Exception e) { LOGGER.error(e, "Collect JVM info fail."); } } + + public double getCpuUsagePercent() { + return this.cpuUsagePercent; + } + } diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/sampling/SamplingService.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/sampling/SamplingService.java index 8ce9e28016..ada9825342 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/sampling/SamplingService.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/sampling/SamplingService.java @@ -18,8 +18,6 @@ package org.apache.skywalking.apm.agent.core.sampling; -import java.lang.management.ManagementFactory; -import java.lang.management.OperatingSystemMXBean; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; @@ -54,14 +52,6 @@ public class SamplingService implements BootService { private SamplingRateWatcher samplingRateWatcher; - private volatile boolean avgCpuLoadLimitOn = false; - - private volatile OperatingSystemMXBean operatingSystemMXBean; - - private volatile int processorNum; - - private volatile double avgCpuLoad; - @Override public void prepare() { } @@ -73,16 +63,6 @@ public void boot() { .registerAgentConfigChangeWatcher(samplingRateWatcher); handleSamplingRateChanged(); - - // todo CDS - if (Config.Agent.SAMPLE_AVG_CPU_LOAD_LIMIT > 0) { - avgCpuLoadLimitOn = true; - operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); - processorNum = operatingSystemMXBean.getAvailableProcessors(); - Executors.newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("SamplingService refreshAvgCpuLoad")) - .scheduleAtFixedRate(new RunnableWithExceptionProtection(this::refreshAvgCpuLoad, t -> LOGGER.error("SamplingService refreshAvgCpuLoad unexpected exception.", t)), - 0, 1, TimeUnit.SECONDS); - } } @Override @@ -105,12 +85,6 @@ public void shutdown() { * @return true if should sample this trace segment. When sampling mechanism is on, return true if sample limited is not reached. */ public boolean trySampling(String operationName) { - if (avgCpuLoadLimitOn) { - if (avgCpuLoad > Config.Agent.SAMPLE_AVG_CPU_LOAD_LIMIT) { - return false; - } - } - if (on) { int factor = samplingFactorHolder.get(); if (factor < samplingRateWatcher.getSamplingRate()) { @@ -162,9 +136,4 @@ public void handleSamplingRateChanged() { } } } - - private void refreshAvgCpuLoad() { - avgCpuLoad = operatingSystemMXBean.getSystemLoadAverage() / processorNum; - } - } diff --git a/apm-sniffer/config/apm-trace-cpu-limit-plugin.config b/apm-sniffer/config/apm-trace-cpu-limit-plugin.config new file mode 100644 index 0000000000..16ce2ae85a --- /dev/null +++ b/apm-sniffer/config/apm-trace-cpu-limit-plugin.config @@ -0,0 +1,23 @@ +# 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. + +# If the operation name of the first span is matching, this segment should be ignored +# ant path match style +# /path/? Match any single character +# /path/* Match any number of characters +# /path/** Match any number of characters and support multilevel directories +# Multiple path comma separation, like trace.ignore_path=/eureka/**,/consul/** +trace.sample_cpu_usage_percent_limit=${SW_SAMPLE_CPU_USAGE_PERCENT_LIMIT:-1} diff --git a/apm-sniffer/optional-plugins/pom.xml b/apm-sniffer/optional-plugins/pom.xml index 308d1d9a90..a58a61e152 100644 --- a/apm-sniffer/optional-plugins/pom.xml +++ b/apm-sniffer/optional-plugins/pom.xml @@ -44,6 +44,7 @@ optional-spring-plugins trace-ignore-plugin + trace-cpu-limit-plugin gson-2.8.x-plugin zookeeper-3.4.x-plugin customize-enhance-plugin diff --git a/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/pom.xml b/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/pom.xml new file mode 100644 index 0000000000..f3b54fc2fa --- /dev/null +++ b/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/pom.xml @@ -0,0 +1,45 @@ + + + + + optional-plugins + org.apache.skywalking + 8.10.0-SNAPSHOT + + 4.0.0 + + apm-trace-cpu-limit-plugin + jar + + apm-trace-cpu-limit-plugin + http://maven.apache.org + + + 1.18.0 + + + + + com.github.stefanbirkner + system-rules + ${ststem-rules.version} + test + + + diff --git a/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/TraceCpuLimitExtendService.java b/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/TraceCpuLimitExtendService.java new file mode 100644 index 0000000000..f55adfd0bb --- /dev/null +++ b/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/TraceCpuLimitExtendService.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.trace.cpu.limit; + +import org.apache.skywalking.apm.agent.core.boot.OverrideImplementor; +import org.apache.skywalking.apm.agent.core.boot.ServiceManager; +import org.apache.skywalking.apm.agent.core.jvm.JVMService; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.agent.core.sampling.SamplingService; +import org.apache.skywalking.apm.plugin.trace.cpu.limit.conf.CpuLimitConfig; +import org.apache.skywalking.apm.plugin.trace.cpu.limit.conf.CpuLimitConfigInitializer; + +@OverrideImplementor(SamplingService.class) +public class TraceCpuLimitExtendService extends SamplingService { + private static final ILog LOGGER = LogManager.getLogger(TraceCpuLimitExtendService.class); + + private volatile boolean cpuUsagePercentLimitOn = false; + private volatile JVMService jvmService; + + @Override + public void prepare() { + super.prepare(); + } + + @Override + public void boot() { + super.boot(); + CpuLimitConfigInitializer.initialize(); + if (CpuLimitConfig.Trace.SAMPLE_CPU_USAGE_PERCENT_LIMIT > 0) { + LOGGER.info("TraceCpuLimitExtendService cpu usage percent limit open"); + jvmService = ServiceManager.INSTANCE.findService(JVMService.class); + cpuUsagePercentLimitOn = true; + } + } + + @Override + public void onComplete() { + } + + @Override + public void shutdown() { + super.shutdown(); + } + + @Override + public boolean trySampling(final String operationName) { + if (cpuUsagePercentLimitOn) { + double cpuUsagePercent = jvmService.getCpuUsagePercent(); + if (cpuUsagePercent > CpuLimitConfig.Trace.SAMPLE_CPU_USAGE_PERCENT_LIMIT) { + return false; + } + } + return super.trySampling(operationName); + } + + @Override + public void forceSampled() { + super.forceSampled(); + } + +} diff --git a/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/conf/CpuLimitConfig.java b/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/conf/CpuLimitConfig.java new file mode 100644 index 0000000000..27ab93d37a --- /dev/null +++ b/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/conf/CpuLimitConfig.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.trace.cpu.limit.conf; + +public class CpuLimitConfig { + + public static class Trace { + public static double SAMPLE_CPU_USAGE_PERCENT_LIMIT = -1; + } +} diff --git a/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/conf/CpuLimitConfigInitializer.java b/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/conf/CpuLimitConfigInitializer.java new file mode 100644 index 0000000000..385302fcdb --- /dev/null +++ b/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/conf/CpuLimitConfigInitializer.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.trace.cpu.limit.conf; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.util.Map; +import java.util.Properties; +import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; +import org.apache.skywalking.apm.agent.core.boot.AgentPackagePath; +import org.apache.skywalking.apm.agent.core.conf.ConfigNotFoundException; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.util.ConfigInitializer; +import org.apache.skywalking.apm.util.PropertyPlaceholderHelper; + +public class CpuLimitConfigInitializer { + private static final ILog LOGGER = LogManager.getLogger(CpuLimitConfigInitializer.class); + private static final String CONFIG_FILE_NAME = "/config/apm-trace-cpu-limit-plugin.config"; + private static final String ENV_KEY_PREFIX = "skywalking."; + + public static void initialize() { + try (final InputStream configFileStream = loadConfigFromAgentFolder()) { + Properties properties = new Properties(); + properties.load(configFileStream); + for (String key : properties.stringPropertyNames()) { + String value = (String) properties.get(key); + properties.put(key, PropertyPlaceholderHelper.INSTANCE.replacePlaceholders(value, properties)); + } + ConfigInitializer.initialize(properties, CpuLimitConfig.class); + } catch (Exception e) { + LOGGER.error(e, "Failed to read the config file, skywalking is going to run in default config."); + } + + try { + overrideConfigBySystemProp(); + } catch (Exception e) { + LOGGER.error(e, "Failed to read the system env."); + } + } + + private static void overrideConfigBySystemProp() throws IllegalAccessException { + Properties properties = new Properties(); + Properties systemProperties = System.getProperties(); + for (final Map.Entry prop : systemProperties.entrySet()) { + if (prop.getKey().toString().startsWith(ENV_KEY_PREFIX)) { + String realKey = prop.getKey().toString().substring(ENV_KEY_PREFIX.length()); + properties.put(realKey, prop.getValue()); + } + } + + if (!properties.isEmpty()) { + ConfigInitializer.initialize(properties, CpuLimitConfig.class); + } + } + + /** + * Load the config file, where the agent jar is. + * + * @return the config file {@link InputStream}, or null if not needEnhance. + */ + private static InputStream loadConfigFromAgentFolder() throws AgentPackageNotFoundException, ConfigNotFoundException { + File configFile = new File(AgentPackagePath.getPath(), CONFIG_FILE_NAME); + if (configFile.exists() && configFile.isFile()) { + try { + LOGGER.info("Ignore config file found in {}.", configFile); + return new FileInputStream(configFile); + } catch (FileNotFoundException e) { + throw new ConfigNotFoundException("Fail to load apm-trace-cpu-limit-plugin.config", e); + } + } + throw new ConfigNotFoundException("Fail to load cpu limit config file."); + } +} diff --git a/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService b/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService new file mode 100644 index 0000000000..46dd1104b3 --- /dev/null +++ b/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService @@ -0,0 +1,19 @@ +# +# 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. +# +# + +org.apache.skywalking.apm.plugin.trace.cpu.limit.TraceCpuLimitExtendService diff --git a/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/test/resources/org.apache.skywalking.apm.agent.core.boot.BootService b/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/test/resources/org.apache.skywalking.apm.agent.core.boot.BootService new file mode 100644 index 0000000000..46dd1104b3 --- /dev/null +++ b/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/test/resources/org.apache.skywalking.apm.agent.core.boot.BootService @@ -0,0 +1,19 @@ +# +# 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. +# +# + +org.apache.skywalking.apm.plugin.trace.cpu.limit.TraceCpuLimitExtendService From 6d63c1e7119e3b2552dc4a6f33286359e1b23f04 Mon Sep 17 00:00:00 2001 From: yuzhongyu Date: Sun, 24 Apr 2022 17:59:33 +0800 Subject: [PATCH 3/6] fix cr --- .../apm/agent/core/jvm/JVMService.java | 5 +- .../config/apm-trace-cpu-limit-plugin.config | 23 ----- apm-sniffer/optional-plugins/pom.xml | 2 +- .../limit/conf/CpuLimitConfigInitializer.java | 92 ------------------- .../pom.xml | 2 +- .../TraceSamplerCpuPolicyExtendService.java} | 16 ++-- .../TraceSamplerCpuPolicyPluginConfig.java} | 12 ++- ...skywalking.apm.agent.core.boot.BootService | 2 +- ...skywalking.apm.agent.core.boot.BootService | 2 +- 9 files changed, 22 insertions(+), 134 deletions(-) delete mode 100644 apm-sniffer/config/apm-trace-cpu-limit-plugin.config delete mode 100644 apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/conf/CpuLimitConfigInitializer.java rename apm-sniffer/optional-plugins/{trace-cpu-limit-plugin => trace-sampler-cpu-policy-plugin}/pom.xml (96%) rename apm-sniffer/optional-plugins/{trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/TraceCpuLimitExtendService.java => trace-sampler-cpu-policy-plugin/src/main/java/org/apache/skywalking/apm/plugin/cpu/policy/TraceSamplerCpuPolicyExtendService.java} (78%) rename apm-sniffer/optional-plugins/{trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/conf/CpuLimitConfig.java => trace-sampler-cpu-policy-plugin/src/main/java/org/apache/skywalking/apm/plugin/cpu/policy/conf/TraceSamplerCpuPolicyPluginConfig.java} (67%) rename apm-sniffer/optional-plugins/{trace-cpu-limit-plugin => trace-sampler-cpu-policy-plugin}/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService (90%) rename apm-sniffer/optional-plugins/{trace-cpu-limit-plugin => trace-sampler-cpu-policy-plugin}/src/test/resources/org.apache.skywalking.apm.agent.core.boot.BootService (90%) diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/JVMService.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/JVMService.java index 24e74573d6..e70f7c8a18 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/JVMService.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/JVMService.java @@ -105,10 +105,11 @@ public void run() { jvmBuilder.setThread(ThreadProvider.INSTANCE.getThreadMetrics()); jvmBuilder.setClazz(ClassProvider.INSTANCE.getClassMetrics()); - sender.offer(jvmBuilder.build()); + JVMMetric jvmMetric = jvmBuilder.build(); + sender.offer(jvmMetric); // refresh cpu usage percent - cpuUsagePercent = jvmBuilder.getCpu().getUsagePercent(); + cpuUsagePercent = jvmMetric.getCpu().getUsagePercent(); } catch (Exception e) { LOGGER.error(e, "Collect JVM info fail."); } diff --git a/apm-sniffer/config/apm-trace-cpu-limit-plugin.config b/apm-sniffer/config/apm-trace-cpu-limit-plugin.config deleted file mode 100644 index 16ce2ae85a..0000000000 --- a/apm-sniffer/config/apm-trace-cpu-limit-plugin.config +++ /dev/null @@ -1,23 +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. - -# If the operation name of the first span is matching, this segment should be ignored -# ant path match style -# /path/? Match any single character -# /path/* Match any number of characters -# /path/** Match any number of characters and support multilevel directories -# Multiple path comma separation, like trace.ignore_path=/eureka/**,/consul/** -trace.sample_cpu_usage_percent_limit=${SW_SAMPLE_CPU_USAGE_PERCENT_LIMIT:-1} diff --git a/apm-sniffer/optional-plugins/pom.xml b/apm-sniffer/optional-plugins/pom.xml index a58a61e152..e7958064d6 100644 --- a/apm-sniffer/optional-plugins/pom.xml +++ b/apm-sniffer/optional-plugins/pom.xml @@ -44,7 +44,6 @@ optional-spring-plugins trace-ignore-plugin - trace-cpu-limit-plugin gson-2.8.x-plugin zookeeper-3.4.x-plugin customize-enhance-plugin @@ -56,6 +55,7 @@ guava-cache-plugin fastjson-1.2.x-plugin jackson-2.x-plugin + trace-sampler-cpu-policy-plugin diff --git a/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/conf/CpuLimitConfigInitializer.java b/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/conf/CpuLimitConfigInitializer.java deleted file mode 100644 index 385302fcdb..0000000000 --- a/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/conf/CpuLimitConfigInitializer.java +++ /dev/null @@ -1,92 +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 org.apache.skywalking.apm.plugin.trace.cpu.limit.conf; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.util.Map; -import java.util.Properties; -import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; -import org.apache.skywalking.apm.agent.core.boot.AgentPackagePath; -import org.apache.skywalking.apm.agent.core.conf.ConfigNotFoundException; -import org.apache.skywalking.apm.agent.core.logging.api.ILog; -import org.apache.skywalking.apm.agent.core.logging.api.LogManager; -import org.apache.skywalking.apm.util.ConfigInitializer; -import org.apache.skywalking.apm.util.PropertyPlaceholderHelper; - -public class CpuLimitConfigInitializer { - private static final ILog LOGGER = LogManager.getLogger(CpuLimitConfigInitializer.class); - private static final String CONFIG_FILE_NAME = "/config/apm-trace-cpu-limit-plugin.config"; - private static final String ENV_KEY_PREFIX = "skywalking."; - - public static void initialize() { - try (final InputStream configFileStream = loadConfigFromAgentFolder()) { - Properties properties = new Properties(); - properties.load(configFileStream); - for (String key : properties.stringPropertyNames()) { - String value = (String) properties.get(key); - properties.put(key, PropertyPlaceholderHelper.INSTANCE.replacePlaceholders(value, properties)); - } - ConfigInitializer.initialize(properties, CpuLimitConfig.class); - } catch (Exception e) { - LOGGER.error(e, "Failed to read the config file, skywalking is going to run in default config."); - } - - try { - overrideConfigBySystemProp(); - } catch (Exception e) { - LOGGER.error(e, "Failed to read the system env."); - } - } - - private static void overrideConfigBySystemProp() throws IllegalAccessException { - Properties properties = new Properties(); - Properties systemProperties = System.getProperties(); - for (final Map.Entry prop : systemProperties.entrySet()) { - if (prop.getKey().toString().startsWith(ENV_KEY_PREFIX)) { - String realKey = prop.getKey().toString().substring(ENV_KEY_PREFIX.length()); - properties.put(realKey, prop.getValue()); - } - } - - if (!properties.isEmpty()) { - ConfigInitializer.initialize(properties, CpuLimitConfig.class); - } - } - - /** - * Load the config file, where the agent jar is. - * - * @return the config file {@link InputStream}, or null if not needEnhance. - */ - private static InputStream loadConfigFromAgentFolder() throws AgentPackageNotFoundException, ConfigNotFoundException { - File configFile = new File(AgentPackagePath.getPath(), CONFIG_FILE_NAME); - if (configFile.exists() && configFile.isFile()) { - try { - LOGGER.info("Ignore config file found in {}.", configFile); - return new FileInputStream(configFile); - } catch (FileNotFoundException e) { - throw new ConfigNotFoundException("Fail to load apm-trace-cpu-limit-plugin.config", e); - } - } - throw new ConfigNotFoundException("Fail to load cpu limit config file."); - } -} diff --git a/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/pom.xml b/apm-sniffer/optional-plugins/trace-sampler-cpu-policy-plugin/pom.xml similarity index 96% rename from apm-sniffer/optional-plugins/trace-cpu-limit-plugin/pom.xml rename to apm-sniffer/optional-plugins/trace-sampler-cpu-policy-plugin/pom.xml index f3b54fc2fa..0756903705 100644 --- a/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/pom.xml +++ b/apm-sniffer/optional-plugins/trace-sampler-cpu-policy-plugin/pom.xml @@ -24,7 +24,7 @@ 4.0.0 - apm-trace-cpu-limit-plugin + trace-sampler-cpu-policy-plugin jar apm-trace-cpu-limit-plugin diff --git a/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/TraceCpuLimitExtendService.java b/apm-sniffer/optional-plugins/trace-sampler-cpu-policy-plugin/src/main/java/org/apache/skywalking/apm/plugin/cpu/policy/TraceSamplerCpuPolicyExtendService.java similarity index 78% rename from apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/TraceCpuLimitExtendService.java rename to apm-sniffer/optional-plugins/trace-sampler-cpu-policy-plugin/src/main/java/org/apache/skywalking/apm/plugin/cpu/policy/TraceSamplerCpuPolicyExtendService.java index f55adfd0bb..da8749a8be 100644 --- a/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/TraceCpuLimitExtendService.java +++ b/apm-sniffer/optional-plugins/trace-sampler-cpu-policy-plugin/src/main/java/org/apache/skywalking/apm/plugin/cpu/policy/TraceSamplerCpuPolicyExtendService.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.trace.cpu.limit; +package org.apache.skywalking.apm.plugin.cpu.policy; import org.apache.skywalking.apm.agent.core.boot.OverrideImplementor; import org.apache.skywalking.apm.agent.core.boot.ServiceManager; @@ -24,12 +24,11 @@ import org.apache.skywalking.apm.agent.core.logging.api.ILog; import org.apache.skywalking.apm.agent.core.logging.api.LogManager; import org.apache.skywalking.apm.agent.core.sampling.SamplingService; -import org.apache.skywalking.apm.plugin.trace.cpu.limit.conf.CpuLimitConfig; -import org.apache.skywalking.apm.plugin.trace.cpu.limit.conf.CpuLimitConfigInitializer; +import org.apache.skywalking.apm.plugin.cpu.policy.conf.TraceSamplerCpuPolicyPluginConfig; @OverrideImplementor(SamplingService.class) -public class TraceCpuLimitExtendService extends SamplingService { - private static final ILog LOGGER = LogManager.getLogger(TraceCpuLimitExtendService.class); +public class TraceSamplerCpuPolicyExtendService extends SamplingService { + private static final ILog LOGGER = LogManager.getLogger(TraceSamplerCpuPolicyExtendService.class); private volatile boolean cpuUsagePercentLimitOn = false; private volatile JVMService jvmService; @@ -42,9 +41,8 @@ public void prepare() { @Override public void boot() { super.boot(); - CpuLimitConfigInitializer.initialize(); - if (CpuLimitConfig.Trace.SAMPLE_CPU_USAGE_PERCENT_LIMIT > 0) { - LOGGER.info("TraceCpuLimitExtendService cpu usage percent limit open"); + if (TraceSamplerCpuPolicyPluginConfig.Plugin.CpuPolicy.SAMPLE_CPU_USAGE_PERCENT_LIMIT > 0) { + LOGGER.info("TraceSamplerCpuPolicyExtendService cpu usage percent limit open"); jvmService = ServiceManager.INSTANCE.findService(JVMService.class); cpuUsagePercentLimitOn = true; } @@ -63,7 +61,7 @@ public void shutdown() { public boolean trySampling(final String operationName) { if (cpuUsagePercentLimitOn) { double cpuUsagePercent = jvmService.getCpuUsagePercent(); - if (cpuUsagePercent > CpuLimitConfig.Trace.SAMPLE_CPU_USAGE_PERCENT_LIMIT) { + if (cpuUsagePercent > TraceSamplerCpuPolicyPluginConfig.Plugin.CpuPolicy.SAMPLE_CPU_USAGE_PERCENT_LIMIT) { return false; } } diff --git a/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/conf/CpuLimitConfig.java b/apm-sniffer/optional-plugins/trace-sampler-cpu-policy-plugin/src/main/java/org/apache/skywalking/apm/plugin/cpu/policy/conf/TraceSamplerCpuPolicyPluginConfig.java similarity index 67% rename from apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/conf/CpuLimitConfig.java rename to apm-sniffer/optional-plugins/trace-sampler-cpu-policy-plugin/src/main/java/org/apache/skywalking/apm/plugin/cpu/policy/conf/TraceSamplerCpuPolicyPluginConfig.java index 27ab93d37a..5878f8a5f7 100644 --- a/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/cpu/limit/conf/CpuLimitConfig.java +++ b/apm-sniffer/optional-plugins/trace-sampler-cpu-policy-plugin/src/main/java/org/apache/skywalking/apm/plugin/cpu/policy/conf/TraceSamplerCpuPolicyPluginConfig.java @@ -16,11 +16,15 @@ * */ -package org.apache.skywalking.apm.plugin.trace.cpu.limit.conf; +package org.apache.skywalking.apm.plugin.cpu.policy.conf; -public class CpuLimitConfig { +import org.apache.skywalking.apm.agent.core.boot.PluginConfig; - public static class Trace { - public static double SAMPLE_CPU_USAGE_PERCENT_LIMIT = -1; +public class TraceSamplerCpuPolicyPluginConfig { + public static class Plugin { + @PluginConfig(root = TraceSamplerCpuPolicyPluginConfig.class) + public static class CpuPolicy { + public static double SAMPLE_CPU_USAGE_PERCENT_LIMIT = -1; + } } } diff --git a/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService b/apm-sniffer/optional-plugins/trace-sampler-cpu-policy-plugin/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService similarity index 90% rename from apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService rename to apm-sniffer/optional-plugins/trace-sampler-cpu-policy-plugin/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService index 46dd1104b3..64f2baa7e2 100644 --- a/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService +++ b/apm-sniffer/optional-plugins/trace-sampler-cpu-policy-plugin/src/main/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService @@ -16,4 +16,4 @@ # # -org.apache.skywalking.apm.plugin.trace.cpu.limit.TraceCpuLimitExtendService +org.apache.skywalking.apm.plugin.cpu.policy.TraceSamplerCpuPolicyExtendService diff --git a/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/test/resources/org.apache.skywalking.apm.agent.core.boot.BootService b/apm-sniffer/optional-plugins/trace-sampler-cpu-policy-plugin/src/test/resources/org.apache.skywalking.apm.agent.core.boot.BootService similarity index 90% rename from apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/test/resources/org.apache.skywalking.apm.agent.core.boot.BootService rename to apm-sniffer/optional-plugins/trace-sampler-cpu-policy-plugin/src/test/resources/org.apache.skywalking.apm.agent.core.boot.BootService index 46dd1104b3..64f2baa7e2 100644 --- a/apm-sniffer/optional-plugins/trace-cpu-limit-plugin/src/test/resources/org.apache.skywalking.apm.agent.core.boot.BootService +++ b/apm-sniffer/optional-plugins/trace-sampler-cpu-policy-plugin/src/test/resources/org.apache.skywalking.apm.agent.core.boot.BootService @@ -16,4 +16,4 @@ # # -org.apache.skywalking.apm.plugin.trace.cpu.limit.TraceCpuLimitExtendService +org.apache.skywalking.apm.plugin.cpu.policy.TraceSamplerCpuPolicyExtendService From bd8cab2fc14cec93f14f97ff3a92efee782bc42a Mon Sep 17 00:00:00 2001 From: yuzhongyu Date: Sun, 24 Apr 2022 18:02:59 +0800 Subject: [PATCH 4/6] update trace-sampler-cpu-policy-plugin parent version --- .../optional-plugins/trace-sampler-cpu-policy-plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apm-sniffer/optional-plugins/trace-sampler-cpu-policy-plugin/pom.xml b/apm-sniffer/optional-plugins/trace-sampler-cpu-policy-plugin/pom.xml index 0756903705..c33f638868 100644 --- a/apm-sniffer/optional-plugins/trace-sampler-cpu-policy-plugin/pom.xml +++ b/apm-sniffer/optional-plugins/trace-sampler-cpu-policy-plugin/pom.xml @@ -20,7 +20,7 @@ optional-plugins org.apache.skywalking - 8.10.0-SNAPSHOT + 8.11.0-SNAPSHOT 4.0.0 From 7ec1269a47d91d5b2d5da64c254dd41b81fcf9bb Mon Sep 17 00:00:00 2001 From: yuzhongyu Date: Mon, 25 Apr 2022 14:17:41 +0800 Subject: [PATCH 5/6] update CHANGES.md and add doc with agent.config --- CHANGES.md | 1 + .../org/apache/skywalking/apm/agent/core/jvm/JVMService.java | 1 - apm-sniffer/config/agent.config | 2 ++ docs/en/setup/service-agent/java-agent/Optional-plugins.md | 3 ++- docs/en/setup/service-agent/java-agent/configurations.md | 1 + 5 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index bf08b72c4d..7024e06c47 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ Release Notes. * Remove redundant `shade.package` property. * Add servicecomb-2.x plugin and Testcase. * Fix NPE in gateway plugin when the timer triggers webflux webclient call. +* Add optional plugin trace-sampler-cpu-policy-plugin. #### Documentation diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/JVMService.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/JVMService.java index e70f7c8a18..beca07afa5 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/JVMService.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/JVMService.java @@ -47,7 +47,6 @@ public class JVMService implements BootService, Runnable { private volatile ScheduledFuture collectMetricFuture; private volatile ScheduledFuture sendMetricFuture; private JVMMetricsSender sender; - private volatile double cpuUsagePercent; @Override diff --git a/apm-sniffer/config/agent.config b/apm-sniffer/config/agent.config index 08b54f6334..56ba54364f 100755 --- a/apm-sniffer/config/agent.config +++ b/apm-sniffer/config/agent.config @@ -270,3 +270,5 @@ plugin.neo4j.trace_cypher_parameters=${SW_PLUGIN_NEO4J_TRACE_CYPHER_PARAMETERS:f plugin.neo4j.cypher_parameters_max_length=${SW_PLUGIN_NEO4J_CYPHER_PARAMETERS_MAX_LENGTH:512} # If set to positive number, the `db.statement` would be truncated to this length, otherwise it would be completely saved, which may cause performance problem. plugin.neo4j.cypher_body_max_length=${SW_PLUGIN_NEO4J_CYPHER_BODY_MAX_LENGTH:2048} +# If set to positive number and activate `trace sampler cpu policy plugin`, the trace will not be sampled when agent process cpu usage percent is greater than `plugin.cpupolicy.sample_cpu_usage_percent_limit`. +plugin.cpupolicy.sample_cpu_usage_percent_limit=${SW_SAMPLE_CPU_USAGE_PERCENT_LIMIT:-1} diff --git a/docs/en/setup/service-agent/java-agent/Optional-plugins.md b/docs/en/setup/service-agent/java-agent/Optional-plugins.md index 853e848469..07925cf9f5 100644 --- a/docs/en/setup/service-agent/java-agent/Optional-plugins.md +++ b/docs/en/setup/service-agent/java-agent/Optional-plugins.md @@ -20,4 +20,5 @@ Now, we have the following known optional plugins. * Plugin of guava-cache in the optional plugin folder. The reason for being an optional plugin is, this plugin enhanced cache framework, generates large number of local spans, which have a potential performance impact. * Plugin of fastjson serialization lib in optional plugin folder. * Plugin of jackson serialization lib in optional plugin folder. -* Plugin of Apache ShenYu(incubating) Gateway 2.4.x in optional plugin folder. Please only activate this plugin when you install agent in Apache ShenYu Gateway. \ No newline at end of file +* Plugin of Apache ShenYu(incubating) Gateway 2.4.x in optional plugin folder. Please only activate this plugin when you install agent in Apache ShenYu Gateway. +* Plugin of trace sampler cpu policy in the optional plugin folder. Please only activate this plugin when you need limit agent sample when the agent process cpu usage is too high. diff --git a/docs/en/setup/service-agent/java-agent/configurations.md b/docs/en/setup/service-agent/java-agent/configurations.md index a9b27f516f..9fd5801f52 100644 --- a/docs/en/setup/service-agent/java-agent/configurations.md +++ b/docs/en/setup/service-agent/java-agent/configurations.md @@ -110,6 +110,7 @@ This is the properties list supported in `agent/config/agent.config`. | `plugin.neo4j.trace_cypher_parameters` | If set to true, the parameters of the cypher would be collected. | SW_PLUGIN_NEO4J_TRACE_CYPHER_PARAMETERS | `false` | | `plugin.neo4j.cypher_parameters_max_length` | If set to positive number, the `db.cypher.parameters` would be truncated to this length, otherwise it would be completely saved, which may cause performance problem. | SW_PLUGIN_NEO4J_CYPHER_PARAMETERS_MAX_LENGTH | `512` | | `plugin.neo4j.cypher_body_max_length` | If set to positive number, the `db.statement` would be truncated to this length, otherwise it would be completely saved, which may cause performance problem. | SW_PLUGIN_NEO4J_CYPHER_BODY_MAX_LENGTH | `2048` | +| `plugin.cpupolicy.sample_cpu_usage_percent_limit` | If set to positive number and activate `trace sampler cpu policy plugin`, the trace will not be sampled when agent process cpu usage percent is greater than `plugin.cpupolicy.sample_cpu_usage_percent_limit`. | SW_SAMPLE_CPU_USAGE_PERCENT_LIMIT | `-1` | # Dynamic Configurations All configurations above are static, if you need to change some agent settings at runtime, please read [CDS - Configuration Discovery Service document](configuration-discovery.md) for more details. From 1db93917324af9a3fb113c805db19c418afccdb4 Mon Sep 17 00:00:00 2001 From: yuzhongyu Date: Mon, 25 Apr 2022 16:26:52 +0800 Subject: [PATCH 6/6] update doc --- CHANGES.md | 2 +- apm-sniffer/config/agent.config | 2 +- docs/en/setup/service-agent/java-agent/Optional-plugins.md | 2 +- docs/en/setup/service-agent/java-agent/configurations.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 7024e06c47..23f81e43e8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,7 +10,7 @@ Release Notes. * Remove redundant `shade.package` property. * Add servicecomb-2.x plugin and Testcase. * Fix NPE in gateway plugin when the timer triggers webflux webclient call. -* Add optional plugin trace-sampler-cpu-policy-plugin. +* Add an optional plugin, trace-sampler-cpu-policy-plugin, which could disable trace collecting in high CPU load. #### Documentation diff --git a/apm-sniffer/config/agent.config b/apm-sniffer/config/agent.config index 56ba54364f..e3d545599b 100755 --- a/apm-sniffer/config/agent.config +++ b/apm-sniffer/config/agent.config @@ -270,5 +270,5 @@ plugin.neo4j.trace_cypher_parameters=${SW_PLUGIN_NEO4J_TRACE_CYPHER_PARAMETERS:f plugin.neo4j.cypher_parameters_max_length=${SW_PLUGIN_NEO4J_CYPHER_PARAMETERS_MAX_LENGTH:512} # If set to positive number, the `db.statement` would be truncated to this length, otherwise it would be completely saved, which may cause performance problem. plugin.neo4j.cypher_body_max_length=${SW_PLUGIN_NEO4J_CYPHER_BODY_MAX_LENGTH:2048} -# If set to positive number and activate `trace sampler cpu policy plugin`, the trace will not be sampled when agent process cpu usage percent is greater than `plugin.cpupolicy.sample_cpu_usage_percent_limit`. +# If set to a positive number and activate `trace sampler CPU policy plugin`, the trace would not be collected when agent process CPU usage percent is greater than `plugin.cpupolicy.sample_cpu_usage_percent_limit`. plugin.cpupolicy.sample_cpu_usage_percent_limit=${SW_SAMPLE_CPU_USAGE_PERCENT_LIMIT:-1} diff --git a/docs/en/setup/service-agent/java-agent/Optional-plugins.md b/docs/en/setup/service-agent/java-agent/Optional-plugins.md index 07925cf9f5..ffc684900f 100644 --- a/docs/en/setup/service-agent/java-agent/Optional-plugins.md +++ b/docs/en/setup/service-agent/java-agent/Optional-plugins.md @@ -21,4 +21,4 @@ Now, we have the following known optional plugins. * Plugin of fastjson serialization lib in optional plugin folder. * Plugin of jackson serialization lib in optional plugin folder. * Plugin of Apache ShenYu(incubating) Gateway 2.4.x in optional plugin folder. Please only activate this plugin when you install agent in Apache ShenYu Gateway. -* Plugin of trace sampler cpu policy in the optional plugin folder. Please only activate this plugin when you need limit agent sample when the agent process cpu usage is too high. +* Plugin of trace sampler CPU policy in the optional plugin folder. Please only activate this plugin when you need to disable trace collecting when the agent process CPU usage is too high(over threshold). diff --git a/docs/en/setup/service-agent/java-agent/configurations.md b/docs/en/setup/service-agent/java-agent/configurations.md index 9fd5801f52..54562d7eea 100644 --- a/docs/en/setup/service-agent/java-agent/configurations.md +++ b/docs/en/setup/service-agent/java-agent/configurations.md @@ -110,7 +110,7 @@ This is the properties list supported in `agent/config/agent.config`. | `plugin.neo4j.trace_cypher_parameters` | If set to true, the parameters of the cypher would be collected. | SW_PLUGIN_NEO4J_TRACE_CYPHER_PARAMETERS | `false` | | `plugin.neo4j.cypher_parameters_max_length` | If set to positive number, the `db.cypher.parameters` would be truncated to this length, otherwise it would be completely saved, which may cause performance problem. | SW_PLUGIN_NEO4J_CYPHER_PARAMETERS_MAX_LENGTH | `512` | | `plugin.neo4j.cypher_body_max_length` | If set to positive number, the `db.statement` would be truncated to this length, otherwise it would be completely saved, which may cause performance problem. | SW_PLUGIN_NEO4J_CYPHER_BODY_MAX_LENGTH | `2048` | -| `plugin.cpupolicy.sample_cpu_usage_percent_limit` | If set to positive number and activate `trace sampler cpu policy plugin`, the trace will not be sampled when agent process cpu usage percent is greater than `plugin.cpupolicy.sample_cpu_usage_percent_limit`. | SW_SAMPLE_CPU_USAGE_PERCENT_LIMIT | `-1` | +| `plugin.cpupolicy.sample_cpu_usage_percent_limit` | If set to a positive number and activate `trace sampler CPU policy plugin`, the trace would not be collected when agent process CPU usage percent is greater than `plugin.cpupolicy.sample_cpu_usage_percent_limit`. | SW_SAMPLE_CPU_USAGE_PERCENT_LIMIT | `-1` | # Dynamic Configurations All configurations above are static, if you need to change some agent settings at runtime, please read [CDS - Configuration Discovery Service document](configuration-discovery.md) for more details.