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 Keep-Alive flag for Zipkin HTTP server #4366

Merged
merged 2 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions cmd/collector/app/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func (c *Collector) Start(options *flags.CollectorOptions) error {
AllowedOrigins: options.Zipkin.AllowedOrigins,
Logger: c.logger,
MetricsFactory: c.metricsFactory,
KeepAlive: options.Zipkin.KeepAlive,
})
if err != nil {
return fmt.Errorf("could not start Zipkin server: %w", err)
Expand Down
11 changes: 8 additions & 3 deletions cmd/collector/app/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ const (

flagCollectorOTLPEnabled = "collector.otlp.enabled"

flagZipkinHTTPHostPort = "collector.zipkin.host-port"
flagZipkinAllowedHeaders = "collector.zipkin.allowed-headers"
flagZipkinAllowedOrigins = "collector.zipkin.allowed-origins"
flagZipkinHTTPHostPort = "collector.zipkin.host-port"
flagZipkinAllowedHeaders = "collector.zipkin.allowed-headers"
flagZipkinAllowedOrigins = "collector.zipkin.allowed-origins"
flagZipkinKeepAliveEnabled = "collector.zipkin.keep-alive"

// DefaultNumWorkers is the default number of workers consuming from the processor queue
DefaultNumWorkers = 50
Expand Down Expand Up @@ -126,6 +127,8 @@ type CollectorOptions struct {
AllowedHeaders string
// TLS configures secure transport for Zipkin endpoint to collect spans
TLS tlscfg.Options
// KeepAlive configures allow Keep-Alive for Zipkin HTTP server
KeepAlive bool
}
// CollectorTags is the string representing collector tags to append to each and every span
CollectorTags map[string]string
Expand Down Expand Up @@ -188,6 +191,7 @@ func AddFlags(flags *flag.FlagSet) {
flags.String(flagZipkinAllowedHeaders, "content-type", "Comma separated list of allowed headers for the Zipkin collector service, default content-type")
flags.String(flagZipkinAllowedOrigins, "*", "Comma separated list of allowed origins for the Zipkin collector service, default accepts all")
flags.String(flagZipkinHTTPHostPort, "", "The host:port (e.g. 127.0.0.1:9411 or :9411) of the collector's Zipkin server (disabled by default)")
flags.Bool(flagZipkinKeepAliveEnabled, true, "KeepAlive configures allow Keep-Alive for Zipkin HTTP server (enabled by default)")
tlsZipkinFlagsConfig.AddFlags(flags)

tenancy.AddFlags(flags)
Expand Down Expand Up @@ -275,6 +279,7 @@ func (cOpts *CollectorOptions) InitFromViper(v *viper.Viper, logger *zap.Logger)

cOpts.Zipkin.AllowedHeaders = v.GetString(flagZipkinAllowedHeaders)
cOpts.Zipkin.AllowedOrigins = v.GetString(flagZipkinAllowedOrigins)
cOpts.Zipkin.KeepAlive = v.GetBool(flagZipkinKeepAliveEnabled)
cOpts.Zipkin.HTTPHostPort = ports.FormatHostPort(v.GetString(flagZipkinHTTPHostPort))
if tlsZipkin, err := tlsZipkinFlagsConfig.InitFromViper(v); err == nil {
cOpts.Zipkin.TLS = tlsZipkin
Expand Down
11 changes: 11 additions & 0 deletions cmd/collector/app/flags/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,14 @@ func TestCollectorOptionsWithFlags_CheckFullTenancy(t *testing.T) {
assert.Equal(t, "custom-tenant-header", c.GRPC.Tenancy.Header)
assert.Equal(t, []string{"acme", "hardware-store"}, c.GRPC.Tenancy.Tenants)
}

func TestCollectorOptionsWithFlags_CheckZipkinKeepAlive(t *testing.T) {
c := &CollectorOptions{}
v, command := config.Viperize(AddFlags)
command.ParseFlags([]string{
"--collector.zipkin.keep-alive=false",
})
c.InitFromViper(v, zap.NewNop())

assert.Equal(t, false, c.Zipkin.KeepAlive)
}
3 changes: 3 additions & 0 deletions cmd/collector/app/server/zipkin.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type ZipkinServerParams struct {
HealthCheck *healthcheck.HealthCheck
Logger *zap.Logger
MetricsFactory metrics.Factory
KeepAlive bool
}

// StartZipkinServer based on the given parameters
Expand Down Expand Up @@ -73,6 +74,8 @@ func StartZipkinServer(params *ZipkinServerParams) (*http.Server, error) {
}
server.TLSConfig = tlsCfg
}

server.SetKeepAlivesEnabled(params.KeepAlive)
serveZipkin(server, listener, params)

return server, nil
Expand Down