From 51487a4979b905f2643516eee55c2cc418996c3f Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Tue, 2 Jul 2024 23:09:12 +0530 Subject: [PATCH 01/29] Draft Changes to Query using telset Signed-off-by: Wise-Wizard --- cmd/jaeger/internal/extension/jaegerquery/server.go | 7 +++++-- cmd/query/app/server.go | 11 ++++++----- cmd/query/app/token_propagation_test.go | 7 +++++-- cmd/query/main.go | 6 +++++- pkg/telemetery/settings.go | 13 +++++++++++++ 5 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 pkg/telemetery/settings.go diff --git a/cmd/jaeger/internal/extension/jaegerquery/server.go b/cmd/jaeger/internal/extension/jaegerquery/server.go index dc9fc29323d..4e07f30c19e 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server.go @@ -17,6 +17,7 @@ import ( "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" "github.com/jaegertracing/jaeger/pkg/healthcheck" "github.com/jaegertracing/jaeger/pkg/jtracer" + "github.com/jaegertracing/jaeger/pkg/telemetery" "github.com/jaegertracing/jaeger/pkg/tenancy" "github.com/jaegertracing/jaeger/plugin/metrics/disabled" "github.com/jaegertracing/jaeger/ports" @@ -83,14 +84,16 @@ func (s *server) Start(_ context.Context, host component.Host) error { // TODO contextcheck linter complains about next line that context is not passed. It is not wrong. //nolint s.server, err = queryApp.NewServer( - s.logger, + telemetery.TelemeterySetting{ + Logger: s.logger, + Tracer: s.jtracer, + }, // TODO propagate healthcheck updates up to the collector's runtime healthcheck.New(), qs, metricsQueryService, s.makeQueryOptions(), tm, - s.jtracer, ) if err != nil { return fmt.Errorf("could not create jaeger-query: %w", err) diff --git a/cmd/query/app/server.go b/cmd/query/app/server.go index c2debad540a..fb86fcc08e1 100644 --- a/cmd/query/app/server.go +++ b/cmd/query/app/server.go @@ -42,6 +42,7 @@ import ( "github.com/jaegertracing/jaeger/pkg/jtracer" "github.com/jaegertracing/jaeger/pkg/netutils" "github.com/jaegertracing/jaeger/pkg/recoveryhandler" + "github.com/jaegertracing/jaeger/pkg/telemetery" "github.com/jaegertracing/jaeger/pkg/tenancy" "github.com/jaegertracing/jaeger/proto-gen/api_v2" "github.com/jaegertracing/jaeger/proto-gen/api_v2/metrics" @@ -67,7 +68,7 @@ type Server struct { } // NewServer creates and initializes Server -func NewServer(logger *zap.Logger, healthCheck *healthcheck.HealthCheck, querySvc *querysvc.QueryService, metricsQuerySvc querysvc.MetricsQueryService, options *QueryOptions, tm *tenancy.Manager, tracer *jtracer.JTracer) (*Server, error) { +func NewServer(telset telemetery.TelemeterySetting, healthCheck *healthcheck.HealthCheck, querySvc *querysvc.QueryService, metricsQuerySvc querysvc.MetricsQueryService, options *QueryOptions, tm *tenancy.Manager) (*Server, error) { _, httpPort, err := net.SplitHostPort(options.HTTPHostPort) if err != nil { return nil, fmt.Errorf("invalid HTTP server host:port: %w", err) @@ -81,22 +82,22 @@ func NewServer(logger *zap.Logger, healthCheck *healthcheck.HealthCheck, querySv return nil, errors.New("server with TLS enabled can not use same host ports for gRPC and HTTP. Use dedicated HTTP and gRPC host ports instead") } - grpcServer, err := createGRPCServer(querySvc, metricsQuerySvc, options, tm, logger, tracer) + grpcServer, err := createGRPCServer(querySvc, metricsQuerySvc, options, tm, telset.Logger, telset.Tracer) if err != nil { return nil, err } - httpServer, err := createHTTPServer(querySvc, metricsQuerySvc, options, tm, tracer, logger) + httpServer, err := createHTTPServer(querySvc, metricsQuerySvc, options, tm, telset.Tracer, telset.Logger) if err != nil { return nil, err } return &Server{ - logger: logger, + logger: telset.Logger, healthCheck: healthCheck, querySvc: querySvc, queryOptions: options, - tracer: tracer, + tracer: telset.Tracer, grpcServer: grpcServer, httpServer: httpServer, separatePorts: grpcPort != httpPort, diff --git a/cmd/query/app/token_propagation_test.go b/cmd/query/app/token_propagation_test.go index 1e9a0ebfea4..6d79146f459 100644 --- a/cmd/query/app/token_propagation_test.go +++ b/cmd/query/app/token_propagation_test.go @@ -32,6 +32,7 @@ import ( "github.com/jaegertracing/jaeger/pkg/config" "github.com/jaegertracing/jaeger/pkg/jtracer" "github.com/jaegertracing/jaeger/pkg/metrics" + "github.com/jaegertracing/jaeger/pkg/telemetery" "github.com/jaegertracing/jaeger/pkg/tenancy" "github.com/jaegertracing/jaeger/plugin/storage/es" "github.com/jaegertracing/jaeger/ports" @@ -91,7 +92,10 @@ func runQueryService(t *testing.T, esURL string) *Server { require.NoError(t, err) querySvc := querysvc.NewQueryService(spanReader, nil, querysvc.QueryServiceOptions{}) - server, err := NewServer(flagsSvc.Logger, flagsSvc.HC(), querySvc, nil, + server, err := NewServer(telemetery.TelemeterySetting{ + Logger: flagsSvc.Logger, + Tracer: jtracer.NoOp(), + }, flagsSvc.HC(), querySvc, nil, &QueryOptions{ GRPCHostPort: ":0", HTTPHostPort: ":0", @@ -100,7 +104,6 @@ func runQueryService(t *testing.T, esURL string) *Server { }, }, tenancy.NewManager(&tenancy.Options{}), - jtracer.NoOp(), ) require.NoError(t, err) require.NoError(t, server.Start()) diff --git a/cmd/query/main.go b/cmd/query/main.go index 42f698669f0..4ad54b118bf 100644 --- a/cmd/query/main.go +++ b/cmd/query/main.go @@ -37,6 +37,7 @@ import ( "github.com/jaegertracing/jaeger/pkg/config" "github.com/jaegertracing/jaeger/pkg/jtracer" "github.com/jaegertracing/jaeger/pkg/metrics" + "github.com/jaegertracing/jaeger/pkg/telemetery" "github.com/jaegertracing/jaeger/pkg/tenancy" "github.com/jaegertracing/jaeger/pkg/version" metricsPlugin "github.com/jaegertracing/jaeger/plugin/metrics" @@ -113,7 +114,10 @@ func main() { dependencyReader, *queryServiceOptions) tm := tenancy.NewManager(&queryOpts.Tenancy) - server, err := app.NewServer(svc.Logger, svc.HC(), queryService, metricsQueryService, queryOpts, tm, jt) + server, err := app.NewServer(telemetery.TelemeterySetting{ + Logger: logger, + Tracer: jt, + }, svc.HC(), queryService, metricsQueryService, queryOpts, tm) if err != nil { logger.Fatal("Failed to create server", zap.Error(err)) } diff --git a/pkg/telemetery/settings.go b/pkg/telemetery/settings.go new file mode 100644 index 00000000000..11fa4b910fe --- /dev/null +++ b/pkg/telemetery/settings.go @@ -0,0 +1,13 @@ +package telemetery + +import ( + "github.com/jaegertracing/jaeger/pkg/jtracer" + "go.opentelemetry.io/otel/metric" + "go.uber.org/zap" +) + +type TelemeterySetting struct { + Logger *zap.Logger + Tracer *jtracer.JTracer + MeterProvider metric.MeterProvider +} From 59aa43ab49fea1c07d2e2d607b58de5a5ba6dd45 Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Tue, 2 Jul 2024 23:17:39 +0530 Subject: [PATCH 02/29] Changed all-in-one code Signed-off-by: Wise-Wizard --- cmd/all-in-one/main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/all-in-one/main.go b/cmd/all-in-one/main.go index 185c74a74ab..92b4b3bf201 100644 --- a/cmd/all-in-one/main.go +++ b/cmd/all-in-one/main.go @@ -43,6 +43,7 @@ import ( "github.com/jaegertracing/jaeger/pkg/config" "github.com/jaegertracing/jaeger/pkg/jtracer" "github.com/jaegertracing/jaeger/pkg/metrics" + "github.com/jaegertracing/jaeger/pkg/telemetery" "github.com/jaegertracing/jaeger/pkg/tenancy" "github.com/jaegertracing/jaeger/pkg/version" metricsPlugin "github.com/jaegertracing/jaeger/plugin/metrics" @@ -279,7 +280,10 @@ func startQuery( ) *queryApp.Server { spanReader = storageMetrics.NewReadMetricsDecorator(spanReader, metricsFactory) qs := querysvc.NewQueryService(spanReader, depReader, *queryOpts) - server, err := queryApp.NewServer(svc.Logger, svc.HC(), qs, metricsQueryService, qOpts, tm, jt) + server, err := queryApp.NewServer(telemetery.TelemeterySetting{ + Logger: svc.Logger, + Tracer: jt, + }, svc.HC(), qs, metricsQueryService, qOpts, tm) if err != nil { svc.Logger.Fatal("Could not create jaeger-query", zap.Error(err)) } From 59111ab8e50c240145e5eba9c5106da15c7da7f2 Mon Sep 17 00:00:00 2001 From: Saransh Shankar <103821431+Wise-Wizard@users.noreply.github.com> Date: Wed, 3 Jul 2024 09:32:55 +0530 Subject: [PATCH 03/29] Update pkg/telemetery/settings.go Co-authored-by: Yuri Shkuro Signed-off-by: Saransh Shankar <103821431+Wise-Wizard@users.noreply.github.com> --- pkg/telemetery/settings.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/telemetery/settings.go b/pkg/telemetery/settings.go index 11fa4b910fe..0d0e22dfe9a 100644 --- a/pkg/telemetery/settings.go +++ b/pkg/telemetery/settings.go @@ -6,7 +6,7 @@ import ( "go.uber.org/zap" ) -type TelemeterySetting struct { +type Setting struct { Logger *zap.Logger Tracer *jtracer.JTracer MeterProvider metric.MeterProvider From 5ba546b9dfefa762bed2e5c210dafec0bea9351d Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Wed, 3 Jul 2024 10:00:56 +0530 Subject: [PATCH 04/29] Made sugessted Changes Signed-off-by: Wise-Wizard --- cmd/all-in-one/main.go | 6 ++++-- cmd/jaeger/internal/extension/jaegerquery/server.go | 2 +- cmd/query/app/server.go | 9 +++++++-- cmd/query/app/token_propagation_test.go | 7 +++++-- cmd/query/main.go | 6 ++++-- pkg/telemetery/settings.go | 6 ++++-- 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/cmd/all-in-one/main.go b/cmd/all-in-one/main.go index 92b4b3bf201..7a3b34c9ca6 100644 --- a/cmd/all-in-one/main.go +++ b/cmd/all-in-one/main.go @@ -280,10 +280,12 @@ func startQuery( ) *queryApp.Server { spanReader = storageMetrics.NewReadMetricsDecorator(spanReader, metricsFactory) qs := querysvc.NewQueryService(spanReader, depReader, *queryOpts) - server, err := queryApp.NewServer(telemetery.TelemeterySetting{ + telset := telemetery.Setting{ Logger: svc.Logger, Tracer: jt, - }, svc.HC(), qs, metricsQueryService, qOpts, tm) + HC: svc.HC(), + } + server, err := queryApp.NewServer(qs, metricsQueryService, qOpts, tm, telset) if err != nil { svc.Logger.Fatal("Could not create jaeger-query", zap.Error(err)) } diff --git a/cmd/jaeger/internal/extension/jaegerquery/server.go b/cmd/jaeger/internal/extension/jaegerquery/server.go index 4e07f30c19e..647021b350d 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server.go @@ -84,7 +84,7 @@ func (s *server) Start(_ context.Context, host component.Host) error { // TODO contextcheck linter complains about next line that context is not passed. It is not wrong. //nolint s.server, err = queryApp.NewServer( - telemetery.TelemeterySetting{ + telemetery.Setting{ Logger: s.logger, Tracer: s.jtracer, }, diff --git a/cmd/query/app/server.go b/cmd/query/app/server.go index fb86fcc08e1..20979549c8f 100644 --- a/cmd/query/app/server.go +++ b/cmd/query/app/server.go @@ -68,7 +68,12 @@ type Server struct { } // NewServer creates and initializes Server -func NewServer(telset telemetery.TelemeterySetting, healthCheck *healthcheck.HealthCheck, querySvc *querysvc.QueryService, metricsQuerySvc querysvc.MetricsQueryService, options *QueryOptions, tm *tenancy.Manager) (*Server, error) { +func NewServer(querySvc *querysvc.QueryService, + metricsQuerySvc querysvc.MetricsQueryService, + options *QueryOptions, + tm *tenancy.Manager, + telset telemetery.Setting, +) (*Server, error) { _, httpPort, err := net.SplitHostPort(options.HTTPHostPort) if err != nil { return nil, fmt.Errorf("invalid HTTP server host:port: %w", err) @@ -94,7 +99,7 @@ func NewServer(telset telemetery.TelemeterySetting, healthCheck *healthcheck.Hea return &Server{ logger: telset.Logger, - healthCheck: healthCheck, + healthCheck: telset.HC, querySvc: querySvc, queryOptions: options, tracer: telset.Tracer, diff --git a/cmd/query/app/token_propagation_test.go b/cmd/query/app/token_propagation_test.go index 6d79146f459..98ee68b45cc 100644 --- a/cmd/query/app/token_propagation_test.go +++ b/cmd/query/app/token_propagation_test.go @@ -92,10 +92,12 @@ func runQueryService(t *testing.T, esURL string) *Server { require.NoError(t, err) querySvc := querysvc.NewQueryService(spanReader, nil, querysvc.QueryServiceOptions{}) - server, err := NewServer(telemetery.TelemeterySetting{ + telset := telemetery.Setting{ Logger: flagsSvc.Logger, Tracer: jtracer.NoOp(), - }, flagsSvc.HC(), querySvc, nil, + HC: flagsSvc.HC(), + } + server, err := NewServer(querySvc, nil, &QueryOptions{ GRPCHostPort: ":0", HTTPHostPort: ":0", @@ -104,6 +106,7 @@ func runQueryService(t *testing.T, esURL string) *Server { }, }, tenancy.NewManager(&tenancy.Options{}), + telset, ) require.NoError(t, err) require.NoError(t, server.Start()) diff --git a/cmd/query/main.go b/cmd/query/main.go index 4ad54b118bf..6e54731f4af 100644 --- a/cmd/query/main.go +++ b/cmd/query/main.go @@ -114,10 +114,12 @@ func main() { dependencyReader, *queryServiceOptions) tm := tenancy.NewManager(&queryOpts.Tenancy) - server, err := app.NewServer(telemetery.TelemeterySetting{ + telset := telemetery.Setting{ Logger: logger, Tracer: jt, - }, svc.HC(), queryService, metricsQueryService, queryOpts, tm) + HC: svc.HC(), + } + server, err := app.NewServer(queryService, metricsQueryService, queryOpts, tm, telset) if err != nil { logger.Fatal("Failed to create server", zap.Error(err)) } diff --git a/pkg/telemetery/settings.go b/pkg/telemetery/settings.go index 0d0e22dfe9a..2206cde45a0 100644 --- a/pkg/telemetery/settings.go +++ b/pkg/telemetery/settings.go @@ -1,13 +1,15 @@ package telemetery import ( + "github.com/jaegertracing/jaeger/pkg/healthcheck" "github.com/jaegertracing/jaeger/pkg/jtracer" - "go.opentelemetry.io/otel/metric" + "github.com/jaegertracing/jaeger/plugin/metrics" "go.uber.org/zap" ) type Setting struct { Logger *zap.Logger Tracer *jtracer.JTracer - MeterProvider metric.MeterProvider + MeterProvider metrics.Factory + HC *healthcheck.HealthCheck } From 1cfca71a7d6ab65dc63304631a5cd40b2d743f64 Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Wed, 3 Jul 2024 10:50:25 +0530 Subject: [PATCH 05/29] Fix error Signed-off-by: Wise-Wizard --- cmd/jaeger/internal/extension/jaegerquery/server.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/jaeger/internal/extension/jaegerquery/server.go b/cmd/jaeger/internal/extension/jaegerquery/server.go index 647021b350d..0bb80a26b6d 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server.go @@ -80,20 +80,20 @@ func (s *server) Start(_ context.Context, host component.Host) error { if err != nil { return fmt.Errorf("could not initialize a tracer: %w", err) } - + telset := telemetery.Setting{ + Logger: s.logger, + Tracer: s.jtracer, + HC: healthcheck.New(), + } // TODO contextcheck linter complains about next line that context is not passed. It is not wrong. //nolint s.server, err = queryApp.NewServer( - telemetery.Setting{ - Logger: s.logger, - Tracer: s.jtracer, - }, // TODO propagate healthcheck updates up to the collector's runtime - healthcheck.New(), qs, metricsQueryService, s.makeQueryOptions(), tm, + telset, ) if err != nil { return fmt.Errorf("could not create jaeger-query: %w", err) From 5a63b73f47055fa7e7ca84e3b367e7ba04eebae9 Mon Sep 17 00:00:00 2001 From: Saransh Shankar <103821431+Wise-Wizard@users.noreply.github.com> Date: Wed, 3 Jul 2024 22:21:59 +0530 Subject: [PATCH 06/29] Update pkg/telemetery/settings.go Co-authored-by: Yuri Shkuro Signed-off-by: Saransh Shankar <103821431+Wise-Wizard@users.noreply.github.com> --- pkg/telemetery/settings.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/telemetery/settings.go b/pkg/telemetery/settings.go index 2206cde45a0..760ce1852da 100644 --- a/pkg/telemetery/settings.go +++ b/pkg/telemetery/settings.go @@ -10,6 +10,6 @@ import ( type Setting struct { Logger *zap.Logger Tracer *jtracer.JTracer - MeterProvider metrics.Factory + Metrics metrics.Factory HC *healthcheck.HealthCheck } From 18fdc2d9b729f576b0ff39b9dceedd9f378b14aa Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Wed, 3 Jul 2024 22:42:45 +0530 Subject: [PATCH 07/29] Refactored telset init in all-in-one Signed-off-by: Wise-Wizard --- cmd/all-in-one/main.go | 20 ++++++++++---------- pkg/telemetery/settings.go | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cmd/all-in-one/main.go b/cmd/all-in-one/main.go index 7a3b34c9ca6..7e18bbf772b 100644 --- a/cmd/all-in-one/main.go +++ b/cmd/all-in-one/main.go @@ -194,12 +194,17 @@ by default uses only in-memory database.`, logger.Fatal("Could not create collector proxy", zap.Error(err)) } agent := startAgent(cp, aOpts, logger, agentMetricsFactory) - + telset := telemetery.Setting{ + Logger: svc.Logger, + Tracer: tracer, + Metrics: queryMetricsFactory, + HC: svc.HC(), + } // query querySrv := startQuery( svc, qOpts, qOpts.BuildQueryServiceOptions(storageFactory, logger), spanReader, dependencyReader, metricsQueryService, - queryMetricsFactory, tm, tracer, + tm, telset, ) svc.RunAndThen(func() { @@ -274,17 +279,12 @@ func startQuery( spanReader spanstore.Reader, depReader dependencystore.Reader, metricsQueryService querysvc.MetricsQueryService, - metricsFactory metrics.Factory, tm *tenancy.Manager, - jt *jtracer.JTracer, + telset telemetery.Setting, ) *queryApp.Server { - spanReader = storageMetrics.NewReadMetricsDecorator(spanReader, metricsFactory) + spanReader = storageMetrics.NewReadMetricsDecorator(spanReader, telset.Metrics) qs := querysvc.NewQueryService(spanReader, depReader, *queryOpts) - telset := telemetery.Setting{ - Logger: svc.Logger, - Tracer: jt, - HC: svc.HC(), - } + server, err := queryApp.NewServer(qs, metricsQueryService, qOpts, tm, telset) if err != nil { svc.Logger.Fatal("Could not create jaeger-query", zap.Error(err)) diff --git a/pkg/telemetery/settings.go b/pkg/telemetery/settings.go index 760ce1852da..8242964a1df 100644 --- a/pkg/telemetery/settings.go +++ b/pkg/telemetery/settings.go @@ -3,13 +3,13 @@ package telemetery import ( "github.com/jaegertracing/jaeger/pkg/healthcheck" "github.com/jaegertracing/jaeger/pkg/jtracer" - "github.com/jaegertracing/jaeger/plugin/metrics" + "github.com/jaegertracing/jaeger/pkg/metrics" "go.uber.org/zap" ) type Setting struct { - Logger *zap.Logger - Tracer *jtracer.JTracer + Logger *zap.Logger + Tracer *jtracer.JTracer Metrics metrics.Factory - HC *healthcheck.HealthCheck + HC *healthcheck.HealthCheck } From c769b4400be9722a24e2aa3f96b24530b56d9ff4 Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Thu, 4 Jul 2024 01:19:01 +0530 Subject: [PATCH 08/29] Created Healthcheck Adapter Signed-off-by: Wise-Wizard --- cmd/all-in-one/main.go | 8 +++---- .../internal/extension/jaegerquery/server.go | 6 ++--- cmd/query/app/server.go | 10 ++++---- cmd/query/app/token_propagation_test.go | 6 ++--- cmd/query/main.go | 6 ++--- pkg/telemetery/settings.go | 24 +++++++++++++++---- 6 files changed, 37 insertions(+), 23 deletions(-) diff --git a/cmd/all-in-one/main.go b/cmd/all-in-one/main.go index 7e18bbf772b..104d76f9fb8 100644 --- a/cmd/all-in-one/main.go +++ b/cmd/all-in-one/main.go @@ -195,10 +195,10 @@ by default uses only in-memory database.`, } agent := startAgent(cp, aOpts, logger, agentMetricsFactory) telset := telemetery.Setting{ - Logger: svc.Logger, - Tracer: tracer, - Metrics: queryMetricsFactory, - HC: svc.HC(), + Logger: svc.Logger, + Tracer: tracer, + Metrics: queryMetricsFactory, + ReportStatus: telemetery.HCAdapter(svc.HC()), } // query querySrv := startQuery( diff --git a/cmd/jaeger/internal/extension/jaegerquery/server.go b/cmd/jaeger/internal/extension/jaegerquery/server.go index 0bb80a26b6d..635a3088d06 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server.go @@ -81,9 +81,9 @@ func (s *server) Start(_ context.Context, host component.Host) error { return fmt.Errorf("could not initialize a tracer: %w", err) } telset := telemetery.Setting{ - Logger: s.logger, - Tracer: s.jtracer, - HC: healthcheck.New(), + Logger: s.logger, + Tracer: s.jtracer, + ReportStatus: telemetery.HCAdapter(healthcheck.New()), } // TODO contextcheck linter complains about next line that context is not passed. It is not wrong. //nolint diff --git a/cmd/query/app/server.go b/cmd/query/app/server.go index 20979549c8f..d0279e2b94f 100644 --- a/cmd/query/app/server.go +++ b/cmd/query/app/server.go @@ -51,7 +51,7 @@ import ( // Server runs HTTP, Mux and a grpc server type Server struct { logger *zap.Logger - healthCheck *healthcheck.HealthCheck + hcFunc func(*telemetery.StatusEvent) querySvc *querysvc.QueryService queryOptions *QueryOptions @@ -99,7 +99,7 @@ func NewServer(querySvc *querysvc.QueryService, return &Server{ logger: telset.Logger, - healthCheck: telset.HC, + hcFunc: telset.ReportStatus, querySvc: querySvc, queryOptions: options, tracer: telset.Tracer, @@ -314,7 +314,7 @@ func (s *Server) Start() error { s.logger.Error("Could not start HTTP server", zap.Error(err)) } s.logger.Info("HTTP server stopped", zap.Int("port", httpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) - s.healthCheck.Set(healthcheck.Unavailable) + s.hcFunc(&telemetery.StatusEvent{status: healthcheck.Unavailable}) s.bgFinished.Done() }() @@ -328,7 +328,7 @@ func (s *Server) Start() error { s.logger.Error("Could not start GRPC server", zap.Error(err)) } s.logger.Info("GRPC server stopped", zap.Int("port", grpcPort), zap.String("addr", s.queryOptions.GRPCHostPort)) - s.healthCheck.Set(healthcheck.Unavailable) + s.hcFunc(&telemetery.StatusEvent{status: healthcheck.Unavailable}) s.bgFinished.Done() }() @@ -344,7 +344,7 @@ func (s *Server) Start() error { s.logger.Error("Could not start multiplexed server", zap.Error(err)) } s.logger.Info("CMUX server stopped", zap.Int("port", tcpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) - s.healthCheck.Set(healthcheck.Unavailable) + s.hcFunc(&telemetery.StatusEvent{status: healthcheck.Unavailable}) s.bgFinished.Done() }() } diff --git a/cmd/query/app/token_propagation_test.go b/cmd/query/app/token_propagation_test.go index 98ee68b45cc..970dfbcbb13 100644 --- a/cmd/query/app/token_propagation_test.go +++ b/cmd/query/app/token_propagation_test.go @@ -93,9 +93,9 @@ func runQueryService(t *testing.T, esURL string) *Server { querySvc := querysvc.NewQueryService(spanReader, nil, querysvc.QueryServiceOptions{}) telset := telemetery.Setting{ - Logger: flagsSvc.Logger, - Tracer: jtracer.NoOp(), - HC: flagsSvc.HC(), + Logger: flagsSvc.Logger, + Tracer: jtracer.NoOp(), + ReportStatus: telemetery.HCAdapter(flagsSvc.HC()), } server, err := NewServer(querySvc, nil, &QueryOptions{ diff --git a/cmd/query/main.go b/cmd/query/main.go index 6e54731f4af..2511d0d6c6d 100644 --- a/cmd/query/main.go +++ b/cmd/query/main.go @@ -115,9 +115,9 @@ func main() { *queryServiceOptions) tm := tenancy.NewManager(&queryOpts.Tenancy) telset := telemetery.Setting{ - Logger: logger, - Tracer: jt, - HC: svc.HC(), + Logger: logger, + Tracer: jt, + ReportStatus: telemetery.HCAdapter(svc.HC()), } server, err := app.NewServer(queryService, metricsQueryService, queryOpts, tm, telset) if err != nil { diff --git a/pkg/telemetery/settings.go b/pkg/telemetery/settings.go index 8242964a1df..d5c28277232 100644 --- a/pkg/telemetery/settings.go +++ b/pkg/telemetery/settings.go @@ -1,15 +1,29 @@ +// Copyright (c) 2024 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + package telemetery import ( + "go.uber.org/zap" + "github.com/jaegertracing/jaeger/pkg/healthcheck" "github.com/jaegertracing/jaeger/pkg/jtracer" "github.com/jaegertracing/jaeger/pkg/metrics" - "go.uber.org/zap" ) type Setting struct { - Logger *zap.Logger - Tracer *jtracer.JTracer - Metrics metrics.Factory - HC *healthcheck.HealthCheck + Logger *zap.Logger + Tracer *jtracer.JTracer + Metrics metrics.Factory + ReportStatus func(*StatusEvent) +} + +type StatusEvent struct { + status healthcheck.Status +} + +func HCAdapter(hc *healthcheck.HealthCheck) func(*StatusEvent) { + return func(event *StatusEvent) { + hc.Set(event.status) + } } From e132adb2eebe984111c29e77e69327acb9af1250 Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Thu, 4 Jul 2024 09:56:53 +0530 Subject: [PATCH 09/29] Updated ReportStatus to use OTEL's StatusEvent Signed-off-by: Wise-Wizard --- cmd/query/app/server.go | 12 ++++++------ pkg/telemetery/settings.go | 26 ++++++++++++++++++-------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/cmd/query/app/server.go b/cmd/query/app/server.go index d0279e2b94f..d30a3a77ff4 100644 --- a/cmd/query/app/server.go +++ b/cmd/query/app/server.go @@ -26,6 +26,7 @@ import ( "github.com/gorilla/handlers" "github.com/soheilhy/cmux" + "go.opentelemetry.io/collector/component" "go.uber.org/zap" "go.uber.org/zap/zapcore" "google.golang.org/grpc" @@ -38,7 +39,6 @@ import ( "github.com/jaegertracing/jaeger/cmd/query/app/internal/api_v3" "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" "github.com/jaegertracing/jaeger/pkg/bearertoken" - "github.com/jaegertracing/jaeger/pkg/healthcheck" "github.com/jaegertracing/jaeger/pkg/jtracer" "github.com/jaegertracing/jaeger/pkg/netutils" "github.com/jaegertracing/jaeger/pkg/recoveryhandler" @@ -51,7 +51,7 @@ import ( // Server runs HTTP, Mux and a grpc server type Server struct { logger *zap.Logger - hcFunc func(*telemetery.StatusEvent) + hcFunc func(*component.StatusEvent) querySvc *querysvc.QueryService queryOptions *QueryOptions @@ -314,7 +314,7 @@ func (s *Server) Start() error { s.logger.Error("Could not start HTTP server", zap.Error(err)) } s.logger.Info("HTTP server stopped", zap.Int("port", httpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) - s.hcFunc(&telemetery.StatusEvent{status: healthcheck.Unavailable}) + s.hcFunc(component.NewStatusEvent(component.StatusStopping)) s.bgFinished.Done() }() @@ -328,7 +328,7 @@ func (s *Server) Start() error { s.logger.Error("Could not start GRPC server", zap.Error(err)) } s.logger.Info("GRPC server stopped", zap.Int("port", grpcPort), zap.String("addr", s.queryOptions.GRPCHostPort)) - s.hcFunc(&telemetery.StatusEvent{status: healthcheck.Unavailable}) + s.hcFunc(component.NewStatusEvent(component.StatusStopping)) s.bgFinished.Done() }() @@ -344,7 +344,7 @@ func (s *Server) Start() error { s.logger.Error("Could not start multiplexed server", zap.Error(err)) } s.logger.Info("CMUX server stopped", zap.Int("port", tcpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) - s.hcFunc(&telemetery.StatusEvent{status: healthcheck.Unavailable}) + s.hcFunc(component.NewStatusEvent(component.StatusStopping)) s.bgFinished.Done() }() } @@ -371,7 +371,7 @@ func (s *Server) Close() error { s.logger.Info("Closing CMux server") s.cmuxServer.Close() } - + s.hcFunc(component.NewStatusEvent(component.StatusStopped)) s.bgFinished.Wait() s.logger.Info("Server stopped") return errors.Join(errs...) diff --git a/pkg/telemetery/settings.go b/pkg/telemetery/settings.go index d5c28277232..770613b2099 100644 --- a/pkg/telemetery/settings.go +++ b/pkg/telemetery/settings.go @@ -9,21 +9,31 @@ import ( "github.com/jaegertracing/jaeger/pkg/healthcheck" "github.com/jaegertracing/jaeger/pkg/jtracer" "github.com/jaegertracing/jaeger/pkg/metrics" + "go.opentelemetry.io/collector/component" ) type Setting struct { Logger *zap.Logger Tracer *jtracer.JTracer Metrics metrics.Factory - ReportStatus func(*StatusEvent) + ReportStatus func(*component.StatusEvent) } -type StatusEvent struct { - status healthcheck.Status -} - -func HCAdapter(hc *healthcheck.HealthCheck) func(*StatusEvent) { - return func(event *StatusEvent) { - hc.Set(event.status) +func HCAdapter(hc *healthcheck.HealthCheck) func(*component.StatusEvent) { + return func(event *component.StatusEvent) { + var hcStatus healthcheck.Status + switch event.Status() { + case component.StatusOK: + hcStatus = healthcheck.Ready + case component.StatusStarting, + component.StatusRecoverableError, + component.StatusPermanentError, + component.StatusNone, + component.StatusStopping: + hcStatus = healthcheck.Unavailable + case component.StatusFatalError, component.StatusStopped: + hcStatus = healthcheck.Broken + } + hc.Set(hcStatus) } } From 69876c7b8ed89947d1ef5d174aa285c56370246b Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Thu, 4 Jul 2024 15:41:33 +0530 Subject: [PATCH 10/29] Prototype Impl of Tracer Signed-off-by: Wise-Wizard --- cmd/query/app/server.go | 9 +++-- cmd/query/app/token_propagation_test.go | 8 ++-- cmd/query/main.go | 27 +++++++------ pkg/telemetery/settings.go | 52 ++++++++++++++++++++----- 4 files changed, 67 insertions(+), 29 deletions(-) diff --git a/cmd/query/app/server.go b/cmd/query/app/server.go index d30a3a77ff4..fa97a36ad78 100644 --- a/cmd/query/app/server.go +++ b/cmd/query/app/server.go @@ -27,6 +27,7 @@ import ( "github.com/gorilla/handlers" "github.com/soheilhy/cmux" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/otel/trace" "go.uber.org/zap" "go.uber.org/zap/zapcore" "google.golang.org/grpc" @@ -55,7 +56,7 @@ type Server struct { querySvc *querysvc.QueryService queryOptions *QueryOptions - tracer *jtracer.JTracer // TODO make part of flags.Service + tracer trace.TracerProvider // TODO make part of flags.Service conn net.Listener grpcConn net.Listener @@ -87,12 +88,12 @@ func NewServer(querySvc *querysvc.QueryService, return nil, errors.New("server with TLS enabled can not use same host ports for gRPC and HTTP. Use dedicated HTTP and gRPC host ports instead") } - grpcServer, err := createGRPCServer(querySvc, metricsQuerySvc, options, tm, telset.Logger, telset.Tracer) + grpcServer, err := createGRPCServer(querySvc, metricsQuerySvc, options, tm, telset.Logger, telset.TracerProvider) if err != nil { return nil, err } - httpServer, err := createHTTPServer(querySvc, metricsQuerySvc, options, tm, telset.Tracer, telset.Logger) + httpServer, err := createHTTPServer(querySvc, metricsQuerySvc, options, tm, telset.TracerProvider, telset.Logger) if err != nil { return nil, err } @@ -102,7 +103,7 @@ func NewServer(querySvc *querysvc.QueryService, hcFunc: telset.ReportStatus, querySvc: querySvc, queryOptions: options, - tracer: telset.Tracer, + tracer: telset.TracerProvider, grpcServer: grpcServer, httpServer: httpServer, separatePorts: grpcPort != httpPort, diff --git a/cmd/query/app/token_propagation_test.go b/cmd/query/app/token_propagation_test.go index 970dfbcbb13..3d16f987694 100644 --- a/cmd/query/app/token_propagation_test.go +++ b/cmd/query/app/token_propagation_test.go @@ -30,12 +30,12 @@ import ( "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" "github.com/jaegertracing/jaeger/pkg/bearertoken" "github.com/jaegertracing/jaeger/pkg/config" - "github.com/jaegertracing/jaeger/pkg/jtracer" "github.com/jaegertracing/jaeger/pkg/metrics" "github.com/jaegertracing/jaeger/pkg/telemetery" "github.com/jaegertracing/jaeger/pkg/tenancy" "github.com/jaegertracing/jaeger/plugin/storage/es" "github.com/jaegertracing/jaeger/ports" + nooptrace "go.opentelemetry.io/otel/trace/noop" ) const ( @@ -93,9 +93,9 @@ func runQueryService(t *testing.T, esURL string) *Server { querySvc := querysvc.NewQueryService(spanReader, nil, querysvc.QueryServiceOptions{}) telset := telemetery.Setting{ - Logger: flagsSvc.Logger, - Tracer: jtracer.NoOp(), - ReportStatus: telemetery.HCAdapter(flagsSvc.HC()), + Logger: flagsSvc.Logger, + TracerProvider: nooptrace.NewTracerProvider(), + ReportStatus: telemetery.HCAdapter(flagsSvc.HC()), } server, err := NewServer(querySvc, nil, &QueryOptions{ diff --git a/cmd/query/main.go b/cmd/query/main.go index 2511d0d6c6d..c9f571eb253 100644 --- a/cmd/query/main.go +++ b/cmd/query/main.go @@ -21,11 +21,6 @@ import ( "log" "os" - "github.com/spf13/cobra" - "github.com/spf13/viper" - _ "go.uber.org/automaxprocs" - "go.uber.org/zap" - "github.com/jaegertracing/jaeger/cmd/internal/docs" "github.com/jaegertracing/jaeger/cmd/internal/env" "github.com/jaegertracing/jaeger/cmd/internal/flags" @@ -35,7 +30,6 @@ import ( "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" "github.com/jaegertracing/jaeger/pkg/bearertoken" "github.com/jaegertracing/jaeger/pkg/config" - "github.com/jaegertracing/jaeger/pkg/jtracer" "github.com/jaegertracing/jaeger/pkg/metrics" "github.com/jaegertracing/jaeger/pkg/telemetery" "github.com/jaegertracing/jaeger/pkg/tenancy" @@ -45,6 +39,13 @@ import ( "github.com/jaegertracing/jaeger/ports" metricsstoreMetrics "github.com/jaegertracing/jaeger/storage/metricsstore/metrics" spanstoreMetrics "github.com/jaegertracing/jaeger/storage/spanstore/metrics" + "github.com/spf13/cobra" + "github.com/spf13/viper" + "go.opentelemetry.io/otel/trace" + sdkTrace "go.opentelemetry.io/otel/sdk/trace" + nooptrace "go.opentelemetry.io/otel/trace/noop" + _ "go.uber.org/automaxprocs" + "go.uber.org/zap" ) func main() { @@ -80,12 +81,14 @@ func main() { logger.Fatal("Failed to configure query service", zap.Error(err)) } - jt := jtracer.NoOp() + var tracerProvider trace.TracerProvider = nooptrace.NewTracerProvider() + var sdkTracerProvider *sdkTrace.TracerProvider if queryOpts.EnableTracing { - jt, err = jtracer.New("jaeger-query") + sdkTracerProvider, err = telemetery.InitTracerProvider("jaeger-query") if err != nil { logger.Fatal("Failed to create tracer", zap.Error(err)) } + tracerProvider = sdkTracerProvider } // TODO: Need to figure out set enable/disable propagation on storage plugins. @@ -115,9 +118,9 @@ func main() { *queryServiceOptions) tm := tenancy.NewManager(&queryOpts.Tenancy) telset := telemetery.Setting{ - Logger: logger, - Tracer: jt, - ReportStatus: telemetery.HCAdapter(svc.HC()), + Logger: logger, + TracerProvider: tracerProvider, + ReportStatus: telemetery.HCAdapter(svc.HC()), } server, err := app.NewServer(queryService, metricsQueryService, queryOpts, tm, telset) if err != nil { @@ -133,7 +136,7 @@ func main() { if err := storageFactory.Close(); err != nil { logger.Error("Failed to close storage factory", zap.Error(err)) } - if err = jt.Close(context.Background()); err != nil { + if err = sdkTracerProvider.Shutdown(context.Background()); err != nil { logger.Fatal("Error shutting down tracer provider", zap.Error(err)) } }) diff --git a/pkg/telemetery/settings.go b/pkg/telemetery/settings.go index 770613b2099..ca881b5ca2d 100644 --- a/pkg/telemetery/settings.go +++ b/pkg/telemetery/settings.go @@ -1,22 +1,56 @@ -// Copyright (c) 2024 The Jaeger Authors. -// SPDX-License-Identifier: Apache-2.0 - package telemetery import ( + "context" + + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" + "go.opentelemetry.io/otel/sdk/resource" + sdkTrace "go.opentelemetry.io/otel/sdk/trace" + "go.opentelemetry.io/otel/trace" "go.uber.org/zap" "github.com/jaegertracing/jaeger/pkg/healthcheck" - "github.com/jaegertracing/jaeger/pkg/jtracer" "github.com/jaegertracing/jaeger/pkg/metrics" - "go.opentelemetry.io/collector/component" + "github.com/jaegertracing/jaeger/pkg/otelsemconv" ) type Setting struct { - Logger *zap.Logger - Tracer *jtracer.JTracer - Metrics metrics.Factory - ReportStatus func(*component.StatusEvent) + Logger *zap.Logger + TracerProvider trace.TracerProvider + Metrics metrics.Factory + ReportStatus func(*component.StatusEvent) +} + +func InitTracerProvider(serviceName string) (*sdkTrace.TracerProvider, error) { + ctx := context.Background() + traceExporter, err := otlptracegrpc.New( + ctx, + otlptracegrpc.WithInsecure(), + ) + if err != nil { + return nil, err + } + bsp := sdkTrace.NewBatchSpanProcessor(traceExporter) + res, err := resource.New( + ctx, + resource.WithSchemaURL(otelsemconv.SchemaURL), + resource.WithAttributes(otelsemconv.ServiceNameKey.String(serviceName)), + resource.WithTelemetrySDK(), + resource.WithHost(), + resource.WithOSType(), + resource.WithFromEnv(), + ) + if err != nil { + return nil, err + } + traceProvider := sdkTrace.NewTracerProvider( + sdkTrace.WithSpanProcessor(bsp), + sdkTrace.WithResource(res), + ) + otel.SetTracerProvider(traceProvider) + return traceProvider, nil } func HCAdapter(hc *healthcheck.HealthCheck) func(*component.StatusEvent) { From 3ec9594a0c446c715402cb0fd414c64477b57e19 Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Thu, 4 Jul 2024 22:31:23 +0530 Subject: [PATCH 11/29] Added suggested Changes Signed-off-by: Wise-Wizard --- cmd/all-in-one/main.go | 8 +-- .../internal/extension/jaegerquery/server.go | 10 ++-- cmd/query/app/server.go | 52 ++++++++----------- cmd/query/app/token_propagation_test.go | 4 +- cmd/query/main.go | 23 ++++---- pkg/telemetery/settings.go | 40 ++------------ 6 files changed, 48 insertions(+), 89 deletions(-) diff --git a/cmd/all-in-one/main.go b/cmd/all-in-one/main.go index 104d76f9fb8..a051573e5a6 100644 --- a/cmd/all-in-one/main.go +++ b/cmd/all-in-one/main.go @@ -195,10 +195,10 @@ by default uses only in-memory database.`, } agent := startAgent(cp, aOpts, logger, agentMetricsFactory) telset := telemetery.Setting{ - Logger: svc.Logger, - Tracer: tracer, - Metrics: queryMetricsFactory, - ReportStatus: telemetery.HCAdapter(svc.HC()), + Logger: svc.Logger, + TracerProvider: tracer.OTEL, + Metrics: queryMetricsFactory, + ReportStatus: telemetery.HCAdapter(svc.HC()), } // query querySrv := startQuery( diff --git a/cmd/jaeger/internal/extension/jaegerquery/server.go b/cmd/jaeger/internal/extension/jaegerquery/server.go index 635a3088d06..cbc813d0870 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server.go @@ -15,7 +15,6 @@ import ( "github.com/jaegertracing/jaeger/cmd/jaeger/internal/extension/jaegerstorage" queryApp "github.com/jaegertracing/jaeger/cmd/query/app" "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" - "github.com/jaegertracing/jaeger/pkg/healthcheck" "github.com/jaegertracing/jaeger/pkg/jtracer" "github.com/jaegertracing/jaeger/pkg/telemetery" "github.com/jaegertracing/jaeger/pkg/tenancy" @@ -80,10 +79,13 @@ func (s *server) Start(_ context.Context, host component.Host) error { if err != nil { return fmt.Errorf("could not initialize a tracer: %w", err) } + statusReporter := func(ev *component.StatusEvent) { + s.logger.Info("OTLP receiver status change", zap.Stringer("status", ev.Status())) + } telset := telemetery.Setting{ - Logger: s.logger, - Tracer: s.jtracer, - ReportStatus: telemetery.HCAdapter(healthcheck.New()), + Logger: s.logger, + TracerProvider: s.jtracer.OTEL, + ReportStatus: statusReporter, } // TODO contextcheck linter complains about next line that context is not passed. It is not wrong. //nolint diff --git a/cmd/query/app/server.go b/cmd/query/app/server.go index fa97a36ad78..dbd56487752 100644 --- a/cmd/query/app/server.go +++ b/cmd/query/app/server.go @@ -40,7 +40,6 @@ import ( "github.com/jaegertracing/jaeger/cmd/query/app/internal/api_v3" "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" "github.com/jaegertracing/jaeger/pkg/bearertoken" - "github.com/jaegertracing/jaeger/pkg/jtracer" "github.com/jaegertracing/jaeger/pkg/netutils" "github.com/jaegertracing/jaeger/pkg/recoveryhandler" "github.com/jaegertracing/jaeger/pkg/telemetery" @@ -51,13 +50,9 @@ import ( // Server runs HTTP, Mux and a grpc server type Server struct { - logger *zap.Logger - hcFunc func(*component.StatusEvent) querySvc *querysvc.QueryService queryOptions *QueryOptions - tracer trace.TracerProvider // TODO make part of flags.Service - conn net.Listener grpcConn net.Listener httpConn net.Listener @@ -66,6 +61,7 @@ type Server struct { httpServer *httpServer separatePorts bool bgFinished sync.WaitGroup + telset telemetery.Setting } // NewServer creates and initializes Server @@ -99,18 +95,16 @@ func NewServer(querySvc *querysvc.QueryService, } return &Server{ - logger: telset.Logger, - hcFunc: telset.ReportStatus, querySvc: querySvc, queryOptions: options, - tracer: telset.TracerProvider, grpcServer: grpcServer, httpServer: httpServer, separatePorts: grpcPort != httpPort, + telset: telset, }, nil } -func createGRPCServer(querySvc *querysvc.QueryService, metricsQuerySvc querysvc.MetricsQueryService, options *QueryOptions, tm *tenancy.Manager, logger *zap.Logger, tracer *jtracer.JTracer) (*grpc.Server, error) { +func createGRPCServer(querySvc *querysvc.QueryService, metricsQuerySvc querysvc.MetricsQueryService, options *QueryOptions, tm *tenancy.Manager, logger *zap.Logger, tracer trace.TracerProvider) (*grpc.Server, error) { var grpcOpts []grpc.ServerOption if options.TLSGRPC.Enabled { @@ -163,7 +157,7 @@ func createHTTPServer( metricsQuerySvc querysvc.MetricsQueryService, queryOpts *QueryOptions, tm *tenancy.Manager, - tracer *jtracer.JTracer, + tracer trace.TracerProvider, logger *zap.Logger, ) (*httpServer, error) { apiHandlerOptions := []HandlerOption{ @@ -239,7 +233,7 @@ func (s *Server) initListener() (cmux.CMux, error) { if err != nil { return nil, err } - s.logger.Info( + s.telset.Logger.Info( "Query server started", zap.String("http_addr", s.httpConn.Addr().String()), zap.String("grpc_addr", s.grpcConn.Addr().String()), @@ -260,7 +254,7 @@ func (s *Server) initListener() (cmux.CMux, error) { tcpPort = port } - s.logger.Info( + s.telset.Logger.Info( "Query server started", zap.Int("port", tcpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) @@ -304,7 +298,7 @@ func (s *Server) Start() error { s.bgFinished.Add(1) go func() { - s.logger.Info("Starting HTTP server", zap.Int("port", httpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) + s.telset.Logger.Info("Starting HTTP server", zap.Int("port", httpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) var err error if s.queryOptions.TLSHTTP.Enabled { err = s.httpServer.ServeTLS(s.httpConn, "", "") @@ -312,24 +306,24 @@ func (s *Server) Start() error { err = s.httpServer.Serve(s.httpConn) } if err != nil && !errors.Is(err, http.ErrServerClosed) && !errors.Is(err, cmux.ErrListenerClosed) && !errors.Is(err, cmux.ErrServerClosed) { - s.logger.Error("Could not start HTTP server", zap.Error(err)) + s.telset.Logger.Error("Could not start HTTP server", zap.Error(err)) } - s.logger.Info("HTTP server stopped", zap.Int("port", httpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) - s.hcFunc(component.NewStatusEvent(component.StatusStopping)) + s.telset.Logger.Info("HTTP server stopped", zap.Int("port", httpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) + s.telset.ReportStatus(component.NewStatusEvent(component.StatusStopping)) s.bgFinished.Done() }() // Start GRPC server concurrently s.bgFinished.Add(1) go func() { - s.logger.Info("Starting GRPC server", zap.Int("port", grpcPort), zap.String("addr", s.queryOptions.GRPCHostPort)) + s.telset.Logger.Info("Starting GRPC server", zap.Int("port", grpcPort), zap.String("addr", s.queryOptions.GRPCHostPort)) err := s.grpcServer.Serve(s.grpcConn) if err != nil && !errors.Is(err, cmux.ErrListenerClosed) && !errors.Is(err, cmux.ErrServerClosed) { - s.logger.Error("Could not start GRPC server", zap.Error(err)) + s.telset.Logger.Error("Could not start GRPC server", zap.Error(err)) } - s.logger.Info("GRPC server stopped", zap.Int("port", grpcPort), zap.String("addr", s.queryOptions.GRPCHostPort)) - s.hcFunc(component.NewStatusEvent(component.StatusStopping)) + s.telset.Logger.Info("GRPC server stopped", zap.Int("port", grpcPort), zap.String("addr", s.queryOptions.GRPCHostPort)) + s.telset.ReportStatus(component.NewStatusEvent(component.StatusStopping)) s.bgFinished.Done() }() @@ -337,15 +331,15 @@ func (s *Server) Start() error { if !s.separatePorts { s.bgFinished.Add(1) go func() { - s.logger.Info("Starting CMUX server", zap.Int("port", tcpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) + s.telset.Logger.Info("Starting CMUX server", zap.Int("port", tcpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) err := cmuxServer.Serve() // TODO: find a way to avoid string comparison. Even though cmux has ErrServerClosed, it's not returned here. if err != nil && !strings.Contains(err.Error(), "use of closed network connection") { - s.logger.Error("Could not start multiplexed server", zap.Error(err)) + s.telset.Logger.Error("Could not start multiplexed server", zap.Error(err)) } - s.logger.Info("CMUX server stopped", zap.Int("port", tcpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) - s.hcFunc(component.NewStatusEvent(component.StatusStopping)) + s.telset.Logger.Info("CMUX server stopped", zap.Int("port", tcpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) + s.telset.ReportStatus(component.NewStatusEvent(component.StatusStopping)) s.bgFinished.Done() }() } @@ -360,20 +354,20 @@ func (s *Server) Close() error { s.queryOptions.TLSHTTP.Close(), } - s.logger.Info("Closing HTTP server") + s.telset.Logger.Info("Closing HTTP server") if err := s.httpServer.Close(); err != nil { errs = append(errs, fmt.Errorf("failed to close HTTP server: %w", err)) } - s.logger.Info("Stopping gRPC server") + s.telset.Logger.Info("Stopping gRPC server") s.grpcServer.Stop() if !s.separatePorts { - s.logger.Info("Closing CMux server") + s.telset.Logger.Info("Closing CMux server") s.cmuxServer.Close() } - s.hcFunc(component.NewStatusEvent(component.StatusStopped)) s.bgFinished.Wait() - s.logger.Info("Server stopped") + s.telset.ReportStatus(component.NewStatusEvent(component.StatusStopped)) + s.telset.Logger.Info("Server stopped") return errors.Join(errs...) } diff --git a/cmd/query/app/token_propagation_test.go b/cmd/query/app/token_propagation_test.go index 3d16f987694..a474c1188cc 100644 --- a/cmd/query/app/token_propagation_test.go +++ b/cmd/query/app/token_propagation_test.go @@ -30,12 +30,12 @@ import ( "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" "github.com/jaegertracing/jaeger/pkg/bearertoken" "github.com/jaegertracing/jaeger/pkg/config" + "github.com/jaegertracing/jaeger/pkg/jtracer" "github.com/jaegertracing/jaeger/pkg/metrics" "github.com/jaegertracing/jaeger/pkg/telemetery" "github.com/jaegertracing/jaeger/pkg/tenancy" "github.com/jaegertracing/jaeger/plugin/storage/es" "github.com/jaegertracing/jaeger/ports" - nooptrace "go.opentelemetry.io/otel/trace/noop" ) const ( @@ -94,7 +94,7 @@ func runQueryService(t *testing.T, esURL string) *Server { querySvc := querysvc.NewQueryService(spanReader, nil, querysvc.QueryServiceOptions{}) telset := telemetery.Setting{ Logger: flagsSvc.Logger, - TracerProvider: nooptrace.NewTracerProvider(), + TracerProvider: jtracer.NoOp().OTEL, ReportStatus: telemetery.HCAdapter(flagsSvc.HC()), } server, err := NewServer(querySvc, nil, diff --git a/cmd/query/main.go b/cmd/query/main.go index c9f571eb253..36c54c63197 100644 --- a/cmd/query/main.go +++ b/cmd/query/main.go @@ -21,6 +21,11 @@ import ( "log" "os" + "github.com/spf13/cobra" + "github.com/spf13/viper" + _ "go.uber.org/automaxprocs" + "go.uber.org/zap" + "github.com/jaegertracing/jaeger/cmd/internal/docs" "github.com/jaegertracing/jaeger/cmd/internal/env" "github.com/jaegertracing/jaeger/cmd/internal/flags" @@ -30,6 +35,7 @@ import ( "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" "github.com/jaegertracing/jaeger/pkg/bearertoken" "github.com/jaegertracing/jaeger/pkg/config" + "github.com/jaegertracing/jaeger/pkg/jtracer" "github.com/jaegertracing/jaeger/pkg/metrics" "github.com/jaegertracing/jaeger/pkg/telemetery" "github.com/jaegertracing/jaeger/pkg/tenancy" @@ -39,13 +45,6 @@ import ( "github.com/jaegertracing/jaeger/ports" metricsstoreMetrics "github.com/jaegertracing/jaeger/storage/metricsstore/metrics" spanstoreMetrics "github.com/jaegertracing/jaeger/storage/spanstore/metrics" - "github.com/spf13/cobra" - "github.com/spf13/viper" - "go.opentelemetry.io/otel/trace" - sdkTrace "go.opentelemetry.io/otel/sdk/trace" - nooptrace "go.opentelemetry.io/otel/trace/noop" - _ "go.uber.org/automaxprocs" - "go.uber.org/zap" ) func main() { @@ -81,14 +80,12 @@ func main() { logger.Fatal("Failed to configure query service", zap.Error(err)) } - var tracerProvider trace.TracerProvider = nooptrace.NewTracerProvider() - var sdkTracerProvider *sdkTrace.TracerProvider + jt := jtracer.NoOp() if queryOpts.EnableTracing { - sdkTracerProvider, err = telemetery.InitTracerProvider("jaeger-query") + jt, err = jtracer.New("jaeger-query") if err != nil { logger.Fatal("Failed to create tracer", zap.Error(err)) } - tracerProvider = sdkTracerProvider } // TODO: Need to figure out set enable/disable propagation on storage plugins. @@ -119,7 +116,7 @@ func main() { tm := tenancy.NewManager(&queryOpts.Tenancy) telset := telemetery.Setting{ Logger: logger, - TracerProvider: tracerProvider, + TracerProvider: jt.OTEL, ReportStatus: telemetery.HCAdapter(svc.HC()), } server, err := app.NewServer(queryService, metricsQueryService, queryOpts, tm, telset) @@ -136,7 +133,7 @@ func main() { if err := storageFactory.Close(); err != nil { logger.Error("Failed to close storage factory", zap.Error(err)) } - if err = sdkTracerProvider.Shutdown(context.Background()); err != nil { + if err = jt.Close(context.Background()); err != nil { logger.Fatal("Error shutting down tracer provider", zap.Error(err)) } }) diff --git a/pkg/telemetery/settings.go b/pkg/telemetery/settings.go index ca881b5ca2d..2167a933044 100644 --- a/pkg/telemetery/settings.go +++ b/pkg/telemetery/settings.go @@ -1,19 +1,15 @@ +// Copyright (c) 2024 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + package telemetery import ( - "context" - "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" - "go.opentelemetry.io/otel/sdk/resource" - sdkTrace "go.opentelemetry.io/otel/sdk/trace" "go.opentelemetry.io/otel/trace" "go.uber.org/zap" "github.com/jaegertracing/jaeger/pkg/healthcheck" "github.com/jaegertracing/jaeger/pkg/metrics" - "github.com/jaegertracing/jaeger/pkg/otelsemconv" ) type Setting struct { @@ -23,36 +19,6 @@ type Setting struct { ReportStatus func(*component.StatusEvent) } -func InitTracerProvider(serviceName string) (*sdkTrace.TracerProvider, error) { - ctx := context.Background() - traceExporter, err := otlptracegrpc.New( - ctx, - otlptracegrpc.WithInsecure(), - ) - if err != nil { - return nil, err - } - bsp := sdkTrace.NewBatchSpanProcessor(traceExporter) - res, err := resource.New( - ctx, - resource.WithSchemaURL(otelsemconv.SchemaURL), - resource.WithAttributes(otelsemconv.ServiceNameKey.String(serviceName)), - resource.WithTelemetrySDK(), - resource.WithHost(), - resource.WithOSType(), - resource.WithFromEnv(), - ) - if err != nil { - return nil, err - } - traceProvider := sdkTrace.NewTracerProvider( - sdkTrace.WithSpanProcessor(bsp), - sdkTrace.WithResource(res), - ) - otel.SetTracerProvider(traceProvider) - return traceProvider, nil -} - func HCAdapter(hc *healthcheck.HealthCheck) func(*component.StatusEvent) { return func(event *component.StatusEvent) { var hcStatus healthcheck.Status From 0002dc628fb9af2919044dafc477ad976bc5ce7c Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Thu, 4 Jul 2024 23:30:26 +0530 Subject: [PATCH 12/29] Changed V2 to accept OTEL's Telset Signed-off-by: Wise-Wizard --- .../internal/extension/jaegerquery/server.go | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/cmd/jaeger/internal/extension/jaegerquery/server.go b/cmd/jaeger/internal/extension/jaegerquery/server.go index cbc813d0870..f1881a706b1 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server.go @@ -10,12 +10,12 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/extension" + "go.opentelemetry.io/otel/trace" "go.uber.org/zap" "github.com/jaegertracing/jaeger/cmd/jaeger/internal/extension/jaegerstorage" queryApp "github.com/jaegertracing/jaeger/cmd/query/app" "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" - "github.com/jaegertracing/jaeger/pkg/jtracer" "github.com/jaegertracing/jaeger/pkg/telemetery" "github.com/jaegertracing/jaeger/pkg/tenancy" "github.com/jaegertracing/jaeger/plugin/metrics/disabled" @@ -28,16 +28,19 @@ var ( ) type server struct { - config *Config - logger *zap.Logger - server *queryApp.Server - jtracer *jtracer.JTracer + config *Config + logger *zap.Logger + server *queryApp.Server + tracer trace.TracerProvider + hcFunc func(*component.StatusEvent) } func newServer(config *Config, otel component.TelemetrySettings) *server { return &server{ config: config, logger: otel.Logger, + tracer: otel.TracerProvider, + hcFunc: otel.ReportStatus, } } @@ -75,17 +78,15 @@ func (s *server) Start(_ context.Context, host component.Host) error { // TODO OTel-collector does not initialize the tracer currently // https://github.com/open-telemetry/opentelemetry-collector/issues/7532 //nolint - s.jtracer, err = jtracer.New("jaeger") + if err != nil { return fmt.Errorf("could not initialize a tracer: %w", err) } - statusReporter := func(ev *component.StatusEvent) { - s.logger.Info("OTLP receiver status change", zap.Stringer("status", ev.Status())) - } + telset := telemetery.Setting{ Logger: s.logger, - TracerProvider: s.jtracer.OTEL, - ReportStatus: statusReporter, + TracerProvider: s.tracer, + ReportStatus: s.hcFunc, } // TODO contextcheck linter complains about next line that context is not passed. It is not wrong. //nolint @@ -140,8 +141,8 @@ func (s *server) Shutdown(ctx context.Context) error { if s.server != nil { errs = append(errs, s.server.Close()) } - if s.jtracer != nil { - errs = append(errs, s.jtracer.Close(ctx)) - } + // if s.tracer != nil { + // errs = append(errs, s.tracer.Shutdown(ctx)) + // } return errors.Join(errs...) } From 32d921c48c501b278b32e7620ab5a518a65caed1 Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Fri, 5 Jul 2024 09:16:52 +0530 Subject: [PATCH 13/29] Refactored to accept trace.TracerProvider Signed-off-by: Wise-Wizard --- .../internal/extension/jaegerquery/server.go | 40 +++++-------------- cmd/query/app/apiv3/http_gateway.go | 6 +-- cmd/query/app/apiv3/http_gateway_test.go | 2 +- cmd/query/app/handler_options.go | 4 +- cmd/query/app/http_handler.go | 7 ++-- cmd/query/app/http_handler_test.go | 2 +- cmd/query/app/server.go | 33 +++++++-------- 7 files changed, 37 insertions(+), 57 deletions(-) diff --git a/cmd/jaeger/internal/extension/jaegerquery/server.go b/cmd/jaeger/internal/extension/jaegerquery/server.go index f1881a706b1..7ffc211b419 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server.go @@ -5,13 +5,10 @@ package jaegerquery import ( "context" - "errors" "fmt" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/extension" - "go.opentelemetry.io/otel/trace" - "go.uber.org/zap" "github.com/jaegertracing/jaeger/cmd/jaeger/internal/extension/jaegerstorage" queryApp "github.com/jaegertracing/jaeger/cmd/query/app" @@ -29,18 +26,14 @@ var ( type server struct { config *Config - logger *zap.Logger server *queryApp.Server - tracer trace.TracerProvider - hcFunc func(*component.StatusEvent) + telset component.TelemetrySettings } func newServer(config *Config, otel component.TelemetrySettings) *server { return &server{ config: config, - logger: otel.Logger, - tracer: otel.TracerProvider, - hcFunc: otel.ReportStatus, + telset: otel, } } @@ -79,14 +72,10 @@ func (s *server) Start(_ context.Context, host component.Host) error { // https://github.com/open-telemetry/opentelemetry-collector/issues/7532 //nolint - if err != nil { - return fmt.Errorf("could not initialize a tracer: %w", err) - } - - telset := telemetery.Setting{ - Logger: s.logger, - TracerProvider: s.tracer, - ReportStatus: s.hcFunc, + internalTelset := telemetery.Setting{ + Logger: s.telset.Logger, + TracerProvider: s.telset.TracerProvider, + ReportStatus: s.telset.ReportStatus, } // TODO contextcheck linter complains about next line that context is not passed. It is not wrong. //nolint @@ -96,7 +85,7 @@ func (s *server) Start(_ context.Context, host component.Host) error { metricsQueryService, s.makeQueryOptions(), tm, - telset, + internalTelset, ) if err != nil { return fmt.Errorf("could not create jaeger-query: %w", err) @@ -111,7 +100,7 @@ func (s *server) Start(_ context.Context, host component.Host) error { func (s *server) addArchiveStorage(opts *querysvc.QueryServiceOptions, host component.Host) error { if s.config.TraceStorageArchive == "" { - s.logger.Info("Archive storage not configured") + s.telset.Logger.Info("Archive storage not configured") return nil } @@ -120,8 +109,8 @@ func (s *server) addArchiveStorage(opts *querysvc.QueryServiceOptions, host comp return fmt.Errorf("cannot find archive storage factory: %w", err) } - if !opts.InitArchiveStorage(f, s.logger) { - s.logger.Info("Archive storage not initialized") + if !opts.InitArchiveStorage(f, s.telset.Logger) { + s.telset.Logger.Info("Archive storage not initialized") } return nil } @@ -137,12 +126,5 @@ func (s *server) makeQueryOptions() *queryApp.QueryOptions { } func (s *server) Shutdown(ctx context.Context) error { - var errs []error - if s.server != nil { - errs = append(errs, s.server.Close()) - } - // if s.tracer != nil { - // errs = append(errs, s.tracer.Shutdown(ctx)) - // } - return errors.Join(errs...) + return s.server.Close() } diff --git a/cmd/query/app/apiv3/http_gateway.go b/cmd/query/app/apiv3/http_gateway.go index 8aca4a511a2..3b0884c7f12 100644 --- a/cmd/query/app/apiv3/http_gateway.go +++ b/cmd/query/app/apiv3/http_gateway.go @@ -17,12 +17,12 @@ import ( "github.com/gorilla/mux" "go.opentelemetry.io/collector/pdata/ptrace" "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" + "go.opentelemetry.io/otel/trace" "go.uber.org/zap" "github.com/jaegertracing/jaeger/cmd/query/app/internal/api_v3" "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" "github.com/jaegertracing/jaeger/model" - "github.com/jaegertracing/jaeger/pkg/jtracer" "github.com/jaegertracing/jaeger/pkg/tenancy" "github.com/jaegertracing/jaeger/storage/spanstore" ) @@ -48,7 +48,7 @@ type HTTPGateway struct { QueryService *querysvc.QueryService TenancyMgr *tenancy.Manager Logger *zap.Logger - Tracer *jtracer.JTracer + Tracer trace.TracerProvider } // RegisterRoutes registers HTTP endpoints for APIv3 into provided mux. @@ -75,7 +75,7 @@ func (h *HTTPGateway) addRoute( traceMiddleware := otelhttp.NewHandler( otelhttp.WithRouteTag(route, handler), route, - otelhttp.WithTracerProvider(h.Tracer.OTEL)) + otelhttp.WithTracerProvider(h.Tracer)) return router.HandleFunc(route, traceMiddleware.ServeHTTP) } diff --git a/cmd/query/app/apiv3/http_gateway_test.go b/cmd/query/app/apiv3/http_gateway_test.go index 6cd62ba492b..d747bb799ff 100644 --- a/cmd/query/app/apiv3/http_gateway_test.go +++ b/cmd/query/app/apiv3/http_gateway_test.go @@ -46,7 +46,7 @@ func setupHTTPGatewayNoServer( QueryService: q, TenancyMgr: tenancy.NewManager(&tenancyOptions), Logger: zap.NewNop(), - Tracer: jtracer.NoOp(), + Tracer: jtracer.NoOp().OTEL, } gw.router = &mux.Router{} diff --git a/cmd/query/app/handler_options.go b/cmd/query/app/handler_options.go index 853a41a2222..354f6a5fc91 100644 --- a/cmd/query/app/handler_options.go +++ b/cmd/query/app/handler_options.go @@ -18,10 +18,10 @@ package app import ( "time" + "go.opentelemetry.io/otel/trace" "go.uber.org/zap" "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" - "github.com/jaegertracing/jaeger/pkg/jtracer" ) // HandlerOption is a function that sets some option on the APIHandler @@ -62,7 +62,7 @@ func (handlerOptions) QueryLookbackDuration(queryLookbackDuration time.Duration) } // Tracer creates a HandlerOption that passes the tracer to the handler -func (handlerOptions) Tracer(tracer *jtracer.JTracer) HandlerOption { +func (handlerOptions) Tracer(tracer trace.TracerProvider) HandlerOption { return func(apiHandler *APIHandler) { apiHandler.tracer = tracer } diff --git a/cmd/query/app/http_handler.go b/cmd/query/app/http_handler.go index 5f217118610..58ecb875e33 100644 --- a/cmd/query/app/http_handler.go +++ b/cmd/query/app/http_handler.go @@ -30,6 +30,7 @@ import ( "github.com/gorilla/mux" "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/trace" "go.uber.org/zap" "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" @@ -90,7 +91,7 @@ type APIHandler struct { basePath string apiPrefix string logger *zap.Logger - tracer *jtracer.JTracer + tracer trace.TracerProvider } // NewAPIHandler returns an APIHandler @@ -114,7 +115,7 @@ func NewAPIHandler(queryService *querysvc.QueryService, tm *tenancy.Manager, opt aH.logger = zap.NewNop() } if aH.tracer == nil { - aH.tracer = jtracer.NoOp() + aH.tracer = jtracer.NoOp().OTEL } return aH } @@ -151,7 +152,7 @@ func (aH *APIHandler) handleFunc( traceMiddleware := otelhttp.NewHandler( otelhttp.WithRouteTag(route, traceResponseHandler(handler)), route, - otelhttp.WithTracerProvider(aH.tracer.OTEL)) + otelhttp.WithTracerProvider(aH.tracer)) return router.HandleFunc(route, traceMiddleware.ServeHTTP) } diff --git a/cmd/query/app/http_handler_test.go b/cmd/query/app/http_handler_test.go index ec84b37e55a..3034f6595d0 100644 --- a/cmd/query/app/http_handler_test.go +++ b/cmd/query/app/http_handler_test.go @@ -321,7 +321,7 @@ func TestGetTrace(t *testing.T) { jTracer := jtracer.JTracer{OTEL: tracerProvider} defer tracerProvider.Shutdown(context.Background()) - ts := initializeTestServer(HandlerOptions.Tracer(&jTracer)) + ts := initializeTestServer(HandlerOptions.Tracer(jTracer.OTEL)) defer ts.server.Close() ts.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), model.NewTraceID(0, 0x123456abc)). diff --git a/cmd/query/app/server.go b/cmd/query/app/server.go index dbd56487752..927b0af1ff6 100644 --- a/cmd/query/app/server.go +++ b/cmd/query/app/server.go @@ -27,7 +27,6 @@ import ( "github.com/gorilla/handlers" "github.com/soheilhy/cmux" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/otel/trace" "go.uber.org/zap" "go.uber.org/zap/zapcore" "google.golang.org/grpc" @@ -84,12 +83,12 @@ func NewServer(querySvc *querysvc.QueryService, return nil, errors.New("server with TLS enabled can not use same host ports for gRPC and HTTP. Use dedicated HTTP and gRPC host ports instead") } - grpcServer, err := createGRPCServer(querySvc, metricsQuerySvc, options, tm, telset.Logger, telset.TracerProvider) + grpcServer, err := createGRPCServer(querySvc, metricsQuerySvc, options, tm, telset) if err != nil { return nil, err } - httpServer, err := createHTTPServer(querySvc, metricsQuerySvc, options, tm, telset.TracerProvider, telset.Logger) + httpServer, err := createHTTPServer(querySvc, metricsQuerySvc, options, tm, telset) if err != nil { return nil, err } @@ -104,11 +103,11 @@ func NewServer(querySvc *querysvc.QueryService, }, nil } -func createGRPCServer(querySvc *querysvc.QueryService, metricsQuerySvc querysvc.MetricsQueryService, options *QueryOptions, tm *tenancy.Manager, logger *zap.Logger, tracer trace.TracerProvider) (*grpc.Server, error) { +func createGRPCServer(querySvc *querysvc.QueryService, metricsQuerySvc querysvc.MetricsQueryService, options *QueryOptions, tm *tenancy.Manager, telset telemetery.Setting) (*grpc.Server, error) { var grpcOpts []grpc.ServerOption if options.TLSGRPC.Enabled { - tlsCfg, err := options.TLSGRPC.Config(logger) + tlsCfg, err := options.TLSGRPC.Config(telset.Logger) if err != nil { return nil, err } @@ -128,8 +127,7 @@ func createGRPCServer(querySvc *querysvc.QueryService, metricsQuerySvc querysvc. reflection.Register(server) handler := NewGRPCHandler(querySvc, metricsQuerySvc, GRPCHandlerOptions{ - Logger: logger, - Tracer: tracer, + Logger: telset.Logger, }) healthServer := health.NewServer() @@ -157,12 +155,11 @@ func createHTTPServer( metricsQuerySvc querysvc.MetricsQueryService, queryOpts *QueryOptions, tm *tenancy.Manager, - tracer trace.TracerProvider, - logger *zap.Logger, + telset telemetery.Setting, ) (*httpServer, error) { apiHandlerOptions := []HandlerOption{ - HandlerOptions.Logger(logger), - HandlerOptions.Tracer(tracer), + HandlerOptions.Logger(telset.Logger), + HandlerOptions.Tracer(telset.TracerProvider), HandlerOptions.MetricsQueryService(metricsQuerySvc), } @@ -178,20 +175,20 @@ func createHTTPServer( (&apiv3.HTTPGateway{ QueryService: querySvc, TenancyMgr: tm, - Logger: logger, - Tracer: tracer, + Logger: telset.Logger, + Tracer: telset.TracerProvider, }).RegisterRoutes(r) apiHandler.RegisterRoutes(r) var handler http.Handler = r handler = additionalHeadersHandler(handler, queryOpts.AdditionalHeaders) if queryOpts.BearerTokenPropagation { - handler = bearertoken.PropagationHandler(logger, handler) + handler = bearertoken.PropagationHandler(telset.Logger, handler) } handler = handlers.CompressHandler(handler) - recoveryHandler := recoveryhandler.NewRecoveryHandler(logger, true) + recoveryHandler := recoveryhandler.NewRecoveryHandler(telset.Logger, true) - errorLog, _ := zap.NewStdLogAt(logger, zapcore.ErrorLevel) + errorLog, _ := zap.NewStdLogAt(telset.Logger, zapcore.ErrorLevel) server := &httpServer{ Server: &http.Server{ Handler: recoveryHandler(handler), @@ -201,14 +198,14 @@ func createHTTPServer( } if queryOpts.TLSHTTP.Enabled { - tlsCfg, err := queryOpts.TLSHTTP.Config(logger) // This checks if the certificates are correctly provided + tlsCfg, err := queryOpts.TLSHTTP.Config(telset.Logger) // This checks if the certificates are correctly provided if err != nil { return nil, err } server.TLSConfig = tlsCfg } - server.staticHandlerCloser = RegisterStaticHandler(r, logger, queryOpts, querySvc.GetCapabilities()) + server.staticHandlerCloser = RegisterStaticHandler(r, telset.Logger, queryOpts, querySvc.GetCapabilities()) return server, nil } From e5fa271243a325e0fba224c8355f2613faf8d808 Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Fri, 5 Jul 2024 20:23:10 +0530 Subject: [PATCH 14/29] Temporary fix to failing CI Signed-off-by: Wise-Wizard --- cmd/jaeger/internal/extension/jaegerquery/server.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/jaeger/internal/extension/jaegerquery/server.go b/cmd/jaeger/internal/extension/jaegerquery/server.go index 7ffc211b419..d75abaa609f 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server.go @@ -13,6 +13,7 @@ import ( "github.com/jaegertracing/jaeger/cmd/jaeger/internal/extension/jaegerstorage" queryApp "github.com/jaegertracing/jaeger/cmd/query/app" "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" + "github.com/jaegertracing/jaeger/pkg/jtracer" "github.com/jaegertracing/jaeger/pkg/telemetery" "github.com/jaegertracing/jaeger/pkg/tenancy" "github.com/jaegertracing/jaeger/plugin/metrics/disabled" @@ -71,12 +72,16 @@ func (s *server) Start(_ context.Context, host component.Host) error { // TODO OTel-collector does not initialize the tracer currently // https://github.com/open-telemetry/opentelemetry-collector/issues/7532 //nolint - + tracerProvider, err := jtracer.New("jaeger") + if err != nil { + return fmt.Errorf("could not initialize a tracer: %w", err) + } internalTelset := telemetery.Setting{ Logger: s.telset.Logger, - TracerProvider: s.telset.TracerProvider, + TracerProvider: tracerProvider.OTEL, ReportStatus: s.telset.ReportStatus, } + // TODO contextcheck linter complains about next line that context is not passed. It is not wrong. //nolint s.server, err = queryApp.NewServer( From 2396ca513814867537f668741353a488b3d88dc0 Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Fri, 5 Jul 2024 20:30:57 +0530 Subject: [PATCH 15/29] Made suggested changes Signed-off-by: Wise-Wizard --- cmd/jaeger/internal/extension/jaegerquery/server.go | 4 ++-- cmd/query/app/server.go | 6 +++--- pkg/telemetery/settings.go | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cmd/jaeger/internal/extension/jaegerquery/server.go b/cmd/jaeger/internal/extension/jaegerquery/server.go index d75abaa609f..babaf6b3ec6 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server.go @@ -76,7 +76,7 @@ func (s *server) Start(_ context.Context, host component.Host) error { if err != nil { return fmt.Errorf("could not initialize a tracer: %w", err) } - internalTelset := telemetery.Setting{ + telset := telemetery.Setting{ Logger: s.telset.Logger, TracerProvider: tracerProvider.OTEL, ReportStatus: s.telset.ReportStatus, @@ -90,7 +90,7 @@ func (s *server) Start(_ context.Context, host component.Host) error { metricsQueryService, s.makeQueryOptions(), tm, - internalTelset, + telset, ) if err != nil { return fmt.Errorf("could not create jaeger-query: %w", err) diff --git a/cmd/query/app/server.go b/cmd/query/app/server.go index 927b0af1ff6..edd4b046cae 100644 --- a/cmd/query/app/server.go +++ b/cmd/query/app/server.go @@ -306,7 +306,7 @@ func (s *Server) Start() error { s.telset.Logger.Error("Could not start HTTP server", zap.Error(err)) } s.telset.Logger.Info("HTTP server stopped", zap.Int("port", httpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) - s.telset.ReportStatus(component.NewStatusEvent(component.StatusStopping)) + s.telset.ReportStatus(component.NewStatusEvent(component.StatusStopped)) s.bgFinished.Done() }() @@ -320,7 +320,7 @@ func (s *Server) Start() error { s.telset.Logger.Error("Could not start GRPC server", zap.Error(err)) } s.telset.Logger.Info("GRPC server stopped", zap.Int("port", grpcPort), zap.String("addr", s.queryOptions.GRPCHostPort)) - s.telset.ReportStatus(component.NewStatusEvent(component.StatusStopping)) + s.telset.ReportStatus(component.NewStatusEvent(component.StatusStopped)) s.bgFinished.Done() }() @@ -336,7 +336,7 @@ func (s *Server) Start() error { s.telset.Logger.Error("Could not start multiplexed server", zap.Error(err)) } s.telset.Logger.Info("CMUX server stopped", zap.Int("port", tcpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) - s.telset.ReportStatus(component.NewStatusEvent(component.StatusStopping)) + s.telset.ReportStatus(component.NewStatusEvent(component.StatusStopped)) s.bgFinished.Done() }() } diff --git a/pkg/telemetery/settings.go b/pkg/telemetery/settings.go index 2167a933044..1cb9551a6b9 100644 --- a/pkg/telemetery/settings.go +++ b/pkg/telemetery/settings.go @@ -29,9 +29,10 @@ func HCAdapter(hc *healthcheck.HealthCheck) func(*component.StatusEvent) { component.StatusRecoverableError, component.StatusPermanentError, component.StatusNone, - component.StatusStopping: + component.StatusStopping, + component.StatusStopped: hcStatus = healthcheck.Unavailable - case component.StatusFatalError, component.StatusStopped: + case component.StatusFatalError: hcStatus = healthcheck.Broken } hc.Set(hcStatus) From 2abe801d37197669d81604215253e29dbd2b8972 Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Fri, 5 Jul 2024 21:49:47 +0530 Subject: [PATCH 16/29] Reduced number of ReportStatus calls Signed-off-by: Wise-Wizard --- cmd/query/app/server.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/query/app/server.go b/cmd/query/app/server.go index edd4b046cae..66342c4c185 100644 --- a/cmd/query/app/server.go +++ b/cmd/query/app/server.go @@ -306,7 +306,6 @@ func (s *Server) Start() error { s.telset.Logger.Error("Could not start HTTP server", zap.Error(err)) } s.telset.Logger.Info("HTTP server stopped", zap.Int("port", httpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) - s.telset.ReportStatus(component.NewStatusEvent(component.StatusStopped)) s.bgFinished.Done() }() @@ -320,7 +319,6 @@ func (s *Server) Start() error { s.telset.Logger.Error("Could not start GRPC server", zap.Error(err)) } s.telset.Logger.Info("GRPC server stopped", zap.Int("port", grpcPort), zap.String("addr", s.queryOptions.GRPCHostPort)) - s.telset.ReportStatus(component.NewStatusEvent(component.StatusStopped)) s.bgFinished.Done() }() @@ -336,11 +334,14 @@ func (s *Server) Start() error { s.telset.Logger.Error("Could not start multiplexed server", zap.Error(err)) } s.telset.Logger.Info("CMUX server stopped", zap.Int("port", tcpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) - s.telset.ReportStatus(component.NewStatusEvent(component.StatusStopped)) s.bgFinished.Done() }() } - + if err != nil { + s.telset.ReportStatus(component.NewStatusEvent(component.StatusFatalError)) + return err + } + s.telset.ReportStatus(component.NewStatusEvent(component.StatusOK)) return nil } From ca9950c081f337d4d69ec874cbe337616568eb6a Mon Sep 17 00:00:00 2001 From: Saransh Shankar <103821431+Wise-Wizard@users.noreply.github.com> Date: Fri, 5 Jul 2024 22:56:33 +0530 Subject: [PATCH 17/29] Update cmd/query/app/server.go Co-authored-by: Yuri Shkuro Signed-off-by: Saransh Shankar <103821431+Wise-Wizard@users.noreply.github.com> --- cmd/query/app/server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/query/app/server.go b/cmd/query/app/server.go index 66342c4c185..9f2d518af07 100644 --- a/cmd/query/app/server.go +++ b/cmd/query/app/server.go @@ -60,7 +60,7 @@ type Server struct { httpServer *httpServer separatePorts bool bgFinished sync.WaitGroup - telset telemetery.Setting + telemetery.Setting } // NewServer creates and initializes Server From a297feb27adf99f830c3a2db9497eb8f03b53027 Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Fri, 5 Jul 2024 23:02:20 +0530 Subject: [PATCH 18/29] Cleaned up COde Signed-off-by: Wise-Wizard --- cmd/query/app/server.go | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/cmd/query/app/server.go b/cmd/query/app/server.go index 9f2d518af07..4e64a8b3ed9 100644 --- a/cmd/query/app/server.go +++ b/cmd/query/app/server.go @@ -99,7 +99,6 @@ func NewServer(querySvc *querysvc.QueryService, grpcServer: grpcServer, httpServer: httpServer, separatePorts: grpcPort != httpPort, - telset: telset, }, nil } @@ -230,7 +229,7 @@ func (s *Server) initListener() (cmux.CMux, error) { if err != nil { return nil, err } - s.telset.Logger.Info( + s.Logger.Info( "Query server started", zap.String("http_addr", s.httpConn.Addr().String()), zap.String("grpc_addr", s.grpcConn.Addr().String()), @@ -251,7 +250,7 @@ func (s *Server) initListener() (cmux.CMux, error) { tcpPort = port } - s.telset.Logger.Info( + s.Logger.Info( "Query server started", zap.Int("port", tcpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) @@ -295,7 +294,7 @@ func (s *Server) Start() error { s.bgFinished.Add(1) go func() { - s.telset.Logger.Info("Starting HTTP server", zap.Int("port", httpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) + s.Logger.Info("Starting HTTP server", zap.Int("port", httpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) var err error if s.queryOptions.TLSHTTP.Enabled { err = s.httpServer.ServeTLS(s.httpConn, "", "") @@ -303,22 +302,24 @@ func (s *Server) Start() error { err = s.httpServer.Serve(s.httpConn) } if err != nil && !errors.Is(err, http.ErrServerClosed) && !errors.Is(err, cmux.ErrListenerClosed) && !errors.Is(err, cmux.ErrServerClosed) { - s.telset.Logger.Error("Could not start HTTP server", zap.Error(err)) + s.Logger.Error("Could not start HTTP server", zap.Error(err)) + s.ReportStatus(component.NewFatalErrorEvent(err)) } - s.telset.Logger.Info("HTTP server stopped", zap.Int("port", httpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) + s.Logger.Info("HTTP server stopped", zap.Int("port", httpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) s.bgFinished.Done() }() // Start GRPC server concurrently s.bgFinished.Add(1) go func() { - s.telset.Logger.Info("Starting GRPC server", zap.Int("port", grpcPort), zap.String("addr", s.queryOptions.GRPCHostPort)) + s.Logger.Info("Starting GRPC server", zap.Int("port", grpcPort), zap.String("addr", s.queryOptions.GRPCHostPort)) err := s.grpcServer.Serve(s.grpcConn) if err != nil && !errors.Is(err, cmux.ErrListenerClosed) && !errors.Is(err, cmux.ErrServerClosed) { - s.telset.Logger.Error("Could not start GRPC server", zap.Error(err)) + s.Logger.Error("Could not start GRPC server", zap.Error(err)) + s.ReportStatus(component.NewFatalErrorEvent(err)) } - s.telset.Logger.Info("GRPC server stopped", zap.Int("port", grpcPort), zap.String("addr", s.queryOptions.GRPCHostPort)) + s.Logger.Info("GRPC server stopped", zap.Int("port", grpcPort), zap.String("addr", s.queryOptions.GRPCHostPort)) s.bgFinished.Done() }() @@ -326,22 +327,18 @@ func (s *Server) Start() error { if !s.separatePorts { s.bgFinished.Add(1) go func() { - s.telset.Logger.Info("Starting CMUX server", zap.Int("port", tcpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) + s.Logger.Info("Starting CMUX server", zap.Int("port", tcpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) err := cmuxServer.Serve() // TODO: find a way to avoid string comparison. Even though cmux has ErrServerClosed, it's not returned here. if err != nil && !strings.Contains(err.Error(), "use of closed network connection") { - s.telset.Logger.Error("Could not start multiplexed server", zap.Error(err)) + s.Logger.Error("Could not start multiplexed server", zap.Error(err)) + s.ReportStatus(component.NewFatalErrorEvent(err)) } - s.telset.Logger.Info("CMUX server stopped", zap.Int("port", tcpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) + s.Logger.Info("CMUX server stopped", zap.Int("port", tcpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) s.bgFinished.Done() }() } - if err != nil { - s.telset.ReportStatus(component.NewStatusEvent(component.StatusFatalError)) - return err - } - s.telset.ReportStatus(component.NewStatusEvent(component.StatusOK)) return nil } @@ -352,20 +349,20 @@ func (s *Server) Close() error { s.queryOptions.TLSHTTP.Close(), } - s.telset.Logger.Info("Closing HTTP server") + s.Logger.Info("Closing HTTP server") if err := s.httpServer.Close(); err != nil { errs = append(errs, fmt.Errorf("failed to close HTTP server: %w", err)) } - s.telset.Logger.Info("Stopping gRPC server") + s.Logger.Info("Stopping gRPC server") s.grpcServer.Stop() if !s.separatePorts { - s.telset.Logger.Info("Closing CMux server") + s.Logger.Info("Closing CMux server") s.cmuxServer.Close() } s.bgFinished.Wait() - s.telset.ReportStatus(component.NewStatusEvent(component.StatusStopped)) - s.telset.Logger.Info("Server stopped") + s.ReportStatus(component.NewStatusEvent(component.StatusStopped)) + s.Logger.Info("Server stopped") return errors.Join(errs...) } From 6680ea3401dad4033a996bdaef47433f91ddf48b Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Fri, 5 Jul 2024 23:09:05 +0530 Subject: [PATCH 19/29] Pass telset to struct Signed-off-by: Wise-Wizard --- cmd/query/app/server.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/query/app/server.go b/cmd/query/app/server.go index 4e64a8b3ed9..0993626b07c 100644 --- a/cmd/query/app/server.go +++ b/cmd/query/app/server.go @@ -99,6 +99,7 @@ func NewServer(querySvc *querysvc.QueryService, grpcServer: grpcServer, httpServer: httpServer, separatePorts: grpcPort != httpPort, + Setting: telset, }, nil } From bc958c248175d35db30f7593c7f36f909c9e4a93 Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Fri, 5 Jul 2024 23:22:54 +0530 Subject: [PATCH 20/29] Made suggested changes Signed-off-by: Wise-Wizard --- cmd/query/app/server.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/query/app/server.go b/cmd/query/app/server.go index 0993626b07c..053889c354d 100644 --- a/cmd/query/app/server.go +++ b/cmd/query/app/server.go @@ -295,6 +295,7 @@ func (s *Server) Start() error { s.bgFinished.Add(1) go func() { + defer s.bgFinished.Done() s.Logger.Info("Starting HTTP server", zap.Int("port", httpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) var err error if s.queryOptions.TLSHTTP.Enabled { @@ -305,29 +306,34 @@ func (s *Server) Start() error { if err != nil && !errors.Is(err, http.ErrServerClosed) && !errors.Is(err, cmux.ErrListenerClosed) && !errors.Is(err, cmux.ErrServerClosed) { s.Logger.Error("Could not start HTTP server", zap.Error(err)) s.ReportStatus(component.NewFatalErrorEvent(err)) + return } s.Logger.Info("HTTP server stopped", zap.Int("port", httpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) - s.bgFinished.Done() + s.ReportStatus(component.NewStatusEvent(component.StatusStopped)) + }() // Start GRPC server concurrently s.bgFinished.Add(1) go func() { + defer s.bgFinished.Done() s.Logger.Info("Starting GRPC server", zap.Int("port", grpcPort), zap.String("addr", s.queryOptions.GRPCHostPort)) err := s.grpcServer.Serve(s.grpcConn) if err != nil && !errors.Is(err, cmux.ErrListenerClosed) && !errors.Is(err, cmux.ErrServerClosed) { s.Logger.Error("Could not start GRPC server", zap.Error(err)) s.ReportStatus(component.NewFatalErrorEvent(err)) + return } s.Logger.Info("GRPC server stopped", zap.Int("port", grpcPort), zap.String("addr", s.queryOptions.GRPCHostPort)) - s.bgFinished.Done() + s.ReportStatus(component.NewStatusEvent(component.StatusStopped)) }() // Start cmux server concurrently. if !s.separatePorts { s.bgFinished.Add(1) go func() { + defer s.bgFinished.Done() s.Logger.Info("Starting CMUX server", zap.Int("port", tcpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) err := cmuxServer.Serve() @@ -335,9 +341,10 @@ func (s *Server) Start() error { if err != nil && !strings.Contains(err.Error(), "use of closed network connection") { s.Logger.Error("Could not start multiplexed server", zap.Error(err)) s.ReportStatus(component.NewFatalErrorEvent(err)) + return } s.Logger.Info("CMUX server stopped", zap.Int("port", tcpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) - s.bgFinished.Done() + s.ReportStatus(component.NewStatusEvent(component.StatusStopped)) }() } return nil From 8654a323e49023a2a6b644bbb381b6c29be0b49e Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Sat, 6 Jul 2024 00:45:23 +0530 Subject: [PATCH 21/29] Worked on Test Signed-off-by: Wise-Wizard --- cmd/query/app/server.go | 3 --- cmd/query/app/server_test.go | 31 ++++++++++++++++++++++--------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/cmd/query/app/server.go b/cmd/query/app/server.go index 053889c354d..c36a8cb7296 100644 --- a/cmd/query/app/server.go +++ b/cmd/query/app/server.go @@ -309,7 +309,6 @@ func (s *Server) Start() error { return } s.Logger.Info("HTTP server stopped", zap.Int("port", httpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) - s.ReportStatus(component.NewStatusEvent(component.StatusStopped)) }() @@ -326,7 +325,6 @@ func (s *Server) Start() error { return } s.Logger.Info("GRPC server stopped", zap.Int("port", grpcPort), zap.String("addr", s.queryOptions.GRPCHostPort)) - s.ReportStatus(component.NewStatusEvent(component.StatusStopped)) }() // Start cmux server concurrently. @@ -344,7 +342,6 @@ func (s *Server) Start() error { return } s.Logger.Info("CMUX server stopped", zap.Int("port", tcpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) - s.ReportStatus(component.NewStatusEvent(component.StatusStopped)) }() } return nil diff --git a/cmd/query/app/server_test.go b/cmd/query/app/server_test.go index b556aecd87f..01706298bb2 100644 --- a/cmd/query/app/server_test.go +++ b/cmd/query/app/server_test.go @@ -40,6 +40,7 @@ import ( "github.com/jaegertracing/jaeger/pkg/config/tlscfg" "github.com/jaegertracing/jaeger/pkg/healthcheck" "github.com/jaegertracing/jaeger/pkg/jtracer" + "github.com/jaegertracing/jaeger/pkg/telemetery" "github.com/jaegertracing/jaeger/pkg/tenancy" "github.com/jaegertracing/jaeger/ports" "github.com/jaegertracing/jaeger/proto-gen/api_v2" @@ -66,10 +67,14 @@ func TestCreateTLSServerSinglePortError(t *testing.T) { KeyPath: testCertKeyLocation + "/example-server-key.pem", ClientCAPath: testCertKeyLocation + "/example-CA-cert.pem", } - - _, err := NewServer(zaptest.NewLogger(t), healthcheck.New(), &querysvc.QueryService{}, nil, + telset := telemetery.Setting{ + Logger: zaptest.NewLogger(t), + TracerProvider: jtracer.NoOp().OTEL, + ReportStatus: telemetery.HCAdapter(healthcheck.New()), + } + _, err := NewServer(&querysvc.QueryService{}, nil, &QueryOptions{HTTPHostPort: ":8080", GRPCHostPort: ":8080", TLSGRPC: tlsCfg, TLSHTTP: tlsCfg}, - tenancy.NewManager(&tenancy.Options{}), jtracer.NoOp()) + tenancy.NewManager(&tenancy.Options{}), telset) require.Error(t, err) } @@ -80,10 +85,14 @@ func TestCreateTLSGrpcServerError(t *testing.T) { KeyPath: "invalid/path", ClientCAPath: "invalid/path", } - - _, err := NewServer(zaptest.NewLogger(t), healthcheck.New(), &querysvc.QueryService{}, nil, + telset := telemetery.Setting{ + Logger: zaptest.NewLogger(t), + TracerProvider: jtracer.NoOp().OTEL, + ReportStatus: telemetery.HCAdapter(healthcheck.New()), + } + _, err := NewServer(&querysvc.QueryService{}, nil, &QueryOptions{HTTPHostPort: ":8080", GRPCHostPort: ":8081", TLSGRPC: tlsCfg}, - tenancy.NewManager(&tenancy.Options{}), jtracer.NoOp()) + tenancy.NewManager(&tenancy.Options{}), telset) require.Error(t, err) } @@ -94,10 +103,14 @@ func TestCreateTLSHttpServerError(t *testing.T) { KeyPath: "invalid/path", ClientCAPath: "invalid/path", } - - _, err := NewServer(zaptest.NewLogger(t), healthcheck.New(), &querysvc.QueryService{}, nil, + telset := telemetery.Setting{ + Logger: zaptest.NewLogger(t), + TracerProvider: jtracer.NoOp().OTEL, + ReportStatus: telemetery.HCAdapter(healthcheck.New()), + } + _, err := NewServer(&querysvc.QueryService{}, nil, &QueryOptions{HTTPHostPort: ":8080", GRPCHostPort: ":8081", TLSHTTP: tlsCfg}, - tenancy.NewManager(&tenancy.Options{}), jtracer.NoOp()) + tenancy.NewManager(&tenancy.Options{}), telset) require.Error(t, err) } From db18701a68a637fdaa7d120ede5d1eca2b1990fa Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Sat, 6 Jul 2024 09:27:40 +0530 Subject: [PATCH 22/29] Cleaned up Test File Signed-off-by: Wise-Wizard --- cmd/query/app/server.go | 3 +- cmd/query/app/server_test.go | 73 ++++++++++++++++++------------------ pkg/telemetery/empty_test.go | 4 ++ 3 files changed, 41 insertions(+), 39 deletions(-) create mode 100644 pkg/telemetery/empty_test.go diff --git a/cmd/query/app/server.go b/cmd/query/app/server.go index c36a8cb7296..98b24df8a1f 100644 --- a/cmd/query/app/server.go +++ b/cmd/query/app/server.go @@ -309,7 +309,6 @@ func (s *Server) Start() error { return } s.Logger.Info("HTTP server stopped", zap.Int("port", httpPort), zap.String("addr", s.queryOptions.HTTPHostPort)) - }() // Start GRPC server concurrently @@ -322,7 +321,7 @@ func (s *Server) Start() error { if err != nil && !errors.Is(err, cmux.ErrListenerClosed) && !errors.Is(err, cmux.ErrServerClosed) { s.Logger.Error("Could not start GRPC server", zap.Error(err)) s.ReportStatus(component.NewFatalErrorEvent(err)) - return + return } s.Logger.Info("GRPC server stopped", zap.Int("port", grpcPort), zap.String("addr", s.queryOptions.GRPCHostPort)) }() diff --git a/cmd/query/app/server_test.go b/cmd/query/app/server_test.go index 01706298bb2..e2d5c839365 100644 --- a/cmd/query/app/server_test.go +++ b/cmd/query/app/server_test.go @@ -50,6 +50,14 @@ import ( var testCertKeyLocation = "../../../pkg/config/tlscfg/testdata" +func initTelSet(logger *zap.Logger, tracerProvider *jtracer.JTracer, hc *healthcheck.HealthCheck) telemetery.Setting { + return telemetery.Setting{ + Logger: logger, + TracerProvider: tracerProvider.OTEL, + ReportStatus: telemetery.HCAdapter(hc), + } +} + func TestServerError(t *testing.T) { srv := &Server{ queryOptions: &QueryOptions{ @@ -67,11 +75,7 @@ func TestCreateTLSServerSinglePortError(t *testing.T) { KeyPath: testCertKeyLocation + "/example-server-key.pem", ClientCAPath: testCertKeyLocation + "/example-CA-cert.pem", } - telset := telemetery.Setting{ - Logger: zaptest.NewLogger(t), - TracerProvider: jtracer.NoOp().OTEL, - ReportStatus: telemetery.HCAdapter(healthcheck.New()), - } + telset := initTelSet(zaptest.NewLogger(t), jtracer.NoOp(), healthcheck.New()) _, err := NewServer(&querysvc.QueryService{}, nil, &QueryOptions{HTTPHostPort: ":8080", GRPCHostPort: ":8080", TLSGRPC: tlsCfg, TLSHTTP: tlsCfg}, tenancy.NewManager(&tenancy.Options{}), telset) @@ -85,11 +89,7 @@ func TestCreateTLSGrpcServerError(t *testing.T) { KeyPath: "invalid/path", ClientCAPath: "invalid/path", } - telset := telemetery.Setting{ - Logger: zaptest.NewLogger(t), - TracerProvider: jtracer.NoOp().OTEL, - ReportStatus: telemetery.HCAdapter(healthcheck.New()), - } + telset := initTelSet(zaptest.NewLogger(t), jtracer.NoOp(), healthcheck.New()) _, err := NewServer(&querysvc.QueryService{}, nil, &QueryOptions{HTTPHostPort: ":8080", GRPCHostPort: ":8081", TLSGRPC: tlsCfg}, tenancy.NewManager(&tenancy.Options{}), telset) @@ -103,11 +103,7 @@ func TestCreateTLSHttpServerError(t *testing.T) { KeyPath: "invalid/path", ClientCAPath: "invalid/path", } - telset := telemetery.Setting{ - Logger: zaptest.NewLogger(t), - TracerProvider: jtracer.NoOp().OTEL, - ReportStatus: telemetery.HCAdapter(healthcheck.New()), - } + telset := initTelSet(zaptest.NewLogger(t), jtracer.NoOp(), healthcheck.New()) _, err := NewServer(&querysvc.QueryService{}, nil, &QueryOptions{HTTPHostPort: ":8080", GRPCHostPort: ":8081", TLSHTTP: tlsCfg}, tenancy.NewManager(&tenancy.Options{}), telset) @@ -367,11 +363,11 @@ func TestServerHTTPTLS(t *testing.T) { } flagsSvc := flags.NewService(ports.QueryAdminHTTP) flagsSvc.Logger = zaptest.NewLogger(t) - + telset := initTelSet(flagsSvc.Logger, jtracer.NoOp(), flagsSvc.HC()) querySvc := makeQuerySvc() - server, err := NewServer(flagsSvc.Logger, flagsSvc.HC(), querySvc.qs, + server, err := NewServer(querySvc.qs, nil, serverOptions, tenancy.NewManager(&tenancy.Options{}), - jtracer.NoOp()) + telset) require.NoError(t, err) require.NoError(t, server.Start()) t.Cleanup(func() { @@ -506,9 +502,10 @@ func TestServerGRPCTLS(t *testing.T) { flagsSvc.Logger = zaptest.NewLogger(t) querySvc := makeQuerySvc() - server, err := NewServer(flagsSvc.Logger, flagsSvc.HC(), querySvc.qs, + telset := initTelSet(flagsSvc.Logger, jtracer.NoOp(), flagsSvc.HC()) + server, err := NewServer(querySvc.qs, nil, serverOptions, tenancy.NewManager(&tenancy.Options{}), - jtracer.NoOp()) + telset) require.NoError(t, err) require.NoError(t, server.Start()) t.Cleanup(func() { @@ -548,7 +545,8 @@ func TestServerGRPCTLS(t *testing.T) { } func TestServerBadHostPort(t *testing.T) { - _, err := NewServer(zaptest.NewLogger(t), healthcheck.New(), &querysvc.QueryService{}, nil, + telset := initTelSet(zaptest.NewLogger(t), jtracer.NoOp(), healthcheck.New()) + _, err := NewServer(&querysvc.QueryService{}, nil, &QueryOptions{ HTTPHostPort: "8080", // bad string, not :port GRPCHostPort: "127.0.0.1:8081", @@ -557,10 +555,10 @@ func TestServerBadHostPort(t *testing.T) { }, }, tenancy.NewManager(&tenancy.Options{}), - jtracer.NoOp()) + telset) require.Error(t, err) - _, err = NewServer(zaptest.NewLogger(t), healthcheck.New(), &querysvc.QueryService{}, nil, + _, err = NewServer(&querysvc.QueryService{}, nil, &QueryOptions{ HTTPHostPort: "127.0.0.1:8081", GRPCHostPort: "9123", // bad string, not :port @@ -569,7 +567,7 @@ func TestServerBadHostPort(t *testing.T) { }, }, tenancy.NewManager(&tenancy.Options{}), - jtracer.NoOp()) + telset) require.Error(t, err) } @@ -579,7 +577,7 @@ func TestServerInUseHostPort(t *testing.T) { conn, err := net.Listen("tcp", availableHostPort) require.NoError(t, err) defer func() { require.NoError(t, conn.Close()) }() - + telset := initTelSet(zaptest.NewLogger(t), jtracer.NoOp(), healthcheck.New()) testCases := []struct { name string httpHostPort string @@ -591,8 +589,6 @@ func TestServerInUseHostPort(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { server, err := NewServer( - zaptest.NewLogger(t), - healthcheck.New(), &querysvc.QueryService{}, nil, &QueryOptions{ @@ -603,7 +599,7 @@ func TestServerInUseHostPort(t *testing.T) { }, }, tenancy.NewManager(&tenancy.Options{}), - jtracer.NoOp(), + telset, ) require.NoError(t, err) require.Error(t, server.Start()) @@ -617,7 +613,8 @@ func TestServerSinglePort(t *testing.T) { flagsSvc.Logger = zaptest.NewLogger(t, zaptest.WrapOptions(zap.AddCaller())) hostPort := ports.GetAddressFromCLIOptions(ports.QueryHTTP, "") querySvc := makeQuerySvc() - server, err := NewServer(flagsSvc.Logger, flagsSvc.HC(), querySvc.qs, nil, + telset := initTelSet(flagsSvc.Logger, jtracer.NoOp(), flagsSvc.HC()) + server, err := NewServer(querySvc.qs, nil, &QueryOptions{ GRPCHostPort: hostPort, HTTPHostPort: hostPort, @@ -626,7 +623,7 @@ func TestServerSinglePort(t *testing.T) { }, }, tenancy.NewManager(&tenancy.Options{}), - jtracer.NoOp()) + telset) require.NoError(t, err) require.NoError(t, server.Start()) t.Cleanup(func() { @@ -657,9 +654,10 @@ func TestServerGracefulExit(t *testing.T) { hostPort := ports.PortToHostPort(ports.QueryAdminHTTP) querySvc := makeQuerySvc() - server, err := NewServer(flagsSvc.Logger, flagsSvc.HC(), querySvc.qs, nil, + telset := initTelSet(flagsSvc.Logger, jtracer.NoOp(), flagsSvc.HC()) + server, err := NewServer(querySvc.qs, nil, &QueryOptions{GRPCHostPort: hostPort, HTTPHostPort: hostPort}, - tenancy.NewManager(&tenancy.Options{}), jtracer.NoOp()) + tenancy.NewManager(&tenancy.Options{}), telset) require.NoError(t, err) require.NoError(t, server.Start()) @@ -689,11 +687,11 @@ func TestServerHandlesPortZero(t *testing.T) { flagsSvc.Logger = zap.New(zapCore) querySvc := &querysvc.QueryService{} - tracer := jtracer.NoOp() - server, err := NewServer(flagsSvc.Logger, flagsSvc.HC(), querySvc, nil, + telset := initTelSet(flagsSvc.Logger, jtracer.NoOp(), flagsSvc.HC()) + server, err := NewServer(querySvc, nil, &QueryOptions{GRPCHostPort: ":0", HTTPHostPort: ":0"}, tenancy.NewManager(&tenancy.Options{}), - tracer) + telset) require.NoError(t, err) require.NoError(t, server.Start()) defer server.Close() @@ -748,8 +746,9 @@ func TestServerHTTPTenancy(t *testing.T) { tenancyMgr := tenancy.NewManager(&serverOptions.Tenancy) querySvc := makeQuerySvc() querySvc.spanReader.On("FindTraces", mock.Anything, mock.Anything).Return([]*model.Trace{mockTrace}, nil).Once() - server, err := NewServer(zaptest.NewLogger(t), healthcheck.New(), querySvc.qs, - nil, serverOptions, tenancyMgr, jtracer.NoOp()) + telset := initTelSet(zaptest.NewLogger(t), jtracer.NoOp(), healthcheck.New()) + server, err := NewServer(querySvc.qs, + nil, serverOptions, tenancyMgr, telset) require.NoError(t, err) require.NoError(t, server.Start()) t.Cleanup(func() { diff --git a/pkg/telemetery/empty_test.go b/pkg/telemetery/empty_test.go new file mode 100644 index 00000000000..fa0482426c8 --- /dev/null +++ b/pkg/telemetery/empty_test.go @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + +package telemetery_test From 45a1ba3bd7fe2712a5cf9c9594a63a4d9b75a71e Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Sat, 6 Jul 2024 09:32:21 +0530 Subject: [PATCH 23/29] Fix Linter Errors Signed-off-by: Wise-Wizard --- pkg/telemetery/empty_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/telemetery/empty_test.go b/pkg/telemetery/empty_test.go index fa0482426c8..e7647bec43a 100644 --- a/pkg/telemetery/empty_test.go +++ b/pkg/telemetery/empty_test.go @@ -2,3 +2,18 @@ // SPDX-License-Identifier: Apache-2.0 package telemetery_test + +import ( + "testing" + + "github.com/jaegertracing/jaeger/pkg/testutils" +) + +func TestDummy(*testing.T) { + // This is a dummy test in the root package. + // Without it `go test -v .` prints "testing: warning: no tests to run". +} + +func TestMain(m *testing.M) { + testutils.VerifyGoLeaks(m) +} From 65ecbd37c8871b5837dcb2effacd74e5c9905bf2 Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Sat, 6 Jul 2024 10:15:47 +0530 Subject: [PATCH 24/29] Fix goleak Signed-off-by: Wise-Wizard --- .../internal/extension/jaegerquery/server.go | 2 +- .../internal/extension/jaegerquery/server_test.go | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/jaeger/internal/extension/jaegerquery/server.go b/cmd/jaeger/internal/extension/jaegerquery/server.go index babaf6b3ec6..abb80f35289 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server.go @@ -130,6 +130,6 @@ func (s *server) makeQueryOptions() *queryApp.QueryOptions { } } -func (s *server) Shutdown(ctx context.Context) error { +func (s *server) Shutdown(_ context.Context) error { return s.server.Close() } diff --git a/cmd/jaeger/internal/extension/jaegerquery/server_test.go b/cmd/jaeger/internal/extension/jaegerquery/server_test.go index 36cc4d82c4c..a5df2ba63a2 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server_test.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server_test.go @@ -119,13 +119,13 @@ func TestServerStart(t *testing.T) { config *Config expectedErr string }{ - { - name: "Non-empty config with fake storage host", - config: &Config{ - TraceStorageArchive: "jaeger_storage", - TraceStoragePrimary: "jaeger_storage", - }, - }, + // { + // name: "Non-empty config with fake storage host", + // config: &Config{ + // TraceStorageArchive: "jaeger_storage", + // TraceStoragePrimary: "jaeger_storage", + // }, + // }, { name: "factory error", config: &Config{ From 74403eea24eaf505bd6e76da799d51464ba28669 Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Sun, 7 Jul 2024 21:11:14 +0530 Subject: [PATCH 25/29] Added Tests Signed-off-by: Wise-Wizard --- .../internal/extension/jaegerquery/server.go | 20 +++-- .../extension/jaegerquery/server_test.go | 14 ++-- pkg/telemetery/empty_test.go | 19 ----- pkg/telemetery/settings_test.go | 73 +++++++++++++++++++ 4 files changed, 95 insertions(+), 31 deletions(-) delete mode 100644 pkg/telemetery/empty_test.go create mode 100644 pkg/telemetery/settings_test.go diff --git a/cmd/jaeger/internal/extension/jaegerquery/server.go b/cmd/jaeger/internal/extension/jaegerquery/server.go index abb80f35289..697c57d7033 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server.go @@ -5,6 +5,7 @@ package jaegerquery import ( "context" + "errors" "fmt" "go.opentelemetry.io/collector/component" @@ -26,9 +27,10 @@ var ( ) type server struct { - config *Config - server *queryApp.Server - telset component.TelemetrySettings + config *Config + server *queryApp.Server + telset component.TelemetrySettings + closeTracer func(ctx context.Context) error } func newServer(config *Config, otel component.TelemetrySettings) *server { @@ -76,6 +78,7 @@ func (s *server) Start(_ context.Context, host component.Host) error { if err != nil { return fmt.Errorf("could not initialize a tracer: %w", err) } + s.closeTracer = tracerProvider.Close telset := telemetery.Setting{ Logger: s.telset.Logger, TracerProvider: tracerProvider.OTEL, @@ -130,6 +133,13 @@ func (s *server) makeQueryOptions() *queryApp.QueryOptions { } } -func (s *server) Shutdown(_ context.Context) error { - return s.server.Close() +func (s *server) Shutdown(ctx context.Context) error { + var errs []error + if s.server != nil { + errs = append(errs, s.server.Close()) + } + if s.server.TracerProvider != nil { + errs = append(errs, s.closeTracer(ctx)) + } + return errors.Join(errs...) } diff --git a/cmd/jaeger/internal/extension/jaegerquery/server_test.go b/cmd/jaeger/internal/extension/jaegerquery/server_test.go index a5df2ba63a2..36cc4d82c4c 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server_test.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server_test.go @@ -119,13 +119,13 @@ func TestServerStart(t *testing.T) { config *Config expectedErr string }{ - // { - // name: "Non-empty config with fake storage host", - // config: &Config{ - // TraceStorageArchive: "jaeger_storage", - // TraceStoragePrimary: "jaeger_storage", - // }, - // }, + { + name: "Non-empty config with fake storage host", + config: &Config{ + TraceStorageArchive: "jaeger_storage", + TraceStoragePrimary: "jaeger_storage", + }, + }, { name: "factory error", config: &Config{ diff --git a/pkg/telemetery/empty_test.go b/pkg/telemetery/empty_test.go deleted file mode 100644 index e7647bec43a..00000000000 --- a/pkg/telemetery/empty_test.go +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2024 The Jaeger Authors. -// SPDX-License-Identifier: Apache-2.0 - -package telemetery_test - -import ( - "testing" - - "github.com/jaegertracing/jaeger/pkg/testutils" -) - -func TestDummy(*testing.T) { - // This is a dummy test in the root package. - // Without it `go test -v .` prints "testing: warning: no tests to run". -} - -func TestMain(m *testing.M) { - testutils.VerifyGoLeaks(m) -} diff --git a/pkg/telemetery/settings_test.go b/pkg/telemetery/settings_test.go new file mode 100644 index 00000000000..38ae3c6a1ee --- /dev/null +++ b/pkg/telemetery/settings_test.go @@ -0,0 +1,73 @@ +// Copyright (c) 2024 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + +package telemetery_test + +import ( + "testing" + + "github.com/jaegertracing/jaeger/pkg/healthcheck" + "github.com/jaegertracing/jaeger/pkg/telemetery" + "github.com/stretchr/testify/assert" + + "go.opentelemetry.io/collector/component" +) + +func TestHCAdapter(t *testing.T) { + tests := []struct { + name string + status component.Status + expectedHC healthcheck.Status + }{ + { + name: "StatusOK", + status: component.StatusOK, + expectedHC: healthcheck.Ready, + }, + { + name: "StatusStarting", + status: component.StatusStarting, + expectedHC: healthcheck.Unavailable, + }, + { + name: "StatusRecoverableError", + status: component.StatusRecoverableError, + expectedHC: healthcheck.Unavailable, + }, + { + name: "StatusPermanentError", + status: component.StatusPermanentError, + expectedHC: healthcheck.Unavailable, + }, + { + name: "StatusNone", + status: component.StatusNone, + expectedHC: healthcheck.Unavailable, + }, + { + name: "StatusStopping", + status: component.StatusStopping, + expectedHC: healthcheck.Unavailable, + }, + { + name: "StatusStopped", + status: component.StatusStopped, + expectedHC: healthcheck.Unavailable, + }, + { + name: "StatusFatalError", + status: component.StatusFatalError, + expectedHC: healthcheck.Broken, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + hc := healthcheck.New() + hcAdapter := telemetery.HCAdapter(hc) + event := component.NewStatusEvent(tt.status) + hcAdapter(event) + assert.Equal(t, tt.expectedHC, hc.Get()) + }) + } +} From 3d9ba042a56f6a043ce11bebdd989b9174580c82 Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Sun, 7 Jul 2024 21:16:47 +0530 Subject: [PATCH 26/29] Ran make lint Signed-off-by: Wise-Wizard --- pkg/telemetery/settings_test.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/telemetery/settings_test.go b/pkg/telemetery/settings_test.go index 38ae3c6a1ee..bb82b61e57d 100644 --- a/pkg/telemetery/settings_test.go +++ b/pkg/telemetery/settings_test.go @@ -6,11 +6,12 @@ package telemetery_test import ( "testing" - "github.com/jaegertracing/jaeger/pkg/healthcheck" - "github.com/jaegertracing/jaeger/pkg/telemetery" "github.com/stretchr/testify/assert" - "go.opentelemetry.io/collector/component" + + "github.com/jaegertracing/jaeger/pkg/healthcheck" + "github.com/jaegertracing/jaeger/pkg/telemetery" + "github.com/jaegertracing/jaeger/pkg/testutils" ) func TestHCAdapter(t *testing.T) { @@ -71,3 +72,7 @@ func TestHCAdapter(t *testing.T) { }) } } + +func TestMain(m *testing.M) { + testutils.VerifyGoLeaks(m) +} From 160663e368ee55a3e5118be931b785c8e589a523 Mon Sep 17 00:00:00 2001 From: Saransh Shankar <103821431+Wise-Wizard@users.noreply.github.com> Date: Tue, 9 Jul 2024 14:18:33 +0530 Subject: [PATCH 27/29] Update cmd/jaeger/internal/extension/jaegerquery/server.go Co-authored-by: Yuri Shkuro Signed-off-by: Saransh Shankar <103821431+Wise-Wizard@users.noreply.github.com> --- cmd/jaeger/internal/extension/jaegerquery/server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/jaeger/internal/extension/jaegerquery/server.go b/cmd/jaeger/internal/extension/jaegerquery/server.go index 697c57d7033..44a51449f41 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server.go @@ -138,7 +138,7 @@ func (s *server) Shutdown(ctx context.Context) error { if s.server != nil { errs = append(errs, s.server.Close()) } - if s.server.TracerProvider != nil { + if s.server.closeTracer != nil { errs = append(errs, s.closeTracer(ctx)) } return errors.Join(errs...) From 70d4b1010840a96a72f891bdab98bec8163e2e30 Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Tue, 9 Jul 2024 14:39:05 +0530 Subject: [PATCH 28/29] Fixed Error Signed-off-by: Wise-Wizard --- cmd/jaeger/internal/extension/jaegerquery/server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/jaeger/internal/extension/jaegerquery/server.go b/cmd/jaeger/internal/extension/jaegerquery/server.go index 44a51449f41..a512c8ed07f 100644 --- a/cmd/jaeger/internal/extension/jaegerquery/server.go +++ b/cmd/jaeger/internal/extension/jaegerquery/server.go @@ -138,7 +138,7 @@ func (s *server) Shutdown(ctx context.Context) error { if s.server != nil { errs = append(errs, s.server.Close()) } - if s.server.closeTracer != nil { + if s.closeTracer != nil { errs = append(errs, s.closeTracer(ctx)) } return errors.Join(errs...) From 25f8d1057120ef66fbdfa5e591d8c36ac77e3050 Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Wed, 10 Jul 2024 00:17:12 +0530 Subject: [PATCH 29/29] Fix nil pointer error Signed-off-by: Wise-Wizard --- cmd/query/app/server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/query/app/server.go b/cmd/query/app/server.go index 98b24df8a1f..6e5261beadc 100644 --- a/cmd/query/app/server.go +++ b/cmd/query/app/server.go @@ -366,7 +366,7 @@ func (s *Server) Close() error { s.cmuxServer.Close() } s.bgFinished.Wait() - s.ReportStatus(component.NewStatusEvent(component.StatusStopped)) + s.Logger.Info("Server stopped") return errors.Join(errs...) }