Skip to content

Commit

Permalink
make tracing provider config optional
Browse files Browse the repository at this point in the history
  • Loading branch information
meghaniankov committed Jan 31, 2024
1 parent 78811f6 commit 6d5c95c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"))
Expand Down
27 changes: 18 additions & 9 deletions pkg/envoy/boilerplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/envoy/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type KubernetesConfigurator struct {
httpGrpcLogger HttpGrpcLogger
accessLogger AccessLogger
defaultRetryOn string
tracingProvider string

previousConfig *envoyConfiguration
listenerVersion string
Expand All @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 6d5c95c

Please sign in to comment.