Debian Codegraph @

samplers/jaegerremote/internal/testutils/sampling_manager.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 // Copyright (c) 2021 The Jaeger Authors.
5 // Copyright (c) 2017 Uber Technologies, Inc.
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18
19 package testutils // import "go.opentelemetry.io/contrib/samplers/jaegerremote/internal/testutils"
20
21 import (
22 "sync"
23
24 jaeger_api_v2 "github.com/jaegertracing/jaeger-idl/proto-gen/api_v2"
25 )
26
27 func newSamplingManager() *samplingManager {
28 return &samplingManager{
29 sampling: make(map[string]any),
30 }
31 }
32
33 type samplingManager struct {
34 sampling map[string]any
35 mutex sync.Mutex
36 }
37
38 // GetSamplingStrategy implements handler method of sampling.SamplingManager.
39 func (s *samplingManager) GetSamplingStrategy(serviceName string) (any, error) {
40 s.mutex.Lock()
41 defer s.mutex.Unlock()
42 if strategy, ok := s.sampling[serviceName]; ok {
43 return strategy, nil
44 }
45 return &jaeger_api_v2.SamplingStrategyResponse{
46 StrategyType: jaeger_api_v2.SamplingStrategyType_PROBABILISTIC,
47 ProbabilisticSampling: &jaeger_api_v2.ProbabilisticSamplingStrategy{
48 SamplingRate: 0.01,
49 },
50 }, nil
51 }
52
53 // AddSamplingStrategy registers a sampling strategy for a service.
54 func (s *samplingManager) AddSamplingStrategy(service string, strategy any) {
55 s.mutex.Lock()
56 defer s.mutex.Unlock()
57 s.sampling[service] = strategy
58 }