forked from TrueCloudLab/frostfs-api-go
[#12] tracing: Add tracing package
Add tracing config, implementation and setup Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
3a7280968b
commit
816628d37d
6 changed files with 807 additions and 0 deletions
212
pkg/tracing/config_test.go
Normal file
212
pkg/tracing/config_test.go
Normal file
|
@ -0,0 +1,212 @@
|
|||
package tracing
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConfig_validate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
config Config
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "disabled",
|
||||
wantErr: false,
|
||||
config: Config{
|
||||
Enabled: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "stdout",
|
||||
wantErr: false,
|
||||
config: Config{
|
||||
Enabled: true,
|
||||
Exporter: Stdout,
|
||||
Service: "test",
|
||||
InstanceID: "s01",
|
||||
Version: "v0.0.1",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "OTLP gRPC",
|
||||
wantErr: false,
|
||||
config: Config{
|
||||
Enabled: true,
|
||||
Exporter: OTLPgRPC,
|
||||
Service: "test",
|
||||
Endpoint: "localhost:4717",
|
||||
InstanceID: "s01",
|
||||
Version: "v0.0.1",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "unknown exporter",
|
||||
wantErr: true,
|
||||
config: Config{
|
||||
Enabled: true,
|
||||
Exporter: "unknown",
|
||||
Service: "test",
|
||||
Endpoint: "localhost:4717",
|
||||
InstanceID: "s01",
|
||||
Version: "v0.0.1",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "no exporter",
|
||||
wantErr: true,
|
||||
config: Config{
|
||||
Enabled: true,
|
||||
Service: "test",
|
||||
Endpoint: "localhost:4717",
|
||||
InstanceID: "s01",
|
||||
Version: "v0.0.1",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "no service",
|
||||
wantErr: true,
|
||||
config: Config{
|
||||
Enabled: true,
|
||||
Exporter: OTLPgRPC,
|
||||
Endpoint: "localhost:4717",
|
||||
InstanceID: "s01",
|
||||
Version: "v0.0.1",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "no endpoint for grpc",
|
||||
wantErr: true,
|
||||
config: Config{
|
||||
Enabled: true,
|
||||
Exporter: OTLPgRPC,
|
||||
Service: "test",
|
||||
InstanceID: "s01",
|
||||
Version: "v0.0.1",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if err := tt.config.validate(); (err != nil) != tt.wantErr {
|
||||
t.Errorf("Config.validate() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfig_hasChange(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
config Config
|
||||
other Config
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "disabled configs always equal",
|
||||
want: false,
|
||||
config: Config{
|
||||
Enabled: false,
|
||||
Exporter: Stdout,
|
||||
Service: "test",
|
||||
InstanceID: "s01",
|
||||
Version: "v1.0.0",
|
||||
},
|
||||
other: Config{
|
||||
Enabled: false,
|
||||
Exporter: OTLPgRPC,
|
||||
Endpoint: "localhost:4717",
|
||||
Service: "test",
|
||||
InstanceID: "s01",
|
||||
Version: "v1.0.0",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "enabled",
|
||||
want: true,
|
||||
config: Config{
|
||||
Enabled: false,
|
||||
Exporter: OTLPgRPC,
|
||||
Endpoint: "localhost:4717",
|
||||
Service: "test",
|
||||
InstanceID: "s01",
|
||||
Version: "v1.0.0",
|
||||
},
|
||||
other: Config{
|
||||
Enabled: true,
|
||||
Exporter: OTLPgRPC,
|
||||
Endpoint: "localhost:4717",
|
||||
Service: "test",
|
||||
InstanceID: "s01",
|
||||
Version: "v1.0.0",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "disabled",
|
||||
want: true,
|
||||
config: Config{
|
||||
Enabled: true,
|
||||
Exporter: OTLPgRPC,
|
||||
Endpoint: "localhost:4717",
|
||||
Service: "test",
|
||||
InstanceID: "s01",
|
||||
Version: "v1.0.0",
|
||||
},
|
||||
other: Config{
|
||||
Enabled: false,
|
||||
Exporter: OTLPgRPC,
|
||||
Endpoint: "localhost:4717",
|
||||
Service: "test",
|
||||
InstanceID: "s01",
|
||||
Version: "v1.0.0",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "do not use endpoint for stdout",
|
||||
want: false,
|
||||
config: Config{
|
||||
Enabled: true,
|
||||
Exporter: Stdout,
|
||||
Endpoint: "localhost:4717",
|
||||
Service: "test",
|
||||
InstanceID: "s01",
|
||||
Version: "v1.0.0",
|
||||
},
|
||||
other: Config{
|
||||
Enabled: true,
|
||||
Exporter: Stdout,
|
||||
Endpoint: "otherhost:4717",
|
||||
Service: "test",
|
||||
InstanceID: "s01",
|
||||
Version: "v1.0.0",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "use endpoint for grpc",
|
||||
want: true,
|
||||
config: Config{
|
||||
Enabled: true,
|
||||
Exporter: OTLPgRPC,
|
||||
Endpoint: "localhost:4717",
|
||||
Service: "test",
|
||||
InstanceID: "s01",
|
||||
Version: "v1.0.0",
|
||||
},
|
||||
other: Config{
|
||||
Enabled: true,
|
||||
Exporter: OTLPgRPC,
|
||||
Endpoint: "otherhost:4717",
|
||||
Service: "test",
|
||||
InstanceID: "s01",
|
||||
Version: "v1.0.0",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := tt.config.hasChange(&tt.other); got != tt.want {
|
||||
t.Errorf("Config.equal() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue