Skip to content
This repository was archived by the owner on Jun 14, 2023. It is now read-only.

Commit 2d02004

Browse files
authored
Support set instance layer (#154)
1 parent acee2ee commit 2d02004

File tree

10 files changed

+85
-27
lines changed

10 files changed

+85
-27
lines changed

.github/workflows/ci.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ jobs:
2727
name: Build
2828
runs-on: ubuntu-latest
2929
steps:
30-
- name: Set up Go 1.12
30+
- name: Set up Go 1.14
3131
uses: actions/setup-go@v1
3232
with:
33-
go-version: 1.12
33+
go-version: 1.14
3434
id: go
3535
- name: Check out code into the Go module directory
3636
uses: actions/checkout@v2

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ bin/
1414

1515
# IDE
1616
.idea/
17+
.vscode/
1718

1819
# Coverage
1920
coverage.txt

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -240,17 +240,17 @@ Go to go2sky-plugins repo to see all the plugins, [click here](https://github.co
240240

241241
Below is the full list of supported environment variables you can set to customize the agent behavior, please read the descriptions for what they can achieve.
242242

243-
| Environment Variable | Description | Default |
244-
|:------------------------------------------------------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:------------------:|
245-
| `SW_AGENT_NAME` | The name of the Go service | unset |
246-
| `SW_AGENT_INSTANCE_NAME` | The name of the Go service instance | Randomly generated |
247-
| `SW_AGENT_SAMPLE` | Sample rate, 1 setting it to 1 means full sampling | 1 |
248-
| `SW_AGENT_COLLECTOR_BACKEND_SERVICES` | The backend OAP server address | unset |
249-
| `SW_AGENT_AUTHENTICATION` | The authentication token to verify that the agent is trusted by the backend OAP, as for how to configure the backend, refer to [the yaml](https://github.com/apache/skywalking/blob/4f0f39ffccdc9b41049903cc540b8904f7c9728e/oap-server/server-bootstrap/src/main/resources/application.yml#L155-L158). | unset |
250-
| `SW_AGENT_COLLECTOR_HEARTBEAT_PERIOD` | Agent heartbeat report period. Unit, second | 20 |
251-
| `SW_AGENT_COLLECTOR_GET_AGENT_DYNAMIC_CONFIG_INTERVAL` | Sniffer get agent dynamic config interval. Unit, second | 20 |
252-
| `SW_AGENT_COLLECTOR_MAX_SEND_QUEUE_SIZE` | Send span queue buffer length | 30000 |
253-
243+
| Environment Variable | Description | Default |
244+
| :----------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------: |
245+
| `SW_AGENT_NAME` | The name of the Go service | unset |
246+
| `SW_AGENT_LAYER` | Instance belong layer name which define in the backend | unset |
247+
| `SW_AGENT_INSTANCE_NAME` | The name of the Go service instance | Randomly generated |
248+
| `SW_AGENT_SAMPLE` | Sample rate, 1 setting it to 1 means full sampling | 1 |
249+
| `SW_AGENT_COLLECTOR_BACKEND_SERVICES` | The backend OAP server address | unset |
250+
| `SW_AGENT_AUTHENTICATION` | The authentication token to verify that the agent is trusted by the backend OAP, as for how to configure the backend, refer to [the yaml](https://github.com/apache/skywalking/blob/4f0f39ffccdc9b41049903cc540b8904f7c9728e/oap-server/server-bootstrap/src/main/resources/application.yml#L155-L158). | unset |
251+
| `SW_AGENT_COLLECTOR_HEARTBEAT_PERIOD` | Agent heartbeat report period. Unit, second | 20 |
252+
| `SW_AGENT_COLLECTOR_GET_AGENT_DYNAMIC_CONFIG_INTERVAL` | Sniffer get agent dynamic config interval. Unit, second | 20 |
253+
| `SW_AGENT_COLLECTOR_MAX_SEND_QUEUE_SIZE` | Send span queue buffer length | 30000 |
254254

255255

256256
## CDS - Configuration Discovery Service

docs/GRPC-Reporter-Option.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
`GRPCReporterOption` allows for functional options to adjust behaviour of a `gRPC` reporter to be created by `NewGRPCReporter`.
44

55
| Function | Describe |
6-
|-------------------------------------|----------------------------------------------------|
6+
| ----------------------------------- | -------------------------------------------------- |
77
| `reporter.WithLog` | setup log for gRPC reporter |
88
| `reporter.WithCheckInterval` | setup service and endpoint registry check interval |
99
| `reporter.WithMaxSendQueueSize` | setup send span queue buffer length |
1010
| `reporter.WithInstanceProps` | setup service instance properties eg: org=SkyAPM |
1111
| `reporter.WithTransportCredentials` | setup transport layer security |
1212
| `reporter.WithAuthentication` | used Authentication for gRPC |
13-
| `reporter.WithCDS` | setup CDS service |
13+
| `reporter.WithCDS` | setup CDS service |
14+
| `reporter.WithLayer` | setup layer |
15+
| `reporter.WithFAASLayer` | setup layer to FAAS |

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module github.com/SkyAPM/go2sky
22

3-
go 1.12
3+
go 1.14
44

55
require (
66
github.com/golang/mock v1.5.0
77
github.com/google/uuid v1.1.2
88
github.com/pkg/errors v0.8.1
99
google.golang.org/grpc v1.40.0
10-
skywalking.apache.org/repo/goapi v0.0.0-20220121092418-9c455d0dda3f
10+
skywalking.apache.org/repo/goapi v0.0.0-20220401015832-2c9eee9481eb
1111
)

go.sum

+10-9
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
7777
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
7878
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
7979
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
80-
golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420 h1:a8jGStKg0XqKDlKqjLrXn0ioF5MH36pT7Z0BRTqLhbk=
81-
golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
80+
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY=
81+
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
8282
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
8383
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
8484
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -94,14 +94,15 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
9494
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
9595
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
9696
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
97-
golang.org/x/sys v0.0.0-20210917161153-d61c044b1678 h1:J27LZFQBFoihqXoegpscI10HpjZ7B5WQLLKL2FZXQKw=
98-
golang.org/x/sys v0.0.0-20210917161153-d61c044b1678/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
97+
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
98+
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9999
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
100100
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
101101
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
102102
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
103-
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
104103
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
104+
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
105+
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
105106
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
106107
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
107108
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
@@ -143,12 +144,12 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
143144
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
144145
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
145146
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
146-
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
147-
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
147+
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
148+
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
148149
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
149150
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
150151
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
151152
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
152153
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
153-
skywalking.apache.org/repo/goapi v0.0.0-20220121092418-9c455d0dda3f h1:i0cL/mhLt8xVO05SCKshkzWNUkXOkiW+zRIIuVWjPko=
154-
skywalking.apache.org/repo/goapi v0.0.0-20220121092418-9c455d0dda3f/go.mod h1:4KrWd+Oi4lkB+PtxZgIlf+3T6EECPru4fOWNMEHjxRk=
154+
skywalking.apache.org/repo/goapi v0.0.0-20220401015832-2c9eee9481eb h1:+PP2DpKFN/rEporLdPI4A7bPWQjwfARlUDKNhSab8iM=
155+
skywalking.apache.org/repo/goapi v0.0.0-20220401015832-2c9eee9481eb/go.mod h1:uWwwvhcwe2MD/nJCg0c1EE/eL6KzaBosLHDfMFoEJ30=

reporter/grpc.go

+5
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ type gRPCReporter struct {
113113

114114
// bootFlag is set if Boot be executed
115115
bootFlag bool
116+
117+
// Instance belong layer name which define in the backend
118+
layer string
116119
}
117120

118121
func (r *gRPCReporter) Boot(service string, serviceInstance string, cdsWatchers []go2sky.AgentConfigChangeWatcher) {
@@ -295,6 +298,7 @@ func (r *gRPCReporter) reportInstanceProperties() (err error) {
295298
Service: r.service,
296299
ServiceInstance: r.serviceInstance,
297300
Properties: props,
301+
Layer: r.layer,
298302
})
299303
return err
300304
}
@@ -323,6 +327,7 @@ func (r *gRPCReporter) check() {
323327
_, err := r.managementClient.KeepAlive(metadata.NewOutgoingContext(context.Background(), r.md), &managementv3.InstancePingPkg{
324328
Service: r.service,
325329
ServiceInstance: r.serviceInstance,
330+
Layer: r.layer,
326331
})
327332

328333
if err != nil {

reporter/grpc_env.go

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727

2828
const (
2929
swAgentAuthentication = "SW_AGENT_AUTHENTICATION"
30+
swAgentLayer = "SW_AGENT_LAYER"
3031
swAgentCollectorHeartbeatPeriod = "SW_AGENT_COLLECTOR_HEARTBEAT_PERIOD"
3132
swAgentCollectorGetAgentDynamicConfigInterval = "SW_AGENT_COLLECTOR_GET_AGENT_DYNAMIC_CONFIG_INTERVAL"
3233
swAgentCollectorBackendServices = "SW_AGENT_COLLECTOR_BACKEND_SERVICES"
@@ -47,6 +48,10 @@ func gRPCReporterOptionsFormEnv() (opts []GRPCReporterOption, err error) {
4748
opts = append(opts, WithAuthentication(auth))
4849
}
4950

51+
if layer := os.Getenv(swAgentLayer); layer != "" {
52+
opts = append(opts, WithLayer(layer))
53+
}
54+
5055
if value := os.Getenv(swAgentCollectorHeartbeatPeriod); value != "" {
5156
period, err1 := strconv.ParseInt(value, 0, 64)
5257
if err1 != nil {

reporter/grpc_opts.go

+14
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,17 @@ func WithCDS(interval time.Duration) GRPCReporterOption {
8686
r.cdsInterval = interval
8787
}
8888
}
89+
90+
// WithLayer setup layer
91+
func WithLayer(layer string) GRPCReporterOption {
92+
return func(r *gRPCReporter) {
93+
r.layer = layer
94+
}
95+
}
96+
97+
// WithFAASLayer set layer to FAAS
98+
func WithFAASLayer() GRPCReporterOption {
99+
return func(r *gRPCReporter) {
100+
r.layer = "FAAS"
101+
}
102+
}

reporter/grpc_test.go

+31-1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,24 @@ func TestGRPCReporterOption(t *testing.T) {
231231
}
232232
},
233233
},
234+
{
235+
name: "with layer",
236+
option: WithLayer("test"),
237+
verifyFunc: func(t *testing.T, reporter *gRPCReporter) {
238+
if reporter.layer != "test" {
239+
t.Error("error layer")
240+
}
241+
},
242+
},
243+
{
244+
name: "with faas layer",
245+
option: WithFAASLayer(),
246+
verifyFunc: func(t *testing.T, reporter *gRPCReporter) {
247+
if reporter.layer != "FAAS" {
248+
t.Error("error faas layer")
249+
}
250+
},
251+
},
234252
}
235253

236254
for _, tt := range tests {
@@ -336,11 +354,13 @@ func (t testLog) Errorf(format string, args ...interface{}) {
336354

337355
func TestGRPCReporter_EnvIfNotSet(t *testing.T) {
338356
os.Setenv(swAgentAuthentication, "auth")
357+
os.Setenv(swAgentLayer, "test3")
339358
os.Setenv(swAgentCollectorHeartbeatPeriod, "10")
340359
os.Setenv(swAgentCollectorGetAgentDynamicConfigInterval, "-1")
341360
os.Setenv(swAgentCollectorMaxSendQueueSize, "10")
342361

343362
defer os.Unsetenv(swAgentAuthentication)
363+
defer os.Unsetenv(swAgentLayer)
344364
defer os.Unsetenv(swAgentCollectorHeartbeatPeriod)
345365
defer os.Unsetenv(swAgentCollectorGetAgentDynamicConfigInterval)
346366
defer os.Unsetenv(swAgentCollectorMaxSendQueueSize)
@@ -359,6 +379,10 @@ func TestGRPCReporter_EnvIfNotSet(t *testing.T) {
359379
t.Errorf("the expected value of Authentication is auth")
360380
}
361381

382+
if r.layer != "test3" {
383+
t.Errorf("the expected value of layer is test3")
384+
}
385+
362386
if r.checkInterval != 10*time.Second {
363387
t.Errorf("the expected value of checkInterval is 10s")
364388
}
@@ -374,17 +398,19 @@ func TestGRPCReporter_EnvIfNotSet(t *testing.T) {
374398

375399
func TestGRPCReporter_EnvOverride(t *testing.T) {
376400
os.Setenv(swAgentAuthentication, "auth")
401+
os.Setenv(swAgentLayer, "test")
377402
os.Setenv(swAgentCollectorHeartbeatPeriod, "10")
378403
os.Setenv(swAgentCollectorGetAgentDynamicConfigInterval, "-1")
379404
os.Setenv(swAgentCollectorMaxSendQueueSize, "10")
380405

381406
defer os.Unsetenv(swAgentAuthentication)
407+
defer os.Unsetenv(swAgentLayer)
382408
defer os.Unsetenv(swAgentCollectorHeartbeatPeriod)
383409
defer os.Unsetenv(swAgentCollectorGetAgentDynamicConfigInterval)
384410
defer os.Unsetenv(swAgentCollectorMaxSendQueueSize)
385411

386412
r := createGRPCReporter()
387-
err := applyGRPCReporterOption(r, WithCDS(10), WithAuthentication("test"), WithCheckInterval(30), WithMaxSendQueueSize(9))
413+
err := applyGRPCReporterOption(r, WithCDS(10), WithLayer("test1"), WithAuthentication("test"), WithCheckInterval(30), WithMaxSendQueueSize(9))
388414
if err != nil {
389415
t.Error(err)
390416
}
@@ -397,6 +423,10 @@ func TestGRPCReporter_EnvOverride(t *testing.T) {
397423
t.Errorf("the expected value of Authentication is auth")
398424
}
399425

426+
if r.layer != "test" {
427+
t.Errorf("the expected value of layer is test")
428+
}
429+
400430
if r.checkInterval != 10*time.Second {
401431
t.Errorf("the expected value of checkInterval is 10s")
402432
}

0 commit comments

Comments
 (0)