Skip to content

Commit

Permalink
refactor: remove pointer, add envconfig and test
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Beaumont <mjboamail@gmail.com>
  • Loading branch information
michaelbeaumont committed Jun 30, 2023
1 parent 2351c8d commit 1b23e5c
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 9 deletions.
4 changes: 4 additions & 0 deletions docs/generated/kuma-cp.md
Original file line number Diff line number Diff line change
Expand Up @@ -700,4 +700,8 @@ proxy:
# Sets the envoy runtime value to limit maximum number of incoming
# connections to a builtin gateway data plane proxy
globalDownstreamMaxConnections: 50000 # ENV: KUMA_PROXY_GATEWAY_GLOBAL_DOWNSTREAM_MAX_CONNECTIONS

tracing:
openTelemetry:
endpoint: "" # e.g. otel-collector:4317
```
4 changes: 1 addition & 3 deletions pkg/api-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ func NewApiServer(
}
container.Filter(cors.Filter)

if cfg.Tracing != nil {
container.Filter(otelrestful.OTelFilter("api-server"))
}
container.Filter(otelrestful.OTelFilter("api-server"))

// We create a WebService and set up resources endpoints and index endpoint instead of creating WebService
// for every resource like /meshes/{mesh}/traffic-permissions, /meshes/{mesh}/traffic-log etc.
Expand Down
5 changes: 4 additions & 1 deletion pkg/config/app/kuma-cp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ type Config struct {
// Intercommunication CP configuration
InterCp intercp.InterCpConfig `json:"interCp"`
// Tracing
Tracing *tracing.Config `json:"tracing"`
Tracing tracing.Config `json:"tracing"`
}

func (c *Config) Sanitize() {
Expand Down Expand Up @@ -290,6 +290,9 @@ func (c *Config) Validate() error {
if err := c.InterCp.Validate(); err != nil {
return errors.Wrap(err, "InterCp validation failed")
}
if err := c.Tracing.Validate(); err != nil {
return errors.Wrap(err, "Tracing validation failed")
}
return nil
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/config/app/kuma-cp/kuma-cp.defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -697,3 +697,7 @@ proxy:
# Sets the envoy runtime value to limit maximum number of incoming
# connections to a builtin gateway data plane proxy
globalDownstreamMaxConnections: 50000 # ENV: KUMA_PROXY_GATEWAY_GLOBAL_DOWNSTREAM_MAX_CONNECTIONS

tracing:
openTelemetry:
endpoint: "" # e.g. otel-collector:4317
1 change: 1 addition & 0 deletions pkg/config/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ proxy:
"KUMA_EXPERIMENTAL_USE_TAG_FIRST_VIRTUAL_OUTBOUND_MODEL": "false",
"KUMA_EXPERIMENTAL_INGRESS_TAG_FILTERS": "kuma.io/service",
"KUMA_PROXY_GATEWAY_GLOBAL_DOWNSTREAM_MAX_CONNECTIONS": "1",
"KUMA_TRACING_OPENTELEMETRY_ENDPOINT": "otel-collector:4317",
},
yamlFileConfig: "",
}),
Expand Down
16 changes: 14 additions & 2 deletions pkg/config/tracing/config.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
package tracing

type Config struct {
OpenTelemetry OpenTelemetry `json:"openTelemetry"`
OpenTelemetry OpenTelemetry `json:"openTelemetry,omitempty"`
}

func (c Config) Validate() error {
if err := c.OpenTelemetry.Validate(); err != nil {
return err
}

return nil
}

type OpenTelemetry struct {
// Address of OpenTelemetry collector.
// E.g. otel-collector:4317
Endpoint string `json:"endpoint"`
Endpoint string `json:"endpoint,omitempty" envconfig:"kuma_tracing_opentelemetry_endpoint"`
}

func (c OpenTelemetry) Validate() error {
return nil
}
6 changes: 3 additions & 3 deletions pkg/plugins/runtime/opentelemetry/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ func (t *tracer) NeedLeaderElection() bool {
}

func (p *plugin) Customize(rt core_runtime.Runtime) error {
tracing := rt.Config().Tracing
if tracing == nil {
otel := rt.Config().Tracing.OpenTelemetry
if otel.Endpoint == "" {
return nil
}

t := tracer{
config: tracing.OpenTelemetry,
config: otel,
}
if err := rt.Add(component.NewResilientComponent(core.Log.WithName("otel-tracer"), &t)); err != nil {
return err
Expand Down

0 comments on commit 1b23e5c

Please sign in to comment.