Skip to content

Commit

Permalink
[refactor] Move sampling grpc handler to internal/sampling/grpc (#6540)
Browse files Browse the repository at this point in the history
## 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 <[email protected]>
  • Loading branch information
ary82 authored Jan 13, 2025
1 parent 2e9ea52 commit fcc8936
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions cmd/collector/app/server/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmd/jaeger/internal/extension/remotesampling/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2018 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package sampling
package grpc

import (
"context"
Expand All @@ -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())
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2018 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package sampling
package grpc

import (
"errors"
Expand Down Expand Up @@ -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 != "" {
Expand Down

0 comments on commit fcc8936

Please sign in to comment.