Skip to content

Commit

Permalink
Merge pull request #81 from uswitch/add-zipkin-tracing
Browse files Browse the repository at this point in the history
Add optional zipkin tracing provider config for HTTP Connection Manager
  • Loading branch information
meghaniankov authored Feb 2, 2024
2 parents 985eb91 + 4566964 commit 5b3ceb2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ The Yggdrasil-specific metrics which are available from the API are:
--max-ejection-percentage int32 maximal percentage of hosts ejected via outlier detection. Set to >=0 to activate outlier detection in envoy. (default -1)
--node-name string envoy node name
--retry-on string default comma-separated list of retry policies (default "5xx")
--tracing-provider name of HTTP Connection Manager tracing provider to include - currently only zipkin config is supported
--upstream-healthcheck-healthy uint32 number of successful healthchecks before the backend is considered healthy (default 3)
--upstream-healthcheck-interval duration duration of the upstream health check interval (default 10s)
--upstream-healthcheck-timeout duration timeout of the upstream healthchecks (default 5s)
Expand Down
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")
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
}
}

0 comments on commit 5b3ceb2

Please sign in to comment.