From fcc8936e6e567e6450ea581ab5d011be931a9f58 Mon Sep 17 00:00:00 2001 From: Aryan Goyal <137564277+ary82@users.noreply.github.com> Date: Mon, 13 Jan 2025 23:08:01 +0530 Subject: [PATCH] [refactor] Move sampling grpc handler to internal/sampling/grpc (#6540) ## Which problem is this PR solving? - Towards #6411 ## Description of the changes - Move sampling grpc handler from cmd/collector/app/sampling to internal/sampling/grpc ## How was this change tested? - Covered by existing ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [ ] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `npm run lint` and `npm run test` Signed-off-by: Aryan Goyal <137564277+ary82@users.noreply.github.com> --- cmd/collector/app/server/grpc.go | 4 ++-- .../internal/extension/remotesampling/extension.go | 4 ++-- .../sampling/grpc}/grpc_handler.go | 14 +++++++------- .../sampling/grpc}/grpc_handler_test.go | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) rename {cmd/collector/app/sampling => internal/sampling/grpc}/grpc_handler.go (52%) rename {cmd/collector/app/sampling => internal/sampling/grpc}/grpc_handler_test.go (96%) diff --git a/cmd/collector/app/server/grpc.go b/cmd/collector/app/server/grpc.go index dbdedce6f26..8e10e78bf6d 100644 --- a/cmd/collector/app/server/grpc.go +++ b/cmd/collector/app/server/grpc.go @@ -17,8 +17,8 @@ import ( "google.golang.org/grpc/reflection" "github.com/jaegertracing/jaeger/cmd/collector/app/handler" - "github.com/jaegertracing/jaeger/cmd/collector/app/sampling" "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/samplingstrategy" + samplinggrpc "github.com/jaegertracing/jaeger/internal/sampling/grpc" "github.com/jaegertracing/jaeger/pkg/telemetry" "github.com/jaegertracing/jaeger/proto-gen/api_v2" ) @@ -65,7 +65,7 @@ func serveGRPC(server *grpc.Server, listener net.Listener, params *GRPCServerPar healthServer := health.NewServer() api_v2.RegisterCollectorServiceServer(server, params.Handler) - api_v2.RegisterSamplingManagerServer(server, sampling.NewGRPCHandler(params.SamplingProvider)) + api_v2.RegisterSamplingManagerServer(server, samplinggrpc.NewHandler(params.SamplingProvider)) healthServer.SetServingStatus("jaeger.api_v2.CollectorService", grpc_health_v1.HealthCheckResponse_SERVING) healthServer.SetServingStatus("jaeger.api_v2.SamplingManager", grpc_health_v1.HealthCheckResponse_SERVING) diff --git a/cmd/jaeger/internal/extension/remotesampling/extension.go b/cmd/jaeger/internal/extension/remotesampling/extension.go index f7a9deb7980..45624fce260 100644 --- a/cmd/jaeger/internal/extension/remotesampling/extension.go +++ b/cmd/jaeger/internal/extension/remotesampling/extension.go @@ -19,10 +19,10 @@ import ( "google.golang.org/grpc/health" "google.golang.org/grpc/health/grpc_health_v1" - "github.com/jaegertracing/jaeger/cmd/collector/app/sampling" "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/samplingstrategy" "github.com/jaegertracing/jaeger/cmd/jaeger/internal/extension/jaegerstorage" "github.com/jaegertracing/jaeger/internal/metrics/otelmetrics" + samplinggrpc "github.com/jaegertracing/jaeger/internal/sampling/grpc" "github.com/jaegertracing/jaeger/pkg/clientcfg/clientcfghttp" "github.com/jaegertracing/jaeger/pkg/metrics" "github.com/jaegertracing/jaeger/plugin/sampling/leaderelection" @@ -276,7 +276,7 @@ func (ext *rsExtension) startGRPCServer(ctx context.Context, host component.Host return err } - api_v2.RegisterSamplingManagerServer(ext.grpcServer, sampling.NewGRPCHandler(ext.strategyProvider)) + api_v2.RegisterSamplingManagerServer(ext.grpcServer, samplinggrpc.NewHandler(ext.strategyProvider)) healthServer := health.NewServer() // support health checks on the gRPC server healthServer.SetServingStatus("jaeger.api_v2.SamplingManager", grpc_health_v1.HealthCheckResponse_SERVING) diff --git a/cmd/collector/app/sampling/grpc_handler.go b/internal/sampling/grpc/grpc_handler.go similarity index 52% rename from cmd/collector/app/sampling/grpc_handler.go rename to internal/sampling/grpc/grpc_handler.go index fbb4c5a3e4c..be6cc64260f 100644 --- a/cmd/collector/app/sampling/grpc_handler.go +++ b/internal/sampling/grpc/grpc_handler.go @@ -1,7 +1,7 @@ // Copyright (c) 2018 The Jaeger Authors. // SPDX-License-Identifier: Apache-2.0 -package sampling +package grpc import ( "context" @@ -10,19 +10,19 @@ import ( "github.com/jaegertracing/jaeger/proto-gen/api_v2" ) -// GRPCHandler is sampling strategy handler for gRPC. -type GRPCHandler struct { +// Handler is sampling strategy handler for gRPC. +type Handler struct { samplingProvider samplingstrategy.Provider } -// NewGRPCHandler creates a handler that controls sampling strategies for services. -func NewGRPCHandler(provider samplingstrategy.Provider) GRPCHandler { - return GRPCHandler{ +// NewHandler creates a handler that controls sampling strategies for services. +func NewHandler(provider samplingstrategy.Provider) Handler { + return Handler{ samplingProvider: provider, } } // GetSamplingStrategy returns sampling decision from store. -func (s GRPCHandler) GetSamplingStrategy(ctx context.Context, param *api_v2.SamplingStrategyParameters) (*api_v2.SamplingStrategyResponse, error) { +func (s Handler) GetSamplingStrategy(ctx context.Context, param *api_v2.SamplingStrategyParameters) (*api_v2.SamplingStrategyResponse, error) { return s.samplingProvider.GetSamplingStrategy(ctx, param.GetServiceName()) } diff --git a/cmd/collector/app/sampling/grpc_handler_test.go b/internal/sampling/grpc/grpc_handler_test.go similarity index 96% rename from cmd/collector/app/sampling/grpc_handler_test.go rename to internal/sampling/grpc/grpc_handler_test.go index 450a1816b3d..f2148a6104b 100644 --- a/cmd/collector/app/sampling/grpc_handler_test.go +++ b/internal/sampling/grpc/grpc_handler_test.go @@ -1,7 +1,7 @@ // Copyright (c) 2018 The Jaeger Authors. // SPDX-License-Identifier: Apache-2.0 -package sampling +package grpc import ( "errors" @@ -40,7 +40,7 @@ func TestNewGRPCHandler(t *testing.T) { {req: &api_v2.SamplingStrategyParameters{ServiceName: "nil"}, resp: nil}, {req: &api_v2.SamplingStrategyParameters{ServiceName: "foo"}, resp: &api_v2.SamplingStrategyResponse{StrategyType: api_v2.SamplingStrategyType_PROBABILISTIC}}, } - h := NewGRPCHandler(mockSamplingStore{}) + h := NewHandler(mockSamplingStore{}) for _, test := range tests { resp, err := h.GetSamplingStrategy(context.Background(), test.req) if test.err != "" {