Skip to content

Commit

Permalink
Proper shutdown tracer when the work is done
Browse files Browse the repository at this point in the history
  • Loading branch information
mgencur committed Aug 17, 2022
1 parent dbd3fc3 commit 2e34855
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions cmd/activator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ func main() {
go throttler.Run(ctx, transport, networkConfig.EnableMeshPodAddressability, networkConfig.MeshCompatibilityMode)

oct := tracing.NewOpenCensusTracer(tracing.WithExporterFull(networking.ActivatorServiceName, env.PodIP, logger))
defer oct.Shutdown(context.Background())

tracerUpdater := configmap.TypeFilter(&tracingconfig.Config{})(func(name string, value interface{}) {
cfg := value.(*tracingconfig.Config)
Expand Down
23 changes: 13 additions & 10 deletions pkg/queue/sharedmain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,18 @@ func Main(opts ...Option) error {
zap.String(logkey.Pod, env.ServingPod))

d.Logger = logger
d.Transport = buildTransport(env, logger)
d.Transport = buildTransport(env)

if env.TracingConfigBackend != tracingconfig.None {
oct := tracing.NewOpenCensusTracer(tracing.WithExporterFull(env.ServingPod, env.ServingPodIP, logger))
oct.ApplyConfig(&tracingconfig.Config{
Backend: env.TracingConfigBackend,
Debug: env.TracingConfigDebug,
ZipkinEndpoint: env.TracingConfigZipkinEndpoint,
SampleRate: env.TracingConfigSampleRate,
})
defer oct.Shutdown(context.Background())
}

// allow extensions to read d and return modified context and transport
for _, opts := range opts {
Expand Down Expand Up @@ -400,7 +411,7 @@ func buildServer(ctx context.Context, env config, transport http.RoundTripper, p
return pkgnet.NewServer(":"+env.QueueServingPort, composedHandler), drainer.Drain
}

func buildTransport(env config, logger *zap.SugaredLogger) http.RoundTripper {
func buildTransport(env config) http.RoundTripper {
maxIdleConns := 1000 // TODO: somewhat arbitrary value for CC=0, needs experimental validation.
if env.ContainerConcurrency > 0 {
maxIdleConns = env.ContainerConcurrency
Expand All @@ -412,14 +423,6 @@ func buildTransport(env config, logger *zap.SugaredLogger) http.RoundTripper {
return transport
}

oct := tracing.NewOpenCensusTracer(tracing.WithExporterFull(env.ServingPod, env.ServingPodIP, logger))
oct.ApplyConfig(&tracingconfig.Config{
Backend: env.TracingConfigBackend,
Debug: env.TracingConfigDebug,
ZipkinEndpoint: env.TracingConfigZipkinEndpoint,
SampleRate: env.TracingConfigSampleRate,
})

return &ochttp.Transport{
Base: transport,
Propagation: tracecontextb3.TraceContextB3Egress,
Expand Down

0 comments on commit 2e34855

Please sign in to comment.