From 6d5c95c68d70c38b41f9b1062fdd4436d552f2b8 Mon Sep 17 00:00:00 2001 From: meghaniankov Date: Wed, 31 Jan 2024 12:14:34 +0000 Subject: [PATCH] make tracing provider config optional --- cmd/root.go | 2 ++ pkg/envoy/boilerplate.go | 27 ++++++++++++++++++--------- pkg/envoy/configurator.go | 5 +++-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 1743115..120b437 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -91,6 +91,7 @@ func init() { rootCmd.PersistentFlags().Int32("max-ejection-percentage", -1, "maximal percentage of hosts ejected via outlier detection. Set to >=0 to activate outlier detection in envoy.") rootCmd.PersistentFlags().Int64("host-selection-retry-attempts", -1, "Number of host selection retry attempts. Set to value >=0 to enable") rootCmd.PersistentFlags().String("retry-on", "5xx", "default comma-separated list of retry policies") + rootCmd.PersistentFlags().String("tracing-provider", "", "HTTP Connection Manager tracing provider block to include") rootCmd.PersistentFlags().Duration("upstream-healthcheck-interval", 10*time.Second, "duration of the upstream health check interval") rootCmd.PersistentFlags().Duration("upstream-healthcheck-timeout", 5*time.Second, "timeout of the upstream healthchecks") rootCmd.PersistentFlags().Uint32("upstream-healthcheck-healthy", 3, "number of successful healthchecks before the backend is considered healthy") @@ -123,6 +124,7 @@ func init() { viper.BindPFlag("maxEjectionPercentage", rootCmd.PersistentFlags().Lookup("max-ejection-percentage")) viper.BindPFlag("hostSelectionRetryAttempts", rootCmd.PersistentFlags().Lookup("host-selection-retry-attempts")) viper.BindPFlag("retryOn", rootCmd.PersistentFlags().Lookup("retry-on")) + viper.BindPFlag("tracingProvider", rootCmd.PersistentFlags().Lookup("tracing-provider")) viper.BindPFlag("upstreamHealthCheck.interval", rootCmd.PersistentFlags().Lookup("upstream-healthcheck-interval")) viper.BindPFlag("upstreamHealthCheck.timeout", rootCmd.PersistentFlags().Lookup("upstream-healthcheck-timeout")) viper.BindPFlag("upstreamHealthCheck.healthyThreshold", rootCmd.PersistentFlags().Lookup("upstream-healthcheck-healthy")) diff --git a/pkg/envoy/boilerplate.go b/pkg/envoy/boilerplate.go index d677d1d..ca1f735 100644 --- a/pkg/envoy/boilerplate.go +++ b/pkg/envoy/boilerplate.go @@ -216,7 +216,7 @@ func makeZipkinTracingProvider() *tracing.ZipkinConfig { return zipkinTracingProviderConfig } -func (c *KubernetesConfigurator) makeConnectionManager(virtualHosts []*route.VirtualHost) (*hcm.HttpConnectionManager, error) { +func (c *KubernetesConfigurator) makeConnectionManager(virtualHosts []*route.VirtualHost, tracingProvider string) (*hcm.HttpConnectionManager, error) { // Access Logs accessLogConfig := makeFileAccessLog(c.accessLogger) anyAccessLogConfig, err := anypb.New(accessLogConfig) @@ -272,7 +272,21 @@ func (c *KubernetesConfigurator) makeConnectionManager(virtualHosts []*route.Vir return &hcm.HttpConnectionManager{}, err } - zipkinTracingProvider, err := anypb.New(makeZipkinTracingProvider()) + tracingProviderConfig := &hcm.HttpConnectionManager_Tracing{} + + if tracingProvider == "zipkin" { + zipkinTracingProvider, err := anypb.New(makeZipkinTracingProvider()) + if err != nil { + log.Fatal(err) + } + + tracingProviderConfig = &hcm.HttpConnectionManager_Tracing{ + Provider: &tracing.Tracing_Http{ + Name: "config.trace.v3.Tracing.Http", + ConfigType: &tracing.Tracing_Http_TypedConfig{TypedConfig: zipkinTracingProvider}, + }, + } + } return &hcm.HttpConnectionManager{ CodecType: hcm.HttpConnectionManager_AUTO, @@ -289,19 +303,14 @@ func (c *KubernetesConfigurator) makeConnectionManager(virtualHosts []*route.Vir VirtualHosts: virtualHosts, }, }, - Tracing: &hcm.HttpConnectionManager_Tracing{ - Provider: &tracing.Tracing_Http{ - Name: "config.trace.v3.Tracing.Http", - ConfigType: &tracing.Tracing_Http_TypedConfig{TypedConfig: zipkinTracingProvider}, - }, - }, + Tracing: tracingProviderConfig, AccessLog: accessLoggers, UseRemoteAddress: &wrapperspb.BoolValue{Value: c.useRemoteAddress}, }, nil } func (c *KubernetesConfigurator) makeFilterChain(certificate Certificate, virtualHosts []*route.VirtualHost) (listener.FilterChain, error) { - httpConnectionManager, err := c.makeConnectionManager(virtualHosts) + httpConnectionManager, err := c.makeConnectionManager(virtualHosts, c.tracingProvider) if err != nil { return listener.FilterChain{}, fmt.Errorf("failed to get httpConnectionManager: %s", err) } diff --git a/pkg/envoy/configurator.go b/pkg/envoy/configurator.go index fc13a9a..ebeae64 100644 --- a/pkg/envoy/configurator.go +++ b/pkg/envoy/configurator.go @@ -69,6 +69,7 @@ type KubernetesConfigurator struct { httpGrpcLogger HttpGrpcLogger accessLogger AccessLogger defaultRetryOn string + tracingProvider string previousConfig *envoyConfiguration listenerVersion string @@ -85,7 +86,7 @@ func NewKubernetesConfigurator(nodeID string, certificates []Certificate, ca str return c } -//Generate creates a new snapshot +// Generate creates a new snapshot func (c *KubernetesConfigurator) Generate(ingresses []*k8s.Ingress, secrets []*v1.Secret) (cache.Snapshot, error) { c.Lock() defer c.Unlock() @@ -236,7 +237,7 @@ func (c *KubernetesConfigurator) generateHTTPFilterChain(config *envoyConfigurat virtualHosts = append(virtualHosts, vhost) } - httpConnectionManager, err := c.makeConnectionManager(virtualHosts) + httpConnectionManager, err := c.makeConnectionManager(virtualHosts, c.tracingProvider) if err != nil { return nil, err }