This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-go.git
The following commit(s) were added to refs/heads/main by this push:
new e7e4678 Support plugin exclusion mechanism (#39)
e7e4678 is described below
commit e7e4678987e74d61468e2445bb1d108ab5f24ac8
Author: mrproliu <[email protected]>
AuthorDate: Tue May 16 09:03:33 2023 +0800
Support plugin exclusion mechanism (#39)
---
.github/workflows/plugin-tests.yaml | 1 +
docs/en/advanced-features/plugin-exclusion.md | 19 +++++++++
docs/en/agent/support-plugins.md | 8 ++--
docs/menu.yml | 2 +
go.work | 4 +-
plugins/{ginv2 => gin}/go.mod | 2 +-
plugins/{ginv2 => gin}/go.sum | 0
plugins/{ginv2 => gin}/instrument.go | 4 +-
plugins/{ginv2 => gin}/intercepter.go | 2 +-
plugins/{ginv2 => gin}/intercepter_test.go | 2 +-
test/plugins/scenarios/dubbo/config/excepted.yml | 17 --------
test/plugins/scenarios/gin/config/excepted.yml | 17 --------
test/plugins/scenarios/http/config/excepted.yml | 17 --------
.../scenarios/plugin_exclusion/bin/startup.sh | 23 +++++++++++
.../{gin => plugin_exclusion}/config/excepted.yml | 44 +++-----------------
.../plugins/scenarios/plugin_exclusion}/go.mod | 9 +---
.../plugins/scenarios/plugin_exclusion/main.go | 48 +++++++++++++++-------
test/plugins/scenarios/plugin_exclusion/plugin.yml | 25 +++++++++++
tools/go-agent/config/agent.default.yaml | 7 +++-
tools/go-agent/config/loader.go | 18 ++++++++
tools/go-agent/instrument/plugins/instrument.go | 11 +++++
tools/go-agent/instrument/plugins/register.go | 4 +-
22 files changed, 160 insertions(+), 124 deletions(-)
diff --git a/.github/workflows/plugin-tests.yaml
b/.github/workflows/plugin-tests.yaml
index 4e88f68..acb82fd 100644
--- a/.github/workflows/plugin-tests.yaml
+++ b/.github/workflows/plugin-tests.yaml
@@ -59,6 +59,7 @@ jobs:
- gin
- http
- dubbo
+ - plugin_exclusion
steps:
- uses: actions/checkout@v2
with:
diff --git a/docs/en/advanced-features/plugin-exclusion.md
b/docs/en/advanced-features/plugin-exclusion.md
new file mode 100644
index 0000000..fbe045c
--- /dev/null
+++ b/docs/en/advanced-features/plugin-exclusion.md
@@ -0,0 +1,19 @@
+# Plugin Exclusion
+
+The plugin exclusion is used during the **compilation phase** to exclude
specific plugins, through their names.
+Consequently, the codes of these excluded plugins will not be weaved in, then,
no relative tracing and metrics.
+
+## Configuration
+
+
+```yaml
+plugin:
+ # List the names of excluded plugins, multiple plugin names should be
splitted by ","
+ # NOTE: This parameter only takes effect during the compilation phase.
+ excluded: ${SW_AGENT_PLUGIN_EXCLUDES:}
+```
+
+This configuration option is also located in the existing configuration files
and [supports configuration based on environment
variables](./settings-override.md#environment-variables).
+However, this environment variable only takes effect during the compilation
phase.
+
+The plugins name please refer to the [Support Plugins
Documentation](../agent/support-plugins.md).
diff --git a/docs/en/agent/support-plugins.md b/docs/en/agent/support-plugins.md
index ea053da..0e01314 100644
--- a/docs/en/agent/support-plugins.md
+++ b/docs/en/agent/support-plugins.md
@@ -1,9 +1,9 @@
# Supported Libraries
* HTTP Server
- * [Gin](https://github.com/gin-gonic/gin)
- * [Native HTTP](https://pkg.go.dev/net/http)
+ * `gin`: [Gin](https://github.com/gin-gonic/gin)
+ * `http`: [Native HTTP](https://pkg.go.dev/net/http)
* HTTP Client
- * [Native HTTP](https://pkg.go.dev/net/http)
+ * `http`: [Native HTTP](https://pkg.go.dev/net/http)
* RPC Frameworks
- * [Dubbo](https://github.com/apache/dubbo-go)
\ No newline at end of file
+ * `dubbo`: [Dubbo](https://github.com/apache/dubbo-go)
\ No newline at end of file
diff --git a/docs/menu.yml b/docs/menu.yml
index 8f3cb11..e20fc8f 100644
--- a/docs/menu.yml
+++ b/docs/menu.yml
@@ -31,6 +31,8 @@ catalog:
path: /en/advanced-features/settings-override
- name: Logging Setup
path: /en/advanced-features/logging-setup
+ - name: Plugin Exclusion
+ path: /en/advanced-features/plugin-exclusion
- name: Supported Libraries
path: /en/agent/support-plugins
- name: Performance Test
diff --git a/go.work b/go.work
index 2db849c..dc9c9a5 100644
--- a/go.work
+++ b/go.work
@@ -6,7 +6,7 @@ use (
// define the plugins
./plugins/core
./plugins/dubbo
- ./plugins/ginv2
+ ./plugins/gin
./plugins/http
./test/benchmark-codebase/consumer
@@ -19,5 +19,7 @@ use (
./test/plugins/scenarios/gin
./test/plugins/scenarios/http
+ ./test/plugins/scenarios/plugin_exclusion
+
./tools/go-agent
)
diff --git a/plugins/ginv2/go.mod b/plugins/gin/go.mod
similarity index 96%
copy from plugins/ginv2/go.mod
copy to plugins/gin/go.mod
index 1c220ab..c9b5c64 100644
--- a/plugins/ginv2/go.mod
+++ b/plugins/gin/go.mod
@@ -1,4 +1,4 @@
-module github.com/apache/skywalking-go/plugins/ginv2
+module github.com/apache/skywalking-go/plugins/gin
go 1.18
diff --git a/plugins/ginv2/go.sum b/plugins/gin/go.sum
similarity index 100%
rename from plugins/ginv2/go.sum
rename to plugins/gin/go.sum
diff --git a/plugins/ginv2/instrument.go b/plugins/gin/instrument.go
similarity index 98%
rename from plugins/ginv2/instrument.go
rename to plugins/gin/instrument.go
index 2f4e398..a764ed0 100644
--- a/plugins/ginv2/instrument.go
+++ b/plugins/gin/instrument.go
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-package ginv2
+package gin
import (
"embed"
@@ -36,7 +36,7 @@ func NewInstrument() *Instrument {
}
func (i *Instrument) Name() string {
- return "ginv2"
+ return "gin"
}
func (i *Instrument) BasePackage() string {
diff --git a/plugins/ginv2/intercepter.go b/plugins/gin/intercepter.go
similarity index 99%
rename from plugins/ginv2/intercepter.go
rename to plugins/gin/intercepter.go
index ec39e74..e1fed3b 100644
--- a/plugins/ginv2/intercepter.go
+++ b/plugins/gin/intercepter.go
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-package ginv2
+package gin
import (
"fmt"
diff --git a/plugins/ginv2/intercepter_test.go b/plugins/gin/intercepter_test.go
similarity index 99%
rename from plugins/ginv2/intercepter_test.go
rename to plugins/gin/intercepter_test.go
index a3a6503..7b530f2 100644
--- a/plugins/ginv2/intercepter_test.go
+++ b/plugins/gin/intercepter_test.go
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-package ginv2
+package gin
import (
"net/http"
diff --git a/test/plugins/scenarios/dubbo/config/excepted.yml
b/test/plugins/scenarios/dubbo/config/excepted.yml
index e2290c5..aaae3b0 100644
--- a/test/plugins/scenarios/dubbo/config/excepted.yml
+++ b/test/plugins/scenarios/dubbo/config/excepted.yml
@@ -40,23 +40,6 @@ segmentItems:
- serviceName: dubbo-client
segmentSize: 2
segments:
- - segmentId: not null
- spans:
- - operationName: GET:/health
- parentSpanId: -1
- spanId: 0
- spanLayer: Http
- startTime: nq 0
- endTime: nq 0
- componentId: 5004
- isError: false
- spanType: Entry
- peer: ''
- skipAnalysis: false
- tags:
- - {key: http.method, value: GET}
- - {key: url, value: 'service:8080/health'}
- - {key: status_code, value: '200'}
- segmentId: not null
spans:
- operationName: /api.Greeter/SayHello
diff --git a/test/plugins/scenarios/gin/config/excepted.yml
b/test/plugins/scenarios/gin/config/excepted.yml
index 32451fd..e928323 100644
--- a/test/plugins/scenarios/gin/config/excepted.yml
+++ b/test/plugins/scenarios/gin/config/excepted.yml
@@ -18,23 +18,6 @@ segmentItems:
- serviceName: gin
segmentSize: ge 3
segments:
- - segmentId: not null
- spans:
- - operationName: GET:/health
- parentSpanId: -1
- spanId: 0
- spanLayer: Http
- startTime: nq 0
- endTime: nq 0
- componentId: 5006
- isError: false
- spanType: Entry
- peer: ''
- skipAnalysis: false
- tags:
- - {key: http.method, value: GET}
- - {key: url, value: 'service:8080/health'}
- - {key: status_code, value: '200'}
- segmentId: not null
spans:
- operationName: GET:/provider
diff --git a/test/plugins/scenarios/http/config/excepted.yml
b/test/plugins/scenarios/http/config/excepted.yml
index cf18a7e..2bb131e 100644
--- a/test/plugins/scenarios/http/config/excepted.yml
+++ b/test/plugins/scenarios/http/config/excepted.yml
@@ -18,23 +18,6 @@ segmentItems:
- serviceName: http
segmentSize: ge 3
segments:
- - segmentId: not null
- spans:
- - operationName: GET:/health
- parentSpanId: -1
- spanId: 0
- spanLayer: Http
- startTime: nq 0
- endTime: nq 0
- componentId: 5004
- isError: false
- spanType: Entry
- peer: ''
- skipAnalysis: false
- tags:
- - {key: http.method, value: GET}
- - {key: url, value: 'service:8080/health'}
- - {key: status_code, value: '200'}
- segmentId: not null
spans:
- operationName: GET:/provider
diff --git a/test/plugins/scenarios/plugin_exclusion/bin/startup.sh
b/test/plugins/scenarios/plugin_exclusion/bin/startup.sh
new file mode 100755
index 0000000..3b91f79
--- /dev/null
+++ b/test/plugins/scenarios/plugin_exclusion/bin/startup.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+#
+# 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.
+
+home="$(cd "$(dirname $0)"; pwd)"
+export SW_AGENT_PLUGIN_EXCLUDES=http
+go build ${GO_BUILD_OPTS} -o gin
+
+./gin
\ No newline at end of file
diff --git a/test/plugins/scenarios/gin/config/excepted.yml
b/test/plugins/scenarios/plugin_exclusion/config/excepted.yml
similarity index 58%
copy from test/plugins/scenarios/gin/config/excepted.yml
copy to test/plugins/scenarios/plugin_exclusion/config/excepted.yml
index 32451fd..2f72231 100644
--- a/test/plugins/scenarios/gin/config/excepted.yml
+++ b/test/plugins/scenarios/plugin_exclusion/config/excepted.yml
@@ -15,26 +15,9 @@
# limitations under the License.
segmentItems:
- - serviceName: gin
+ - serviceName: plugin_exclusion
segmentSize: ge 3
segments:
- - segmentId: not null
- spans:
- - operationName: GET:/health
- parentSpanId: -1
- spanId: 0
- spanLayer: Http
- startTime: nq 0
- endTime: nq 0
- componentId: 5006
- isError: false
- spanType: Entry
- peer: ''
- skipAnalysis: false
- tags:
- - {key: http.method, value: GET}
- - {key: url, value: 'service:8080/health'}
- - {key: status_code, value: '200'}
- segmentId: not null
spans:
- operationName: GET:/provider
@@ -52,33 +35,15 @@ segmentItems:
- {key: http.method, value: GET}
- {key: url, value: 'localhost:8080/provider'}
- {key: status_code, value: '200'}
- refs:
- - {parentEndpoint: 'GET:/consumer', networkAddress:
'localhost:8080', refType: CrossProcess,
- parentSpanId: 1, parentTraceSegmentId: not null,
parentServiceInstance: not null,
- parentService: gin, traceId: not null}
+ refs: null
- segmentId: not null
spans:
- - operationName: GET:/provider
- parentSpanId: 0
- spanId: 1
- spanLayer: Http
- startTime: gt 0
- endTime: gt 0
- componentId: 5005
- isError: false
- spanType: Exit
- peer: localhost:8080
- skipAnalysis: false
- tags:
- - {key: http.method, value: GET}
- - {key: url, value: 'localhost:8080/provider'}
- - {key: status_code, value: '200'}
- operationName: GET:/consumer
parentSpanId: -1
spanId: 0
spanLayer: Http
- startTime: gt 0
- endTime: gt 0
+ startTime: nq 0
+ endTime: nq 0
componentId: 5006
isError: false
spanType: Entry
@@ -88,5 +53,6 @@ segmentItems:
- {key: http.method, value: GET}
- {key: url, value: 'service:8080/consumer'}
- {key: status_code, value: '200'}
+ refs: null
meterItems: []
logItems: []
\ No newline at end of file
diff --git a/plugins/ginv2/go.mod
b/test/plugins/scenarios/plugin_exclusion/go.mod
similarity index 85%
rename from plugins/ginv2/go.mod
rename to test/plugins/scenarios/plugin_exclusion/go.mod
index 1c220ab..331a496 100644
--- a/plugins/ginv2/go.mod
+++ b/test/plugins/scenarios/plugin_exclusion/go.mod
@@ -1,16 +1,12 @@
-module github.com/apache/skywalking-go/plugins/ginv2
+module test/plugins/scenarios/plugin_exclusion
go 1.18
-require (
- github.com/gin-gonic/gin v1.9.0
- github.com/stretchr/testify v1.8.2
-)
+require github.com/gin-gonic/gin v1.9.0
require (
github.com/bytedance/sonic v1.8.8 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 //
indirect
- github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
@@ -25,7 +21,6 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd //
indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
- github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
diff --git a/tools/go-agent/instrument/plugins/register.go
b/test/plugins/scenarios/plugin_exclusion/main.go
similarity index 51%
copy from tools/go-agent/instrument/plugins/register.go
copy to test/plugins/scenarios/plugin_exclusion/main.go
index 8a31f5d..b44133e 100644
--- a/tools/go-agent/instrument/plugins/register.go
+++ b/test/plugins/scenarios/plugin_exclusion/main.go
@@ -15,24 +15,44 @@
// specific language governing permissions and limitations
// under the License.
-package plugins
+package main
import (
- "github.com/apache/skywalking-go/plugins/core/instrument"
- "github.com/apache/skywalking-go/plugins/dubbo"
- "github.com/apache/skywalking-go/plugins/ginv2"
- "github.com/apache/skywalking-go/plugins/http"
+ "io"
+ "log"
+ "net/http"
+
+ "github.com/gin-gonic/gin"
+
+ _ "github.com/apache/skywalking-go"
)
-var instruments = make([]instrument.Instrument, 0)
+func main() {
+ engine := gin.New()
+ engine.Handle("GET", "/consumer", func(context *gin.Context) {
+ resp, err := http.Get("http://localhost:8080/provider")
+ if err != nil {
+ log.Print(err)
+ context.Status(http.StatusInternalServerError)
+ return
+ }
+ defer resp.Body.Close()
+ body, err := io.ReadAll(resp.Body)
+ if err != nil {
+ log.Print(err)
+ context.Status(http.StatusInternalServerError)
+ return
+ }
+ context.String(200, string(body))
+ })
-func init() {
- // register the plugins instrument
- registerFramework(ginv2.NewInstrument())
- registerFramework(http.NewInstrument())
- registerFramework(dubbo.NewInstrument())
-}
+ engine.Handle("GET", "/provider", func(context *gin.Context) {
+ context.String(200, "success")
+ })
+
+ engine.Handle("GET", "health", func(context *gin.Context) {
+ context.Status(http.StatusOK)
+ })
-func registerFramework(ins instrument.Instrument) {
- instruments = append(instruments, ins)
+ _ = engine.Run(":8080")
}
diff --git a/test/plugins/scenarios/plugin_exclusion/plugin.yml
b/test/plugins/scenarios/plugin_exclusion/plugin.yml
new file mode 100644
index 0000000..99dc771
--- /dev/null
+++ b/test/plugins/scenarios/plugin_exclusion/plugin.yml
@@ -0,0 +1,25 @@
+# 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.
+
+entry-service: http://${HTTP_HOST}:${HTTP_PORT}/consumer
+health-checker: http://${HTTP_HOST}:${HTTP_PORT}/health
+start-script: ./bin/startup.sh
+framework: github.com/gin-gonic/gin
+export-port: 8080
+support-version:
+ - go: 1.18
+ framework:
+ - v1.9.0
\ No newline at end of file
diff --git a/tools/go-agent/config/agent.default.yaml
b/tools/go-agent/config/agent.default.yaml
index b4c5add..55cf652 100644
--- a/tools/go-agent/config/agent.default.yaml
+++ b/tools/go-agent/config/agent.default.yaml
@@ -47,4 +47,9 @@ log:
# Whether to automatically integrate Tracing information into the logs.
enable: ${SW_AGENT_LOG_TRACING_ENABLE:true}
# If tracing information is enabled, the tracing information would be
stored in the current Key in each log.
- key: ${SW_AGENT_LOG_TRACING_KEY:SW_CTX}
\ No newline at end of file
+ key: ${SW_AGENT_LOG_TRACING_KEY:SW_CTX}
+
+plugin:
+ # List the names of excluded plugins, multiple plugin names should be
splitted by ","
+ # NOTE: This parameter only takes effect during the compilation phase.
+ excluded: ${SW_AGENT_PLUGIN_EXCLUDES:}
\ No newline at end of file
diff --git a/tools/go-agent/config/loader.go b/tools/go-agent/config/loader.go
index d721562..8188a18 100644
--- a/tools/go-agent/config/loader.go
+++ b/tools/go-agent/config/loader.go
@@ -41,6 +41,7 @@ type Config struct {
Agent Agent `yaml:"agent"`
Reporter Reporter `yaml:"reporter"`
Log Log `yaml:"log"`
+ Plugin Plugin `yaml:"plugin"`
}
type Agent struct {
@@ -68,6 +69,10 @@ type GRPCReporter struct {
MaxSendQueue StringValue `yaml:"max_send_queue"`
}
+type Plugin struct {
+ Excluded StringValue `yaml:"excluded"`
+}
+
func LoadConfig(path string) error {
// load the default config
defaultConfig, err := defaultAgentFS.ReadFile("agent.default.yaml")
@@ -180,6 +185,19 @@ func (s *StringValue) ToGoBoolFunction() string {
return fmt.Sprintf("func() bool { return %s }", s.ToGoBoolValue())
}
+func (s *StringValue) GetListStringResult() []string {
+ val := s.Default
+ if s.EnvKey != "" {
+ if envValue := os.Getenv(s.EnvKey); envValue != "" {
+ val = envValue
+ }
+ }
+ if val == "" {
+ return nil
+ }
+ return strings.Split(val, ",")
+}
+
func (s *StringValue) overwriteFrom(other StringValue) {
if other.EnvKey != "" {
s.EnvKey = other.EnvKey
diff --git a/tools/go-agent/instrument/plugins/instrument.go
b/tools/go-agent/instrument/plugins/instrument.go
index b7b2e21..5d6c4d9 100644
--- a/tools/go-agent/instrument/plugins/instrument.go
+++ b/tools/go-agent/instrument/plugins/instrument.go
@@ -28,6 +28,7 @@ import (
"github.com/apache/skywalking-go/plugins/core"
"github.com/apache/skywalking-go/plugins/core/instrument"
+ "github.com/apache/skywalking-go/tools/go-agent/config"
"github.com/apache/skywalking-go/tools/go-agent/instrument/api"
"github.com/apache/skywalking-go/tools/go-agent/instrument/consts"
"github.com/apache/skywalking-go/tools/go-agent/instrument/plugins/rewrite"
@@ -67,7 +68,17 @@ type Enhance interface {
}
func (i *Instrument) CouldHandle(opts *api.CompileOptions) bool {
+ excludePlugins :=
config.GetConfig().Plugin.Excluded.GetListStringResult()
+ excludePluginMap := make(map[string]bool, len(excludePlugins))
+ for _, v := range excludePlugins {
+ excludePluginMap[v] = true
+ }
for _, ins := range instruments {
+ // exclude the plugin at the compile phase if it's ignored
+ if excludePluginMap[ins.Name()] {
+ logrus.Infof("plugin is exclude: %s", ins.Name())
+ continue
+ }
// must have the same base package prefix
if !strings.HasPrefix(opts.Package, ins.BasePackage()) {
continue
diff --git a/tools/go-agent/instrument/plugins/register.go
b/tools/go-agent/instrument/plugins/register.go
index 8a31f5d..d9e5aec 100644
--- a/tools/go-agent/instrument/plugins/register.go
+++ b/tools/go-agent/instrument/plugins/register.go
@@ -20,7 +20,7 @@ package plugins
import (
"github.com/apache/skywalking-go/plugins/core/instrument"
"github.com/apache/skywalking-go/plugins/dubbo"
- "github.com/apache/skywalking-go/plugins/ginv2"
+ "github.com/apache/skywalking-go/plugins/gin"
"github.com/apache/skywalking-go/plugins/http"
)
@@ -28,7 +28,7 @@ var instruments = make([]instrument.Instrument, 0)
func init() {
// register the plugins instrument
- registerFramework(ginv2.NewInstrument())
+ registerFramework(gin.NewInstrument())
registerFramework(http.NewInstrument())
registerFramework(dubbo.NewInstrument())
}