You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ta...@apache.org on 2021/01/10 07:50:31 UTC
[skywalking] 01/01: Support trace path ignore with patterns match.
This is an automated email from the ASF dual-hosted git repository.
tanjian pushed a commit to branch feature-traceignore-in-oap
in repository https://gitbox.apache.org/repos/asf/skywalking.git
commit b3e1aa66cb660fc9618a99efbb8fd38857872145
Author: JaredTan95 <ji...@daocloud.io>
AuthorDate: Sun Jan 10 15:49:58 2021 +0800
Support trace path ignore with patterns match.
- Bring agent trace ignore feature to OAP and support dynamic update patterns.
---
CHANGES.md | 1 +
.../apm/util}/matcher/FastPathMatcher.java | 2 +-
.../apm/util}/matcher/TracePathMatcher.java | 2 +-
.../trace/ignore/TraceIgnoreExtendService.java | 4 +-
.../plugin/trace/ignore/TracePathMatcherTest.java | 4 +-
docs/en/setup/backend/backend-receivers.md | 151 +++++++++++++++------
.../analyzer/provider/AnalyzerModuleConfig.java | 18 ++-
.../analyzer/provider/AnalyzerModuleProvider.java | 11 +-
.../provider/trace/TraceIgnorePathWatcher.java | 70 ++++++++++
.../parser/listener/SegmentAnalysisListener.java | 15 ++
.../parser/listener/TraceIgnorePathHandler.java | 58 ++++++++
.../provider/trace/TraceIgnorePathWatcherTest.java | 113 +++++++++++++++
.../src/main/resources/application.yml | 1 +
13 files changed, 397 insertions(+), 53 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index c48826f..63b48d8 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -56,6 +56,7 @@ Release Notes.
* Improve ReadWriteSafeCache concurrency read-write performance
* Fix bug that if use JSON as InfluxDB.ResponseFormat then NumberFormatException maybe occur.
* Fix `timeBucket` not taking effect in EqualsAndHashCode annotation of some relationship metrics.
+* Support trace path ignore with patterns match.
#### UI
* Fix un-removed tags in trace query.
diff --git a/apm-sniffer/optional-plugins/trace-ignore-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/ignore/matcher/FastPathMatcher.java b/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/matcher/FastPathMatcher.java
similarity index 98%
rename from apm-sniffer/optional-plugins/trace-ignore-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/ignore/matcher/FastPathMatcher.java
rename to apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/matcher/FastPathMatcher.java
index 4e91542..2d3ab78 100644
--- a/apm-sniffer/optional-plugins/trace-ignore-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/ignore/matcher/FastPathMatcher.java
+++ b/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/matcher/FastPathMatcher.java
@@ -16,7 +16,7 @@
*
*/
-package org.apache.skywalking.apm.plugin.trace.ignore.matcher;
+package org.apache.skywalking.apm.util.matcher;
public class FastPathMatcher implements TracePathMatcher {
@Override
diff --git a/apm-sniffer/optional-plugins/trace-ignore-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/ignore/matcher/TracePathMatcher.java b/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/matcher/TracePathMatcher.java
similarity index 93%
rename from apm-sniffer/optional-plugins/trace-ignore-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/ignore/matcher/TracePathMatcher.java
rename to apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/matcher/TracePathMatcher.java
index ad39434..b9afcfa 100644
--- a/apm-sniffer/optional-plugins/trace-ignore-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/ignore/matcher/TracePathMatcher.java
+++ b/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/matcher/TracePathMatcher.java
@@ -16,7 +16,7 @@
*
*/
-package org.apache.skywalking.apm.plugin.trace.ignore.matcher;
+package org.apache.skywalking.apm.util.matcher;
public interface TracePathMatcher {
diff --git a/apm-sniffer/optional-plugins/trace-ignore-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnoreExtendService.java b/apm-sniffer/optional-plugins/trace-ignore-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnoreExtendService.java
index f826838..bae7b9c 100644
--- a/apm-sniffer/optional-plugins/trace-ignore-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnoreExtendService.java
+++ b/apm-sniffer/optional-plugins/trace-ignore-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnoreExtendService.java
@@ -24,9 +24,9 @@ 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.ignore.conf.IgnoreConfig;
import org.apache.skywalking.apm.plugin.trace.ignore.conf.IgnoreConfigInitializer;
-import org.apache.skywalking.apm.plugin.trace.ignore.matcher.FastPathMatcher;
-import org.apache.skywalking.apm.plugin.trace.ignore.matcher.TracePathMatcher;
import org.apache.skywalking.apm.util.StringUtil;
+import org.apache.skywalking.apm.util.matcher.FastPathMatcher;
+import org.apache.skywalking.apm.util.matcher.TracePathMatcher;
@OverrideImplementor(SamplingService.class)
public class TraceIgnoreExtendService extends SamplingService {
diff --git a/apm-sniffer/optional-plugins/trace-ignore-plugin/src/test/java/org/apache/skywalking/apm/plugin/trace/ignore/TracePathMatcherTest.java b/apm-sniffer/optional-plugins/trace-ignore-plugin/src/test/java/org/apache/skywalking/apm/plugin/trace/ignore/TracePathMatcherTest.java
index 7a8cc5e..04d2ea5 100644
--- a/apm-sniffer/optional-plugins/trace-ignore-plugin/src/test/java/org/apache/skywalking/apm/plugin/trace/ignore/TracePathMatcherTest.java
+++ b/apm-sniffer/optional-plugins/trace-ignore-plugin/src/test/java/org/apache/skywalking/apm/plugin/trace/ignore/TracePathMatcherTest.java
@@ -18,8 +18,8 @@
package org.apache.skywalking.apm.plugin.trace.ignore;
-import org.apache.skywalking.apm.plugin.trace.ignore.matcher.FastPathMatcher;
-import org.apache.skywalking.apm.plugin.trace.ignore.matcher.TracePathMatcher;
+import org.apache.skywalking.apm.util.matcher.FastPathMatcher;
+import org.apache.skywalking.apm.util.matcher.TracePathMatcher;
import org.junit.Assert;
import org.junit.Test;
diff --git a/docs/en/setup/backend/backend-receivers.md b/docs/en/setup/backend/backend-receivers.md
index cdcd876..b0b6068 100644
--- a/docs/en/setup/backend/backend-receivers.md
+++ b/docs/en/setup/backend/backend-receivers.md
@@ -1,16 +1,18 @@
-
# Choose receiver
-Receiver is a concept in SkyWalking backend. All modules, which are responsible for receiving telemetry
-or tracing data from other being monitored system, are all being called **Receiver**. If you are looking for the pull mode,
-Take a look at [fetcher document](backend-fetcher.md).
+
+Receiver is a concept in SkyWalking backend. All modules, which are responsible for receiving telemetry or tracing data
+from other being monitored system, are all being called **Receiver**. If you are looking for the pull mode, Take a look
+at [fetcher document](backend-fetcher.md).
We have following receivers, and `default` implementors are provided in our Apache distribution.
+
1. **receiver-trace**. gRPC and HTTPRestful services to accept SkyWalking format traces.
1. **receiver-register**. gRPC and HTTPRestful services to provide service, service instance and endpoint register.
1. **service-mesh**. gRPC services accept data from inbound mesh probes.
1. **receiver-jvm**. gRPC services accept JVM metrics data.
-1. **envoy-metric**. Envoy `metrics_service` and `ALS(access log service)` supported by this receiver. OAL script support all GAUGE type metrics.
-1. **receiver-profile**. gRPC services accept profile task status and snapshot reporter.
+1. **envoy-metric**. Envoy `metrics_service` and `ALS(access log service)` supported by this receiver. OAL script
+ support all GAUGE type metrics.
+1. **receiver-profile**. gRPC services accept profile task status and snapshot reporter.
1. **receiver_zipkin**. See [details](#zipkin-receiver).
1. **receiver_jaeger**. See [details](#jaeger-receiver).
1. **receiver-otel**. See [details](#opentelemetry-receiver).
@@ -18,7 +20,36 @@ We have following receivers, and `default` implementors are provided in our Apac
1. **receiver-browser**. gRPC services to accept browser performance data and error log.
The sample settings of these receivers should be already in default `application.yml`, and also list here
+
```yaml
+agent-analyzer:
+ selector: ${SW_AGENT_ANALYZER:default}
+ default:
+ sampleRate: ${SW_TRACE_SAMPLE_RATE:10000} # The sample rate precision is 1/10000. 10000 means 100% sample in default.
+ traceIgnorePathPatterns: ${SW_TRACE_IGNORE_PATH_PATTERNS:""} # Ignore matched trace. The current matching rules follow `Ant Path` match style , like `/path/*`, `/path/**`, `/path/?`, multiple paths should be separated by `,`.
+ slowDBAccessThreshold: ${SW_SLOW_DB_THRESHOLD:default:200,mongodb:100} # The slow database access thresholds. Unit ms.
+ forceSampleErrorSegment: ${SW_FORCE_SAMPLE_ERROR_SEGMENT:true} # When sampling mechanism active, this config can open(true) force save some error segment. true is default.
+ segmentStatusAnalysisStrategy: ${SW_SEGMENT_STATUS_ANALYSIS_STRATEGY:FROM_SPAN_STATUS} # Determine the final segment status from the status of spans. Available values are `FROM_SPAN_STATUS` , `FROM_ENTRY_SPAN` and `FROM_FIRST_SPAN`. `FROM_SPAN_STATUS` represents the segment status would be error if any span is in error status. `FROM_ENTRY_SPAN` means the segment status would be determined by the status of entry spans only. `FROM_FIRST_SPAN` means the segment status would be determine [...]
+ # Nginx and Envoy agents can't get the real remote address.
+ # Exit spans with the component in the list would not generate the client-side instance relation metrics.
+ noUpstreamRealAddressAgents: ${SW_NO_UPSTREAM_REAL_ADDRESS:6000,9000}
+ slowTraceSegmentThreshold: ${SW_SLOW_TRACE_SEGMENT_THRESHOLD:-1} # Setting this threshold about the latency would make the slow trace segments sampled if they cost more time, even the sampling mechanism activated. The default value is `-1`, which means would not sample slow traces. Unit, millisecond.
+ meterAnalyzerActiveFiles: ${SW_METER_ANALYZER_ACTIVE_FILES:spring-sleuth.yaml} # Which files could be meter analyzed, files split by ","
+
+receiver-sharing-server:
+ selector: ${SW_RECEIVER_SHARING_SERVER:default}
+ default:
+ # For Jetty server
+ restHost: ${SW_RECEIVER_SHARING_REST_HOST:0.0.0.0}
+ restPort: ${SW_RECEIVER_SHARING_REST_PORT:0}
+ contextPath: ${SW_RECEIVER_SHARING_REST_CONTEXT_PATH:/}
+ restMinThreads: ${SW_RECEIVER_SHARING_JETTY_MIN_THREADS:1}
+ ......
+ # For gRPC server
+ gRPCHost: ${SW_RECEIVER_GRPC_HOST:0.0.0.0}
+ gRPCPort: ${SW_RECEIVER_GRPC_PORT:0}
+ ......
+ authentication: ${SW_AUTHENTICATION:""}
receiver-register:
selector: ${SW_RECEIVER_REGISTER:default}
default:
@@ -31,6 +62,14 @@ receiver-jvm:
selector: ${SW_RECEIVER_JVM:default}
default:
+receiver-clr:
+ selector: ${SW_RECEIVER_CLR:default}
+ default:
+
+receiver-profile:
+ selector: ${SW_RECEIVER_PROFILE:default}
+ default:
+
service-mesh:
selector: ${SW_SERVICE_MESH:default}
default:
@@ -40,33 +79,57 @@ envoy-metric:
default:
acceptMetricsService: ${SW_ENVOY_METRIC_SERVICE:true}
alsHTTPAnalysis: ${SW_ENVOY_METRIC_ALS_HTTP_ANALYSIS:""}
+ k8sServiceNameRule: ${K8S_SERVICE_NAME_RULE:"${service.metadata.name}"}
+
+prometheus-fetcher:
+ selector: ${SW_PROMETHEUS_FETCHER:-}
+ default:
+ enabledRules: ${SW_PROMETHEUS_FETCHER_ENABLED_RULES:"self"}
+
+kafka-fetcher:
+ selector: ${SW_KAFKA_FETCHER:-}
+ default:
+ bootstrapServers: ${SW_KAFKA_FETCHER_SERVERS:localhost:9092}
+ ......
+ kafkaHandlerThreadPoolSize: ${SW_KAFKA_HANDLER_THREAD_POOL_SIZE:-1}
+ kafkaHandlerThreadPoolQueueSize: ${SW_KAFKA_HANDLER_THREAD_POOL_QUEUE_SIZE:-1}
+
+receiver-meter:
+ selector: ${SW_RECEIVER_METER:default}
+ default:
+
+receiver-otel:
+ selector: ${SW_OTEL_RECEIVER:-}
+ default:
+ enabledHandlers: ${SW_OTEL_RECEIVER_ENABLED_HANDLERS:"oc"}
+ enabledOcRules: ${SW_OTEL_RECEIVER_ENABLED_OC_RULES:"istio-controlplane"}
receiver_zipkin:
selector: ${SW_RECEIVER_ZIPKIN:-}
default:
host: ${SW_RECEIVER_ZIPKIN_HOST:0.0.0.0}
port: ${SW_RECEIVER_ZIPKIN_PORT:9411}
- contextPath: ${SW_RECEIVER_ZIPKIN_CONTEXT_PATH:/}
- jettyMinThreads: ${SW_RECEIVER_ZIPKIN_JETTY_MIN_THREADS:1}
- jettyMaxThreads: ${SW_RECEIVER_ZIPKIN_JETTY_MAX_THREADS:200}
- jettyIdleTimeOut: ${SW_RECEIVER_ZIPKIN_JETTY_IDLE_TIMEOUT:30000}
- jettyAcceptorPriorityDelta: ${SW_RECEIVER_ZIPKIN_JETTY_DELTA:0}
+ ......
jettyAcceptQueueSize: ${SW_RECEIVER_ZIPKIN_QUEUE_SIZE:0}
-receiver-profile:
- selector: ${SW_RECEIVER_PROFILE:default}
+receiver_jaeger:
+ selector: ${SW_RECEIVER_JAEGER:-}
default:
+ gRPCHost: ${SW_RECEIVER_JAEGER_HOST:0.0.0.0}
+ gRPCPort: ${SW_RECEIVER_JAEGER_PORT:14250}
receiver-browser:
selector: ${SW_RECEIVER_BROWSER:default}
default:
+ # The sample rate precision is 1/10000. 10000 means 100% sample in default.
sampleRate: ${SW_RECEIVER_BROWSER_SAMPLE_RATE:10000}
```
## gRPC/HTTP server for receiver
-In default, all gRPC/HTTP services should be served at `core/gRPC` and `core/rest`.
-But the `receiver-sharing-server` module provide a way to make all receivers serving at
-different ip:port, if you set them explicitly.
+
+In default, all gRPC/HTTP services should be served at `core/gRPC` and `core/rest`. But the `receiver-sharing-server`
+module provide a way to make all receivers serving at different ip:port, if you set them explicitly.
+
```yaml
receiver-sharing-server:
selector: ${SW_RECEIVER_SHARING_SERVER:default}
@@ -81,20 +144,21 @@ receiver-sharing-server:
jettyAcceptQueueSize: ${SW_RECEIVER_SHARING_JETTY_QUEUE_SIZE:0}
```
-Notice, if you add these settings, make sure they are not as same as core module,
-because gRPC/HTTP servers of core are still used for UI and OAP internal communications.
+Notice, if you add these settings, make sure they are not as same as core module, because gRPC/HTTP servers of core are
+still used for UI and OAP internal communications.
## Zipkin receiver
+
Zipkin receiver could work in two different mode.
-1. Tracing mode(default). Tracing mode is that, skywalking OAP acts like zipkin collector,
-fully supports Zipkin v1/v2 formats through HTTP service,
-also provide persistence and query in skywalking UI.
-But it wouldn't analysis metrics from them. In most case, I suggest you could use this feature, when metrics come from service mesh.
-Notice, in this mode, Zipkin receiver requires `zipkin-elasticsearch` storage implementation active.
-Read [this](backend-storage.md#elasticsearch-6-with-zipkin-trace-extension) to know
-how to active.
+
+1. Tracing mode(default). Tracing mode is that, skywalking OAP acts like zipkin collector, fully supports Zipkin v1/v2
+ formats through HTTP service, also provide persistence and query in skywalking UI. But it wouldn't analysis metrics
+ from them. In most case, I suggest you could use this feature, when metrics come from service mesh. Notice, in this
+ mode, Zipkin receiver requires `zipkin-elasticsearch` storage implementation active.
+ Read [this](backend-storage.md#elasticsearch-6-with-zipkin-trace-extension) to know how to active.
Use following config to active.
+
```yaml
receiver_zipkin:
selector: ${SW_RECEIVER_ZIPKIN:-}
@@ -109,11 +173,12 @@ receiver_zipkin:
jettyAcceptQueueSize: ${SW_RECEIVER_ZIPKIN_QUEUE_SIZE:0}
```
-2. Analysis mode(Not production ready), receive Zipkin v1/v2 formats through HTTP service. Transform the trace to skywalking
-native format, and analysis like skywalking trace. This feature can't work in production env right now,
-because of Zipkin tag/endpoint value unpredictable, we can't make sure it fits production env requirements.
+2. Analysis mode(Not production ready), receive Zipkin v1/v2 formats through HTTP service. Transform the trace to
+ skywalking native format, and analysis like skywalking trace. This feature can't work in production env right now,
+ because of Zipkin tag/endpoint value unpredictable, we can't make sure it fits production env requirements.
Active `analysis mode`, you should set `needAnalysis` config.
+
```yaml
receiver_zipkin:
selector: ${SW_RECEIVER_ZIPKIN:-}
@@ -132,16 +197,18 @@ receiver_zipkin:
NOTICE, Zipkin receiver is only provided in `apache-skywalking-apm-x.y.z.tar.gz` tar.
## Jaeger receiver
-Jaeger receiver right now only works in `Tracing Mode`, and no analysis.
-Jaeger receiver provides extra gRPC host/port, if absent, sharing-server host/port will be used, then core gRPC host/port.
-Receiver requires `jaeger-elasticsearch` storage implementation active.
-Read [this](backend-storage.md#elasticsearch-6-with-jaeger-trace-extension) to know how to active.
-Right now, you need [jaeger agent](https://www.jaegertracing.io/docs/1.11/architecture/#agent) to batch
-send spans to SkyWalking oap server. Read [Jaeger Architecture](https://www.jaegertracing.io/docs/1.11/architecture/)
+Jaeger receiver right now only works in `Tracing Mode`, and no analysis. Jaeger receiver provides extra gRPC host/port,
+if absent, sharing-server host/port will be used, then core gRPC host/port. Receiver requires `jaeger-elasticsearch`
+storage implementation active. Read [this](backend-storage.md#elasticsearch-6-with-jaeger-trace-extension) to know how
+to active.
+
+Right now, you need [jaeger agent](https://www.jaegertracing.io/docs/1.11/architecture/#agent) to batch send spans to
+SkyWalking oap server. Read [Jaeger Architecture](https://www.jaegertracing.io/docs/1.11/architecture/)
to get more details.
Active the receiver.
+
```yaml
receiver_jaeger:
selector: ${SW_RECEIVER_JAEGER:-}
@@ -154,17 +221,20 @@ NOTICE, Jaeger receiver is only provided in `apache-skywalking-apm-x.y.z.tar.gz`
## OpenTelemetry receiver
-OpenTelemetry receiver supports to ingest agent metrics by meter-system. OAP can load the configuration at bootstrap.
-If the new configuration is not well-formed, OAP fails to start up. The files are located at `$CLASSPATH/otel-<handler>-rules`.
-Eg, the `oc` handler loads fules from `$CLASSPATH/otel-oc-rules`,
+OpenTelemetry receiver supports to ingest agent metrics by meter-system. OAP can load the configuration at bootstrap. If
+the new configuration is not well-formed, OAP fails to start up. The files are located
+at `$CLASSPATH/otel-<handler>-rules`. Eg, the `oc` handler loads fules from `$CLASSPATH/otel-oc-rules`,
Supported handlers:
- * `oc`: [OpenCensus](https://github.com/open-telemetry/opentelemetry-collector/blob/master/exporter/opencensusexporter/README.md) gRPC service handler.
+* `oc`: [OpenCensus](https://github.com/open-telemetry/opentelemetry-collector/blob/master/exporter/opencensusexporter/README.md)
+gRPC service handler.
The rule file should be in YAML format, defined by the scheme described in [prometheus-fetcher](./backend-fetcher.md).
-Notice, `receiver-otel` only support `group`, `defaultMetricLevel` and `metricsRules` nodes of scheme due to the push mode it opts to.
+Notice, `receiver-otel` only support `group`, `defaultMetricLevel` and `metricsRules` nodes of scheme due to the push
+mode it opts to.
To active the `oc` handler and `istio` relevant rules:
+
```yaml
receiver-otel:
selector: ${SW_OTEL_RECEIVER:default}
@@ -175,11 +245,12 @@ receiver-otel:
## Meter receiver
-Meter receiver supports accept the metrics into the meter-system. OAP can load the configuration at bootstrap.
+Meter receiver supports accept the metrics into the meter-system. OAP can load the configuration at bootstrap.
The file is written in YAML format, defined by the scheme described in [backend-meter](./backend-meter.md).
To active the `default` implementation:
+
```yaml
receiver-meter:
selector: ${SW_RECEIVER_METER:default}
diff --git a/oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/AnalyzerModuleConfig.java b/oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/AnalyzerModuleConfig.java
index f13ee99..d0e1d1d 100644
--- a/oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/AnalyzerModuleConfig.java
+++ b/oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/AnalyzerModuleConfig.java
@@ -18,11 +18,14 @@
package org.apache.skywalking.oap.server.analyzer.provider;
+import java.util.ArrayList;
+import java.util.List;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.skywalking.oap.server.analyzer.provider.trace.DBLatencyThresholdsAndWatcher;
+import org.apache.skywalking.oap.server.analyzer.provider.trace.TraceIgnorePathWatcher;
import org.apache.skywalking.oap.server.analyzer.provider.trace.TraceLatencyThresholdsAndWatcher;
import org.apache.skywalking.oap.server.analyzer.provider.trace.TraceSampleRateWatcher;
import org.apache.skywalking.oap.server.analyzer.provider.trace.UninstrumentedGatewaysConfig;
@@ -30,9 +33,6 @@ import org.apache.skywalking.oap.server.analyzer.provider.trace.parser.listener.
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.library.module.ModuleConfig;
-import java.util.ArrayList;
-import java.util.List;
-
import static org.apache.skywalking.oap.server.analyzer.provider.trace.parser.listener.strategy.SegmentStatusStrategy.FROM_SPAN_STATUS;
@Slf4j
@@ -43,6 +43,11 @@ public class AnalyzerModuleConfig extends ModuleConfig {
@Setter
@Getter
private int sampleRate = 10000;
+
+ @Setter
+ @Getter
+ private String traceIgnorePathPatterns = "";
+
/**
* Some of the agent can not have the upstream real network address, such as https://github.com/apache/skywalking-nginx-lua.
* service instance mapping and service instance client side relation are ignored.
@@ -58,7 +63,9 @@ public class AnalyzerModuleConfig extends ModuleConfig {
@Getter
private String slowDBAccessThreshold = "default:200";
/**
- * Setting this threshold about the latency would make the slow trace segments sampled if they cost more time, even the sampling mechanism activated. The default value is `-1`, which means would not sample slow traces. Unit, millisecond.
+ * Setting this threshold about the latency would make the slow trace segments sampled if they cost more time, even
+ * the sampling mechanism activated. The default value is `-1`, which means would not sample slow traces. Unit,
+ * millisecond.
*/
@Setter
@Getter
@@ -74,6 +81,9 @@ public class AnalyzerModuleConfig extends ModuleConfig {
private TraceSampleRateWatcher traceSampleRateWatcher;
@Setter
@Getter
+ private TraceIgnorePathWatcher traceIgnorePathWatcher;
+ @Setter
+ @Getter
private TraceLatencyThresholdsAndWatcher traceLatencyThresholdsAndWatcher;
/**
* Analysis trace status.
diff --git a/oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/AnalyzerModuleProvider.java b/oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/AnalyzerModuleProvider.java
index c2cce55..7b861b3 100644
--- a/oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/AnalyzerModuleProvider.java
+++ b/oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/AnalyzerModuleProvider.java
@@ -18,6 +18,7 @@
package org.apache.skywalking.oap.server.analyzer.provider;
+import java.util.List;
import lombok.Getter;
import org.apache.skywalking.oap.server.analyzer.module.AnalyzerModule;
import org.apache.skywalking.oap.server.analyzer.provider.meter.config.MeterConfig;
@@ -25,6 +26,7 @@ import org.apache.skywalking.oap.server.analyzer.provider.meter.config.MeterConf
import org.apache.skywalking.oap.server.analyzer.provider.meter.process.IMeterProcessService;
import org.apache.skywalking.oap.server.analyzer.provider.meter.process.MeterProcessService;
import org.apache.skywalking.oap.server.analyzer.provider.trace.DBLatencyThresholdsAndWatcher;
+import org.apache.skywalking.oap.server.analyzer.provider.trace.TraceIgnorePathWatcher;
import org.apache.skywalking.oap.server.analyzer.provider.trace.TraceLatencyThresholdsAndWatcher;
import org.apache.skywalking.oap.server.analyzer.provider.trace.TraceSampleRateWatcher;
import org.apache.skywalking.oap.server.analyzer.provider.trace.UninstrumentedGatewaysConfig;
@@ -46,8 +48,6 @@ import org.apache.skywalking.oap.server.library.module.ModuleStartException;
import org.apache.skywalking.oap.server.library.module.ServiceNotProvidedException;
import org.apache.skywalking.oap.server.telemetry.TelemetryModule;
-import java.util.List;
-
public class AnalyzerModuleProvider extends ModuleProvider {
@Getter
private final AnalyzerModuleConfig moduleConfig;
@@ -60,6 +60,8 @@ public class AnalyzerModuleProvider extends ModuleProvider {
@Getter
private TraceSampleRateWatcher traceSampleRateWatcher;
@Getter
+ private TraceIgnorePathWatcher traceIgnorePathWatcher;
+ @Getter
private TraceLatencyThresholdsAndWatcher traceLatencyThresholdsAndWatcher;
private List<MeterConfig> meterConfigs;
@@ -92,17 +94,20 @@ public class AnalyzerModuleProvider extends ModuleProvider {
uninstrumentedGatewaysConfig = new UninstrumentedGatewaysConfig(this);
traceSampleRateWatcher = new TraceSampleRateWatcher(this);
+ traceIgnorePathWatcher = new TraceIgnorePathWatcher(this);
traceLatencyThresholdsAndWatcher = new TraceLatencyThresholdsAndWatcher(this);
moduleConfig.setDbLatencyThresholdsAndWatcher(thresholds);
moduleConfig.setUninstrumentedGatewaysConfig(uninstrumentedGatewaysConfig);
moduleConfig.setTraceSampleRateWatcher(traceSampleRateWatcher);
+ moduleConfig.setTraceIgnorePathWatcher(traceIgnorePathWatcher);
moduleConfig.setTraceLatencyThresholdsAndWatcher(traceLatencyThresholdsAndWatcher);
segmentParserService = new SegmentParserServiceImpl(getManager(), moduleConfig);
this.registerServiceImplementation(ISegmentParserService.class, segmentParserService);
- meterConfigs = MeterConfigs.loadConfig(moduleConfig.getConfigPath(), moduleConfig.meterAnalyzerActiveFileNames());
+ meterConfigs = MeterConfigs.loadConfig(
+ moduleConfig.getConfigPath(), moduleConfig.meterAnalyzerActiveFileNames());
processService = new MeterProcessService(getManager());
this.registerServiceImplementation(IMeterProcessService.class, processService);
}
diff --git a/oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/TraceIgnorePathWatcher.java b/oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/TraceIgnorePathWatcher.java
new file mode 100644
index 0000000..5c11df4
--- /dev/null
+++ b/oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/TraceIgnorePathWatcher.java
@@ -0,0 +1,70 @@
+/*
+ * 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.oap.server.analyzer.provider.trace;
+
+import java.util.concurrent.atomic.AtomicReference;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.analyzer.module.AnalyzerModule;
+import org.apache.skywalking.oap.server.analyzer.provider.AnalyzerModuleConfig;
+import org.apache.skywalking.oap.server.configuration.api.ConfigChangeWatcher;
+import org.apache.skywalking.oap.server.library.module.ModuleProvider;
+
+@Slf4j
+public class TraceIgnorePathWatcher extends ConfigChangeWatcher {
+ private AtomicReference<String> traceIgnorePathPatterns;
+
+ public TraceIgnorePathWatcher(ModuleProvider provider) {
+ super(AnalyzerModule.NAME, provider, "traceIgnorePathPatterns");
+ traceIgnorePathPatterns = new AtomicReference<>();
+ traceIgnorePathPatterns.set(getDefaultValue());
+ }
+
+ private void activeSetting(String config) {
+ if (log.isDebugEnabled()) {
+ log.debug("Updating using new static config: {}", config);
+ }
+ try {
+ traceIgnorePathPatterns.set(config);
+ } catch (NumberFormatException ex) {
+ log.error("Cannot load traceIgnorePathPatterns from: {}", config, ex);
+ }
+ }
+
+ @Override
+ public void notify(ConfigChangeEvent value) {
+ if (EventType.DELETE.equals(value.getEventType())) {
+ activeSetting(getDefaultValue());
+ } else {
+ activeSetting(value.getNewValue());
+ }
+ }
+
+ @Override
+ public String value() {
+ return String.valueOf(traceIgnorePathPatterns.get());
+ }
+
+ private String getDefaultValue() {
+ return ((AnalyzerModuleConfig) this.getProvider().createConfigBeanIfAbsent()).getTraceIgnorePathPatterns();
+ }
+
+ public String getTraceIgnorePathPatterns() {
+ return traceIgnorePathPatterns.get();
+ }
+}
diff --git a/oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/parser/listener/SegmentAnalysisListener.java b/oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/parser/listener/SegmentAnalysisListener.java
index d27379c..4b1fe49 100644
--- a/oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/parser/listener/SegmentAnalysisListener.java
+++ b/oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/parser/listener/SegmentAnalysisListener.java
@@ -21,6 +21,7 @@ package org.apache.skywalking.oap.server.analyzer.provider.trace.parser.listener
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.apm.network.language.agent.v3.SegmentObject;
@@ -51,6 +52,7 @@ import org.apache.skywalking.oap.server.library.util.BooleanUtils;
public class SegmentAnalysisListener implements FirstAnalysisListener, EntryAnalysisListener, SegmentListener {
private final SourceReceiver sourceReceiver;
private final TraceSegmentSampler sampler;
+ private final TraceIgnorePathHandler traceIgnoreHandler;
private final boolean forceSampleErrorSegment;
private final NamingControl namingControl;
private final List<String> searchableTagKeys;
@@ -128,7 +130,12 @@ public class SegmentAnalysisListener implements FirstAnalysisListener, EntryAnal
@Override
public void parseSegment(SegmentObject segmentObject) {
segment.setTraceId(segmentObject.getTraceId());
+ AtomicReference<String> rootOperationName = new AtomicReference<>();
segmentObject.getSpansList().forEach(span -> {
+ if (span.getSpanId() == 0) {
+ rootOperationName.set(span.getOperationName());
+ }
+
if (startTimestamp == 0 || startTimestamp > span.getStartTime()) {
startTimestamp = span.getStartTime();
}
@@ -138,6 +145,11 @@ public class SegmentAnalysisListener implements FirstAnalysisListener, EntryAnal
isError = isError || segmentStatusAnalyzer.isError(span);
appendSearchableTags(span);
});
+
+ if (traceIgnoreHandler.shouldIgnore(rootOperationName.get())) {
+ sampleStatus = SAMPLE_STATUS.IGNORE;
+ }
+
final long accurateDuration = endTimestamp - startTimestamp;
duration = accurateDuration > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) accurateDuration;
@@ -191,6 +203,7 @@ public class SegmentAnalysisListener implements FirstAnalysisListener, EntryAnal
public static class Factory implements AnalysisListenerFactory {
private final SourceReceiver sourceReceiver;
private final TraceSegmentSampler sampler;
+ private final TraceIgnorePathHandler traceIgnoreHandler;
private final boolean forceSampleErrorSegment;
private final NamingControl namingControl;
private final List<String> searchTagKeys;
@@ -204,6 +217,7 @@ public class SegmentAnalysisListener implements FirstAnalysisListener, EntryAnal
.getService(ConfigService.class);
this.searchTagKeys = Arrays.asList(configService.getSearchableTracesTags().split(Const.COMMA));
this.sampler = new TraceSegmentSampler(config.getTraceSampleRateWatcher());
+ this.traceIgnoreHandler = new TraceIgnorePathHandler(config.getTraceIgnorePathWatcher());
this.forceSampleErrorSegment = config.isForceSampleErrorSegment();
this.namingControl = moduleManager.find(CoreModule.NAME)
.provider()
@@ -218,6 +232,7 @@ public class SegmentAnalysisListener implements FirstAnalysisListener, EntryAnal
return new SegmentAnalysisListener(
sourceReceiver,
sampler,
+ traceIgnoreHandler,
forceSampleErrorSegment,
namingControl,
searchTagKeys,
diff --git a/oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/parser/listener/TraceIgnorePathHandler.java b/oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/parser/listener/TraceIgnorePathHandler.java
new file mode 100644
index 0000000..f6d9146
--- /dev/null
+++ b/oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/parser/listener/TraceIgnorePathHandler.java
@@ -0,0 +1,58 @@
+/*
+ * 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.oap.server.analyzer.provider.trace.parser.listener;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.apm.util.StringUtil;
+import org.apache.skywalking.apm.util.matcher.FastPathMatcher;
+import org.apache.skywalking.apm.util.matcher.TracePathMatcher;
+import org.apache.skywalking.oap.server.analyzer.provider.trace.TraceIgnorePathWatcher;
+
+/**
+ * The sampler makes the sampling mechanism works at backend side. Sample result: [0,sampleRate) sampled, (sampleRate,~)
+ * ignored
+ */
+@Slf4j
+public class TraceIgnorePathHandler {
+ private TraceIgnorePathWatcher traceIgnorePathWatcher;
+ private static final String PATTERN_SEPARATOR = ",";
+ private TracePathMatcher pathMatcher = new FastPathMatcher();
+ private String[] patterns = new String[] {};
+
+ public TraceIgnorePathHandler(TraceIgnorePathWatcher traceIgnorePathWatcher) {
+ this.traceIgnorePathWatcher = traceIgnorePathWatcher;
+ if (StringUtil.isNotBlank(traceIgnorePathWatcher.getTraceIgnorePathPatterns())) {
+ patterns = traceIgnorePathWatcher.getTraceIgnorePathPatterns().split(PATTERN_SEPARATOR);
+ }
+ }
+
+ public boolean shouldIgnore(String operationName) {
+ if (StringUtil.isNotBlank(traceIgnorePathWatcher.getTraceIgnorePathPatterns())
+ && traceIgnorePathWatcher.getTraceIgnorePathPatterns().split(PATTERN_SEPARATOR).length > 0) {
+ for (String pattern : patterns) {
+ if (pathMatcher.match(pattern, operationName)) {
+ log.debug("operationName : {} has been Ignored", operationName);
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+}
diff --git a/oap-server/analyzer/agent-analyzer/src/test/java/org/apache/skywalking/oap/server/analyzer/provider/trace/TraceIgnorePathWatcherTest.java b/oap-server/analyzer/agent-analyzer/src/test/java/org/apache/skywalking/oap/server/analyzer/provider/trace/TraceIgnorePathWatcherTest.java
new file mode 100644
index 0000000..f123c31
--- /dev/null
+++ b/oap-server/analyzer/agent-analyzer/src/test/java/org/apache/skywalking/oap/server/analyzer/provider/trace/TraceIgnorePathWatcherTest.java
@@ -0,0 +1,113 @@
+/*
+ * 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.oap.server.analyzer.provider.trace;
+
+import java.util.Optional;
+import java.util.Set;
+import org.apache.skywalking.oap.server.analyzer.provider.AnalyzerModuleProvider;
+import org.apache.skywalking.oap.server.configuration.api.ConfigChangeWatcher;
+import org.apache.skywalking.oap.server.configuration.api.ConfigTable;
+import org.apache.skywalking.oap.server.configuration.api.ConfigWatcherRegister;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TraceIgnorePathWatcherTest {
+ private AnalyzerModuleProvider provider;
+
+ @Before
+ public void init() {
+ provider = new AnalyzerModuleProvider();
+ }
+
+ @Test
+ public void testInit() {
+ TraceIgnorePathWatcher traceIgnorePathWatcher = new TraceIgnorePathWatcher(provider);
+ Assert.assertEquals(traceIgnorePathWatcher.getTraceIgnorePathPatterns(), "");
+ Assert.assertEquals(traceIgnorePathWatcher.value(), "");
+ }
+
+ @Test(timeout = 20000)
+ public void testDynamicUpdate() throws InterruptedException {
+ ConfigWatcherRegister register = new MockConfigWatcherRegister(3);
+
+ TraceIgnorePathWatcher watcher = new TraceIgnorePathWatcher(provider);
+ register.registerConfigChangeWatcher(watcher);
+ register.start();
+
+ while (watcher.getTraceIgnorePathPatterns().equals("")) {
+ Thread.sleep(2000);
+ }
+ assertThat(watcher.getTraceIgnorePathPatterns(), is("/ignore/path/**"));
+ assertThat(provider.getModuleConfig().getTraceIgnorePathPatterns(), is("/ignore/path/**"));
+ }
+
+ @Test
+ public void testNotify() {
+ TraceIgnorePathWatcher traceIgnorePathWatcher = new TraceIgnorePathWatcher(provider);
+ ConfigChangeWatcher.ConfigChangeEvent value1 = new ConfigChangeWatcher.ConfigChangeEvent(
+ "/ignore/path2/**", ConfigChangeWatcher.EventType.MODIFY);
+
+ traceIgnorePathWatcher.notify(value1);
+ Assert.assertEquals(traceIgnorePathWatcher.getTraceIgnorePathPatterns(), "/ignore/path2/**");
+ Assert.assertEquals(traceIgnorePathWatcher.value(), "/ignore/path2/**");
+
+ ConfigChangeWatcher.ConfigChangeEvent value2 = new ConfigChangeWatcher.ConfigChangeEvent(
+ "/ignore/path2/**", ConfigChangeWatcher.EventType.DELETE);
+
+ traceIgnorePathWatcher.notify(value2);
+ Assert.assertEquals(traceIgnorePathWatcher.getTraceIgnorePathPatterns(), "");
+ Assert.assertEquals(traceIgnorePathWatcher.value(), "");
+
+ ConfigChangeWatcher.ConfigChangeEvent value3 = new ConfigChangeWatcher.ConfigChangeEvent(
+ "/ignore/path3/**", ConfigChangeWatcher.EventType.ADD);
+
+ traceIgnorePathWatcher.notify(value3);
+ Assert.assertEquals(traceIgnorePathWatcher.getTraceIgnorePathPatterns(), "/ignore/path3/**");
+ Assert.assertEquals(traceIgnorePathWatcher.value(), "/ignore/path3/**");
+
+ ConfigChangeWatcher.ConfigChangeEvent value4 = new ConfigChangeWatcher.ConfigChangeEvent(
+ "/ignore/path4/**", ConfigChangeWatcher.EventType.MODIFY);
+
+ traceIgnorePathWatcher.notify(value4);
+ Assert.assertEquals(traceIgnorePathWatcher.getTraceIgnorePathPatterns(), "/ignore/path4/**");
+ Assert.assertEquals(traceIgnorePathWatcher.value(), "/ignore/path4/**");
+ }
+
+ public static class MockConfigWatcherRegister extends ConfigWatcherRegister {
+
+ public MockConfigWatcherRegister(long syncPeriod) {
+ super(syncPeriod);
+ }
+
+ @Override
+ public Optional<ConfigTable> readConfig(Set<String> keys) {
+ ConfigTable table = new ConfigTable();
+ table.add(new ConfigTable.ConfigItem("agent-analyzer.default.traceIgnorePathPatterns", "/ignore/path/**"));
+ return Optional.of(table);
+ }
+ }
+
+}
diff --git a/oap-server/server-bootstrap/src/main/resources/application.yml b/oap-server/server-bootstrap/src/main/resources/application.yml
index 04edb32..dd23523 100755
--- a/oap-server/server-bootstrap/src/main/resources/application.yml
+++ b/oap-server/server-bootstrap/src/main/resources/application.yml
@@ -200,6 +200,7 @@ agent-analyzer:
selector: ${SW_AGENT_ANALYZER:default}
default:
sampleRate: ${SW_TRACE_SAMPLE_RATE:10000} # The sample rate precision is 1/10000. 10000 means 100% sample in default.
+ traceIgnorePathPatterns: ${SW_TRACE_IGNORE_PATH_PATTERNS:""} # Ignore matched trace. The current matching rules follow `Ant Path` match style , like `/path/*`, `/path/**`, `/path/?`, multiple paths should be separated by `,`.
slowDBAccessThreshold: ${SW_SLOW_DB_THRESHOLD:default:200,mongodb:100} # The slow database access thresholds. Unit ms.
forceSampleErrorSegment: ${SW_FORCE_SAMPLE_ERROR_SEGMENT:true} # When sampling mechanism active, this config can open(true) force save some error segment. true is default.
segmentStatusAnalysisStrategy: ${SW_SEGMENT_STATUS_ANALYSIS_STRATEGY:FROM_SPAN_STATUS} # Determine the final segment status from the status of spans. Available values are `FROM_SPAN_STATUS` , `FROM_ENTRY_SPAN` and `FROM_FIRST_SPAN`. `FROM_SPAN_STATUS` represents the segment status would be error if any span is in error status. `FROM_ENTRY_SPAN` means the segment status would be determined by the status of entry spans only. `FROM_FIRST_SPAN` means the segment status would be determine [...]