Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[extension/jaegerremotesampling] remove jaeger sampling dependency #36977

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
41 changes: 41 additions & 0 deletions extension/jaegerremotesampling/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) 2018 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package jaegerremotesampling

import (
"github.com/jaegertracing/jaeger/proto-gen/api_v2"
)

const (
// samplerTypeProbabilistic is the type of sampler that samples traces
// with a certain fixed probability.
samplerTypeProbabilistic = "probabilistic"

// samplerTypeRateLimiting is the type of sampler that samples
// only up to a fixed number of traces per second.
samplerTypeRateLimiting = "ratelimiting"

// defaultSamplingProbability is the default sampling probability the
// Strategy Store will use if none is provided.
defaultSamplingProbability = 0.001
)

// defaultStrategy is the default sampling strategy the Strategy Store will return
// if none is provided.
func defaultStrategyResponse() *api_v2.SamplingStrategyResponse {
return &api_v2.SamplingStrategyResponse{
StrategyType: api_v2.SamplingStrategyType_PROBABILISTIC,
ProbabilisticSampling: &api_v2.ProbabilisticSamplingStrategy{
SamplingRate: defaultSamplingProbability,
},
}
}

func defaultStrategies() *storedStrategies {
s := &storedStrategies{
serviceStrategies: make(map[string]*api_v2.SamplingStrategyResponse),
}
s.defaultStrategy = defaultStrategyResponse()
return s
}
8 changes: 3 additions & 5 deletions extension/jaegerremotesampling/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"context"
"fmt"

"github.com/jaegertracing/jaeger/cmd/collector/app/sampling/samplingstrategy"
"github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider/static"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/extension"
"go.uber.org/zap"
Expand All @@ -24,7 +22,7 @@ type jrsExtension struct {

httpServer component.Component
grpcServer component.Component
samplingStore samplingstrategy.Provider
samplingStore internal.Provider

closers []func() error
}
Expand All @@ -44,11 +42,11 @@ func (jrse *jrsExtension) Start(ctx context.Context, host component.Host) error
// - local file
// we can then use a simplified logic here to assign the appropriate store
if jrse.cfg.Source.File != "" {
opts := static.Options{
opts := Options{
StrategiesFile: jrse.cfg.Source.File,
ReloadInterval: jrse.cfg.Source.ReloadInterval,
}
ss, err := static.NewProvider(opts, jrse.telemetry.Logger)
ss, err := NewProvider(opts, jrse.telemetry.Logger)
if err != nil {
return fmt.Errorf("failed to create the local file strategy store: %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
"probabilisticSampling": {
"samplingRate": 1
},
"operationSampling": {
"defaultSamplingProbability": 1,
"perOperationStrategies": [
{
"operation": "/health",
"probabilisticSampling": {
"samplingRate": 0.1
}
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"strategyType": 1,
"rateLimitingSampling": {
"maxTracesPerSecond": 3
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"probabilisticSampling": {
"samplingRate": 1
},
"operationSampling": {
"defaultSamplingProbability": 1,
"perOperationStrategies": [
{
"operation": "/health",
"probabilisticSampling": {
"samplingRate": 0.1
}
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"strategyType": 1,
"rateLimitingSampling": {
"maxTracesPerSecond": 3
},
"operationSampling": {
"defaultSamplingProbability": 0.2,
"perOperationStrategies": [
{
"operation": "/health",
"probabilisticSampling": {
"samplingRate": 0.1
}
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"nonsense"
33 changes: 33 additions & 0 deletions extension/jaegerremotesampling/fixtures/missing-service-types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"default_strategy": {
"type": "probabilistic",
"param": 0.5
},
"service_strategies": [
{
"service": "foo",
"operation_strategies": [
{
"operation": "op1",
"type": "probabilistic",
"param": 0.2
}
]
},
{
"service": "bar",
"operation_strategies": [
{
"operation": "op3",
"type": "probabilistic",
"param": 0.3
},
{
"operation": "op5",
"type": "probabilistic",
"param": 0.4
}
]
}
]
}
74 changes: 74 additions & 0 deletions extension/jaegerremotesampling/fixtures/operation_strategies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"default_strategy": {
"type": "probabilistic",
"param": 0.5,
"operation_strategies": [
{
"operation": "op0",
"type": "probabilistic",
"param": 0.2
},
{
"operation": "op6",
"type": "probabilistic",
"param": 0
},
{
"operation": "spam",
"type": "ratelimiting",
"param": 1
},
{
"operation": "op7",
"type": "probabilistic",
"param": 1
}
]
},
"service_strategies": [
{
"service": "foo",
"type": "probabilistic",
"param": 0.8,
"operation_strategies": [
{
"operation": "op6",
"type": "probabilistic",
"param": 0.5
},
{
"operation": "op1",
"type": "probabilistic",
"param": 0.2
},
{
"operation": "op2",
"type": "ratelimiting",
"param": 10
}
]
},
{
"service": "bar",
"type": "ratelimiting",
"param": 5,
"operation_strategies": [
{
"operation": "op3",
"type": "probabilistic",
"param": 0.3
},
{
"operation": "op4",
"type": "ratelimiting",
"param": 100
},
{
"operation": "op5",
"type": "probabilistic",
"param": 0.4
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"service_strategies": [
{
"service": "ServiceA",
"type": "probabilistic",
"param": 1.0
},
{
"service": "ServiceB",
"type": "ratelimiting",
"param": 3
}
],
"default_strategy": {
"type": "probabilistic",
"param": 0.2,
"operation_strategies": [
{
"operation": "/health",
"type": "probabilistic",
"param": 0.1
}
]
}
}
18 changes: 18 additions & 0 deletions extension/jaegerremotesampling/fixtures/strategies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"default_strategy": {
"type": "probabilistic",
"param": 0.5
},
"service_strategies": [
{
"service": "foo",
"type": "probabilistic",
"param": 0.8
},
{
"service": "bar",
"type": "ratelimiting",
"param": 5
}
]
}
8 changes: 3 additions & 5 deletions extension/jaegerremotesampling/internal/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"fmt"
"net"

"github.com/jaegertracing/jaeger/cmd/collector/app/sampling"
"github.com/jaegertracing/jaeger/cmd/collector/app/sampling/samplingstrategy"
"github.com/jaegertracing/jaeger/proto-gen/api_v2"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configgrpc"
Expand All @@ -34,7 +32,7 @@ type grpcServer interface {
func NewGRPC(
telemetry component.TelemetrySettings,
settings configgrpc.ServerConfig,
strategyStore samplingstrategy.Provider,
strategyStore Provider,
) (*SamplingGRPCServer, error) {
if strategyStore == nil {
return nil, errMissingStrategyStore
Expand All @@ -51,7 +49,7 @@ func NewGRPC(
type SamplingGRPCServer struct {
telemetry component.TelemetrySettings
settings configgrpc.ServerConfig
strategyStore samplingstrategy.Provider
strategyStore Provider

grpcServer grpcServer
}
Expand All @@ -64,7 +62,7 @@ func (s *SamplingGRPCServer) Start(ctx context.Context, host component.Host) err
reflection.Register(server)
s.grpcServer = server

api_v2.RegisterSamplingManagerServer(server, sampling.NewGRPCHandler(s.strategyStore))
api_v2.RegisterSamplingManagerServer(server, NewGRPCHandler(s.strategyStore))

healthServer := health.NewServer()
healthServer.SetServingStatus("jaeger.api_v2.SamplingManager", grpc_health_v1.HealthCheckResponse_SERVING)
Expand Down
27 changes: 27 additions & 0 deletions extension/jaegerremotesampling/internal/grpc_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2018 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package internal

import (
"context"

"github.com/jaegertracing/jaeger/proto-gen/api_v2"
)

// GRPCHandler is sampling strategy handler for gRPC.
type GRPCHandler struct {
samplingProvider Provider
}

// NewGRPCHandler creates a handler that controls sampling strategies for services.
func NewGRPCHandler(provider Provider) GRPCHandler {
return GRPCHandler{
samplingProvider: provider,
}
}

// GetSamplingStrategy returns sampling decision from store.
func (s GRPCHandler) GetSamplingStrategy(ctx context.Context, param *api_v2.SamplingStrategyParameters) (*api_v2.SamplingStrategyResponse, error) {
return s.samplingProvider.GetSamplingStrategy(ctx, param.GetServiceName())
}
Loading