Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Allow manually configured Sampler In Jaeger Config (#324)
Browse files Browse the repository at this point in the history
* In Jaeger Config, enable to add directly a sampler

It can be useful when using a specific sampler that is not included in
this library

Signed-off-by: Etienne CARRIERE <[email protected]>

* Fix tests

Signed-off-by: Etienne CARRIERE <[email protected]>

* PEP-8

Signed-off-by: Etienne CARRIERE <[email protected]>

* Come back to `sampler_config`

Signed-off-by: Etienne Carriere <[email protected]>
  • Loading branch information
Etienne-Carriere authored Sep 3, 2021
1 parent 948b37e commit abf7a25
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
4 changes: 3 additions & 1 deletion jaeger_client/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
ProbabilisticSampler,
RateLimitingSampler,
RemoteControlledSampler,
)
Sampler)
from .constants import (
DEFAULT_SAMPLING_INTERVAL,
DEFAULT_FLUSH_INTERVAL,
Expand Down Expand Up @@ -220,6 +220,8 @@ def max_traceback_length(self):
@property
def sampler(self):
sampler_config = self.config.get('sampler', {})
if isinstance(sampler_config, Sampler):
return sampler_config
sampler_type = sampler_config.get('type', None)
sampler_param = sampler_config.get('param', None)
if not sampler_type:
Expand Down
11 changes: 10 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@
# limitations under the License.

from __future__ import absolute_import

import os
import unittest

import opentracing.tracer

from jaeger_client import Config, ConstSampler, ProbabilisticSampler, RateLimitingSampler
from jaeger_client import constants
from jaeger_client.config import DEFAULT_THROTTLER_PORT
from jaeger_client.metrics import MetricsFactory
from jaeger_client.reporter import NullReporter
from jaeger_client import constants
from tests.test_utils import TestSampler


class ConfigTests(unittest.TestCase):
Expand Down Expand Up @@ -80,6 +84,11 @@ def test_bad_sampler(self):
with self.assertRaises(ValueError):
c.sampler.is_sampled(0)

def test_object_sampler_sampler(self):
sampler = TestSampler()
c = Config({'sampler': sampler}, service_name='x')
assert c.sampler is sampler

def test_agent_reporting_host(self):
c = Config({}, service_name='x')
assert c.local_agent_reporting_host == 'localhost'
Expand Down
13 changes: 9 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import unittest

from jaeger_client import utils
from jaeger_client.sampler import Sampler


class ConfigTests(unittest.TestCase):
Expand All @@ -43,10 +44,10 @@ def test_get_unknown_boolean(self):
def test_get_None_boolean(self):
self.check_boolean(None, 'qwer', False)

# def test_error_reporter_doesnt_send_metrics_if_not_configured(self):
# er = utils.ErrorReporter(False)
# er.error('foo', 1)
# assert not mock_metrics.count.called
# def test_error_reporter_doesnt_send_metrics_if_not_configured(self):
# er = utils.ErrorReporter(False)
# er.error('foo', 1)
# assert not mock_metrics.count.called

def test_error_reporter_sends_metrics_if_configured(self):
mock_metrics = mock.MagicMock()
Expand Down Expand Up @@ -81,3 +82,7 @@ def test_local_ip_does_not_blow_up():
def test_get_local_ip_by_socket_does_not_blow_up():
import jaeger_client.utils
jaeger_client.utils.get_local_ip_by_socket()


class TestSampler(Sampler):
pass

0 comments on commit abf7a25

Please sign in to comment.