Skip to content
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

Add optional zipkin tracing provider config for HTTP Connection Manager #81

Merged
merged 8 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
3 changes: 3 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")
meghaniankov marked this conversation as resolved.
Show resolved Hide resolved
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 Expand Up @@ -241,6 +243,7 @@ func main(*cobra.Command, []string) error {
envoy.WithSyncSecrets(c.SyncSecrets),
envoy.WithDefaultRetryOn(viper.GetString("retryOn")),
envoy.WithAccessLog(c.AccessLogger),
envoy.WithTracingProvider(viper.GetString("tracingProvider")),
)
snapshotter := envoy.NewSnapshotter(envoyCache, configurator, aggregator)

Expand Down
27 changes: 26 additions & 1 deletion pkg/envoy/boilerplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
endpoint "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
listener "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
route "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
tracing "github.com/envoyproxy/go-control-plane/envoy/config/trace/v3"
eal "github.com/envoyproxy/go-control-plane/envoy/extensions/access_loggers/file/v3"
gal "github.com/envoyproxy/go-control-plane/envoy/extensions/access_loggers/grpc/v3"
eauthz "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/ext_authz/v3"
Expand Down Expand Up @@ -205,6 +206,16 @@ func makeFileAccessLog(cfg AccessLogger) *eal.FileAccessLog {
return accessLogConfig
}

func makeZipkinTracingProvider() *tracing.ZipkinConfig {
zipkinTracingProviderConfig := &tracing.ZipkinConfig{
CollectorCluster: "zipkin",
CollectorEndpoint: "/api/v2/spans",
CollectorEndpointVersion: tracing.ZipkinConfig_HTTP_JSON,
}

return zipkinTracingProviderConfig
}

func (c *KubernetesConfigurator) makeConnectionManager(virtualHosts []*route.VirtualHost) (*hcm.HttpConnectionManager, error) {
// Access Logs
accessLogConfig := makeFileAccessLog(c.accessLogger)
Expand Down Expand Up @@ -261,6 +272,20 @@ func (c *KubernetesConfigurator) makeConnectionManager(virtualHosts []*route.Vir
return &hcm.HttpConnectionManager{}, err
}

tracingConfig := &hcm.HttpConnectionManager_Tracing{}

if c.tracingProvider == "zipkin" {
zipkinTracingProvider, err := anypb.New(makeZipkinTracingProvider())
if err != nil {
log.Fatalf("failed to set zipkin tracing provider config: %s", err)
}

tracingConfig.Provider = &tracing.Tracing_Http{
Name: "config.trace.v3.Tracing.Http",
ConfigType: &tracing.Tracing_Http_TypedConfig{TypedConfig: zipkinTracingProvider},
}
}

return &hcm.HttpConnectionManager{
CodecType: hcm.HttpConnectionManager_AUTO,
StatPrefix: "ingress_http",
Expand All @@ -276,7 +301,7 @@ func (c *KubernetesConfigurator) makeConnectionManager(virtualHosts []*route.Vir
VirtualHosts: virtualHosts,
},
},
Tracing: &hcm.HttpConnectionManager_Tracing{},
Tracing: tracingConfig,
AccessLog: accessLoggers,
UseRemoteAddress: &wrapperspb.BoolValue{Value: c.useRemoteAddress},
}, nil
Expand Down
3 changes: 2 additions & 1 deletion 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
7 changes: 7 additions & 0 deletions pkg/envoy/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,10 @@ func WithAccessLog(accessLogger AccessLogger) option {
c.accessLogger = accessLogger
}
}

// WithTracingProvider configures the tracing provider for HTTP connection manager
func WithTracingProvider(tracingProvider string) option {
return func(c *KubernetesConfigurator) {
c.tracingProvider = tracingProvider
}
}
Loading