This repository was archived by the owner on Jul 11, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +24
-11
lines changed
Expand file tree Collapse file tree 4 files changed +24
-11
lines changed Original file line number Diff line number Diff line change 2828default_logger = logging .getLogger ('jaeger_tracing' )
2929
3030
31- class RemoteThrottler (object ):
31+ class Throttler (object ):
32+ def set_client_id (self , client_id : int ) -> None :
33+ """
34+ Called by tracer to set client ID of throttler.
35+ """
36+ pass
37+
38+ def is_allowed (self , operation : str ) -> bool :
39+ raise NotImplementedError ()
40+
41+ def close (self ) -> None :
42+ pass
43+
44+
45+ class RemoteThrottler (Throttler ):
3246 """
3347 RemoteThrottler controls the flow of spans emitted from client to prevent
3448 flooding. RemoteThrottler requests credits from the throttling service
@@ -78,10 +92,7 @@ def is_allowed(self, operation):
7892 self .credits [operation ] = value - MINIMUM_CREDITS
7993 return True
8094
81- def _set_client_id (self , client_id ):
82- """
83- Method for tracer to set client ID of throttler.
84- """
95+ def set_client_id (self , client_id ):
8596 with self .lock :
8697 if self .client_id is None :
8798 self .client_id = client_id
Original file line number Diff line number Diff line change 3939from .utils import local_ip
4040from .sampler import Sampler
4141from .reporter import BaseReporter
42+ from .throttler import Throttler
4243
4344logger = logging .getLogger ('jaeger_tracing' )
4445
@@ -63,7 +64,7 @@ def __init__(
6364 tags : Optional [Dict [str , Any ]] = None ,
6465 max_tag_value_length : int = constants .MAX_TAG_VALUE_LENGTH ,
6566 max_traceback_length : int = constants .MAX_TRACEBACK_LENGTH ,
66- throttler : Optional [Any ] = None ,
67+ throttler : Optional [Throttler ] = None ,
6768 scope_manager : Optional [ScopeManager ] = None ,
6869 ) -> None :
6970 self .service_name = service_name
@@ -115,7 +116,7 @@ def __init__(
115116 self .throttler = throttler
116117 if self .throttler :
117118 client_id = random .randint (0 , sys .maxsize )
118- self .throttler ._set_client_id (client_id )
119+ self .throttler .set_client_id (client_id )
119120 self .tags [constants .CLIENT_UUID_TAG_KEY ] = client_id
120121
121122 self .reporter .set_process (
Original file line number Diff line number Diff line change 2424from jaeger_client .config import DEFAULT_THROTTLER_PORT
2525from jaeger_client .metrics import MetricsFactory
2626from jaeger_client .reporter import NullReporter
27- from tests .test_utils import TestSampler
27+ from tests .test_utils import MockSampler
2828
2929
3030class ConfigTests (unittest .TestCase ):
@@ -85,7 +85,7 @@ def test_bad_sampler(self):
8585 c .sampler .is_sampled (0 )
8686
8787 def test_object_sampler_sampler (self ):
88- sampler = TestSampler ()
88+ sampler = MockSampler ()
8989 c = Config ({'sampler' : sampler }, service_name = 'x' )
9090 assert c .sampler is sampler
9191
Original file line number Diff line number Diff line change @@ -84,5 +84,6 @@ def test_get_local_ip_by_socket_does_not_blow_up():
8484 jaeger_client .utils .get_local_ip_by_socket ()
8585
8686
87- class TestSampler (Sampler ):
88- pass
87+ class MockSampler (Sampler ):
88+ def __init__ (self ):
89+ pass
You can’t perform that action at this time.
0 commit comments