Skip to content

Add a flag in tracing config to use service instead of pod name #3164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions tracing/config/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ const (
// ConfigName is the name of the configmap
ConfigName = "config-tracing"

enableKey = "enable"
backendKey = "backend"
zipkinEndpointKey = "zipkin-endpoint"
debugKey = "debug"
sampleRateKey = "sample-rate"
enableKey = "enable"
backendKey = "backend"
zipkinEndpointKey = "zipkin-endpoint"
debugKey = "debug"
sampleRateKey = "sample-rate"
useServingServiceKey = "use-serving-service"
)

// BackendType specifies the backend to use for tracing
Expand All @@ -54,8 +55,9 @@ type Config struct {
Backend BackendType
ZipkinEndpoint string

Debug bool
SampleRate float64
Debug bool
SampleRate float64
UseServingService bool
}

// Equals returns true if two Configs are identical
Expand All @@ -66,9 +68,10 @@ func (cfg *Config) Equals(other *Config) bool {
// NoopConfig returns a new noop config
func NoopConfig() *Config {
return &Config{
Backend: None,
Debug: false,
SampleRate: 0.1,
Backend: None,
Debug: false,
SampleRate: 0.1,
UseServingService: false,
}
}

Expand Down Expand Up @@ -98,6 +101,7 @@ func NewTracingConfigFromMap(cfgMap map[string]string) (*Config, error) {
cm.AsString(zipkinEndpointKey, &tc.ZipkinEndpoint),
cm.AsBool(debugKey, &tc.Debug),
cm.AsFloat64(sampleRateKey, &tc.SampleRate),
cm.AsBool(useServingServiceKey, &tc.UseServingService),
); err != nil {
return nil, err
}
Expand Down Expand Up @@ -152,6 +156,7 @@ func TracingConfigToJSON(cfg *Config) (string, error) {
}
out[debugKey] = strconv.FormatBool(cfg.Debug)
out[sampleRateKey] = fmt.Sprint(cfg.SampleRate)
out[useServingServiceKey] = strconv.FormatBool(cfg.UseServingService)

jsonCfg, err := json.Marshal(out)
return string(jsonCfg), err
Expand Down
77 changes: 45 additions & 32 deletions tracing/config/tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,34 @@ func TestNewConfigSuccess(t *testing.T) {
}, {
name: "Everything enabled (legacy)",
input: map[string]string{
enableKey: "true",
zipkinEndpointKey: "some-endpoint",
debugKey: "true",
sampleRateKey: "0.5",
enableKey: "true",
zipkinEndpointKey: "some-endpoint",
debugKey: "true",
sampleRateKey: "0.5",
useServingServiceKey: "true",
},
output: &Config{
Backend: Zipkin,
Debug: true,
ZipkinEndpoint: "some-endpoint",
SampleRate: 0.5,
Backend: Zipkin,
Debug: true,
ZipkinEndpoint: "some-endpoint",
SampleRate: 0.5,
UseServingService: true,
},
}, {
name: "Everything enabled (zipkin)",
input: map[string]string{
backendKey: "zipkin",
zipkinEndpointKey: "some-endpoint",
debugKey: "true",
sampleRateKey: "0.5",
backendKey: "zipkin",
zipkinEndpointKey: "some-endpoint",
debugKey: "true",
sampleRateKey: "0.5",
useServingServiceKey: "true",
},
output: &Config{
Backend: Zipkin,
Debug: true,
ZipkinEndpoint: "some-endpoint",
SampleRate: 0.5,
Backend: Zipkin,
Debug: true,
ZipkinEndpoint: "some-endpoint",
SampleRate: 0.5,
UseServingService: true,
},
}}

Expand Down Expand Up @@ -116,30 +120,34 @@ func TestNewConfigJSON(t *testing.T) {
}, {
name: "Everything enabled (legacy)",
input: map[string]string{
enableKey: "true",
zipkinEndpointKey: "some-endpoint",
debugKey: "true",
sampleRateKey: "0.5",
enableKey: "true",
zipkinEndpointKey: "some-endpoint",
debugKey: "true",
sampleRateKey: "0.5",
useServingServiceKey: "true",
},
output: &Config{
Backend: Zipkin,
Debug: true,
ZipkinEndpoint: "some-endpoint",
SampleRate: 0.5,
Backend: Zipkin,
Debug: true,
ZipkinEndpoint: "some-endpoint",
SampleRate: 0.5,
UseServingService: true,
},
}, {
name: "Everything enabled (zipkin)",
input: map[string]string{
backendKey: "zipkin",
zipkinEndpointKey: "some-endpoint",
debugKey: "true",
sampleRateKey: "0.5",
backendKey: "zipkin",
zipkinEndpointKey: "some-endpoint",
debugKey: "true",
sampleRateKey: "0.5",
useServingServiceKey: "true",
},
output: &Config{
Backend: Zipkin,
Debug: true,
ZipkinEndpoint: "some-endpoint",
SampleRate: 0.5,
Backend: Zipkin,
Debug: true,
ZipkinEndpoint: "some-endpoint",
SampleRate: 0.5,
UseServingService: true,
},
}}

Expand Down Expand Up @@ -206,6 +214,11 @@ func TestNewConfigFailures(t *testing.T) {
input: map[string]string{
enableKey: "dot dash dot",
},
}, {
name: "useServingService invalid value",
input: map[string]string{
enableKey: "not a boolean",
},
}}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
Expand Down