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

Commit

Permalink
Support set instance layer (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
arugal authored Apr 1, 2022
1 parent acee2ee commit 2d02004
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.12
- name: Set up Go 1.14
uses: actions/setup-go@v1
with:
go-version: 1.12
go-version: 1.14
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ bin/

# IDE
.idea/
.vscode/

# Coverage
coverage.txt
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,17 @@ Go to go2sky-plugins repo to see all the plugins, [click here](https://github.co

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.

| Environment Variable | Description | Default |
|:------------------------------------------------------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:------------------:|
| `SW_AGENT_NAME` | The name of the Go service | unset |
| `SW_AGENT_INSTANCE_NAME` | The name of the Go service instance | Randomly generated |
| `SW_AGENT_SAMPLE` | Sample rate, 1 setting it to 1 means full sampling | 1 |
| `SW_AGENT_COLLECTOR_BACKEND_SERVICES` | The backend OAP server address | unset |
| `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 |
| `SW_AGENT_COLLECTOR_HEARTBEAT_PERIOD` | Agent heartbeat report period. Unit, second | 20 |
| `SW_AGENT_COLLECTOR_GET_AGENT_DYNAMIC_CONFIG_INTERVAL` | Sniffer get agent dynamic config interval. Unit, second | 20 |
| `SW_AGENT_COLLECTOR_MAX_SEND_QUEUE_SIZE` | Send span queue buffer length | 30000 |

| Environment Variable | Description | Default |
| :----------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------: |
| `SW_AGENT_NAME` | The name of the Go service | unset |
| `SW_AGENT_LAYER` | Instance belong layer name which define in the backend | unset |
| `SW_AGENT_INSTANCE_NAME` | The name of the Go service instance | Randomly generated |
| `SW_AGENT_SAMPLE` | Sample rate, 1 setting it to 1 means full sampling | 1 |
| `SW_AGENT_COLLECTOR_BACKEND_SERVICES` | The backend OAP server address | unset |
| `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 |
| `SW_AGENT_COLLECTOR_HEARTBEAT_PERIOD` | Agent heartbeat report period. Unit, second | 20 |
| `SW_AGENT_COLLECTOR_GET_AGENT_DYNAMIC_CONFIG_INTERVAL` | Sniffer get agent dynamic config interval. Unit, second | 20 |
| `SW_AGENT_COLLECTOR_MAX_SEND_QUEUE_SIZE` | Send span queue buffer length | 30000 |


## CDS - Configuration Discovery Service
Expand Down
6 changes: 4 additions & 2 deletions docs/GRPC-Reporter-Option.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
`GRPCReporterOption` allows for functional options to adjust behaviour of a `gRPC` reporter to be created by `NewGRPCReporter`.

| Function | Describe |
|-------------------------------------|----------------------------------------------------|
| ----------------------------------- | -------------------------------------------------- |
| `reporter.WithLog` | setup log for gRPC reporter |
| `reporter.WithCheckInterval` | setup service and endpoint registry check interval |
| `reporter.WithMaxSendQueueSize` | setup send span queue buffer length |
| `reporter.WithInstanceProps` | setup service instance properties eg: org=SkyAPM |
| `reporter.WithTransportCredentials` | setup transport layer security |
| `reporter.WithAuthentication` | used Authentication for gRPC |
| `reporter.WithCDS` | setup CDS service |
| `reporter.WithCDS` | setup CDS service |
| `reporter.WithLayer` | setup layer |
| `reporter.WithFAASLayer` | setup layer to FAAS |
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module github.com/SkyAPM/go2sky

go 1.12
go 1.14

require (
github.com/golang/mock v1.5.0
github.com/google/uuid v1.1.2
github.com/pkg/errors v0.8.1
google.golang.org/grpc v1.40.0
skywalking.apache.org/repo/goapi v0.0.0-20220121092418-9c455d0dda3f
skywalking.apache.org/repo/goapi v0.0.0-20220401015832-2c9eee9481eb
)
19 changes: 10 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420 h1:a8jGStKg0XqKDlKqjLrXn0ioF5MH36pT7Z0BRTqLhbk=
golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -94,14 +94,15 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210917161153-d61c044b1678 h1:J27LZFQBFoihqXoegpscI10HpjZ7B5WQLLKL2FZXQKw=
golang.org/x/sys v0.0.0-20210917161153-d61c044b1678/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
Expand Down Expand Up @@ -143,12 +144,12 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
skywalking.apache.org/repo/goapi v0.0.0-20220121092418-9c455d0dda3f h1:i0cL/mhLt8xVO05SCKshkzWNUkXOkiW+zRIIuVWjPko=
skywalking.apache.org/repo/goapi v0.0.0-20220121092418-9c455d0dda3f/go.mod h1:4KrWd+Oi4lkB+PtxZgIlf+3T6EECPru4fOWNMEHjxRk=
skywalking.apache.org/repo/goapi v0.0.0-20220401015832-2c9eee9481eb h1:+PP2DpKFN/rEporLdPI4A7bPWQjwfARlUDKNhSab8iM=
skywalking.apache.org/repo/goapi v0.0.0-20220401015832-2c9eee9481eb/go.mod h1:uWwwvhcwe2MD/nJCg0c1EE/eL6KzaBosLHDfMFoEJ30=
5 changes: 5 additions & 0 deletions reporter/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ type gRPCReporter struct {

// bootFlag is set if Boot be executed
bootFlag bool

// Instance belong layer name which define in the backend
layer string
}

func (r *gRPCReporter) Boot(service string, serviceInstance string, cdsWatchers []go2sky.AgentConfigChangeWatcher) {
Expand Down Expand Up @@ -295,6 +298,7 @@ func (r *gRPCReporter) reportInstanceProperties() (err error) {
Service: r.service,
ServiceInstance: r.serviceInstance,
Properties: props,
Layer: r.layer,
})
return err
}
Expand Down Expand Up @@ -323,6 +327,7 @@ func (r *gRPCReporter) check() {
_, err := r.managementClient.KeepAlive(metadata.NewOutgoingContext(context.Background(), r.md), &managementv3.InstancePingPkg{
Service: r.service,
ServiceInstance: r.serviceInstance,
Layer: r.layer,
})

if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions reporter/grpc_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

const (
swAgentAuthentication = "SW_AGENT_AUTHENTICATION"
swAgentLayer = "SW_AGENT_LAYER"
swAgentCollectorHeartbeatPeriod = "SW_AGENT_COLLECTOR_HEARTBEAT_PERIOD"
swAgentCollectorGetAgentDynamicConfigInterval = "SW_AGENT_COLLECTOR_GET_AGENT_DYNAMIC_CONFIG_INTERVAL"
swAgentCollectorBackendServices = "SW_AGENT_COLLECTOR_BACKEND_SERVICES"
Expand All @@ -47,6 +48,10 @@ func gRPCReporterOptionsFormEnv() (opts []GRPCReporterOption, err error) {
opts = append(opts, WithAuthentication(auth))
}

if layer := os.Getenv(swAgentLayer); layer != "" {
opts = append(opts, WithLayer(layer))
}

if value := os.Getenv(swAgentCollectorHeartbeatPeriod); value != "" {
period, err1 := strconv.ParseInt(value, 0, 64)
if err1 != nil {
Expand Down
14 changes: 14 additions & 0 deletions reporter/grpc_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,17 @@ func WithCDS(interval time.Duration) GRPCReporterOption {
r.cdsInterval = interval
}
}

// WithLayer setup layer
func WithLayer(layer string) GRPCReporterOption {
return func(r *gRPCReporter) {
r.layer = layer
}
}

// WithFAASLayer set layer to FAAS
func WithFAASLayer() GRPCReporterOption {
return func(r *gRPCReporter) {
r.layer = "FAAS"
}
}
32 changes: 31 additions & 1 deletion reporter/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,24 @@ func TestGRPCReporterOption(t *testing.T) {
}
},
},
{
name: "with layer",
option: WithLayer("test"),
verifyFunc: func(t *testing.T, reporter *gRPCReporter) {
if reporter.layer != "test" {
t.Error("error layer")
}
},
},
{
name: "with faas layer",
option: WithFAASLayer(),
verifyFunc: func(t *testing.T, reporter *gRPCReporter) {
if reporter.layer != "FAAS" {
t.Error("error faas layer")
}
},
},
}

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

func TestGRPCReporter_EnvIfNotSet(t *testing.T) {
os.Setenv(swAgentAuthentication, "auth")
os.Setenv(swAgentLayer, "test3")
os.Setenv(swAgentCollectorHeartbeatPeriod, "10")
os.Setenv(swAgentCollectorGetAgentDynamicConfigInterval, "-1")
os.Setenv(swAgentCollectorMaxSendQueueSize, "10")

defer os.Unsetenv(swAgentAuthentication)
defer os.Unsetenv(swAgentLayer)
defer os.Unsetenv(swAgentCollectorHeartbeatPeriod)
defer os.Unsetenv(swAgentCollectorGetAgentDynamicConfigInterval)
defer os.Unsetenv(swAgentCollectorMaxSendQueueSize)
Expand All @@ -359,6 +379,10 @@ func TestGRPCReporter_EnvIfNotSet(t *testing.T) {
t.Errorf("the expected value of Authentication is auth")
}

if r.layer != "test3" {
t.Errorf("the expected value of layer is test3")
}

if r.checkInterval != 10*time.Second {
t.Errorf("the expected value of checkInterval is 10s")
}
Expand All @@ -374,17 +398,19 @@ func TestGRPCReporter_EnvIfNotSet(t *testing.T) {

func TestGRPCReporter_EnvOverride(t *testing.T) {
os.Setenv(swAgentAuthentication, "auth")
os.Setenv(swAgentLayer, "test")
os.Setenv(swAgentCollectorHeartbeatPeriod, "10")
os.Setenv(swAgentCollectorGetAgentDynamicConfigInterval, "-1")
os.Setenv(swAgentCollectorMaxSendQueueSize, "10")

defer os.Unsetenv(swAgentAuthentication)
defer os.Unsetenv(swAgentLayer)
defer os.Unsetenv(swAgentCollectorHeartbeatPeriod)
defer os.Unsetenv(swAgentCollectorGetAgentDynamicConfigInterval)
defer os.Unsetenv(swAgentCollectorMaxSendQueueSize)

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

if r.layer != "test" {
t.Errorf("the expected value of layer is test")
}

if r.checkInterval != 10*time.Second {
t.Errorf("the expected value of checkInterval is 10s")
}
Expand Down

0 comments on commit 2d02004

Please sign in to comment.