Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.

Commit 2b5e4fb

Browse files
mdouaihyyurishkuro
authored andcommitted
Throw exception on invalid sampling rate (fix #149) (#168)
Signed-off-by: FR-MUREX-COM\mchaikhadouaihy <[email protected]>
1 parent fec4327 commit 2b5e4fb

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/jaegertracing/samplers/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class Config {
122122
oss << "Invalid parameter for probabilistic sampler: " << _param
123123
<< ", expecting value between 0 and 1";
124124
logger.error(oss.str());
125+
throw std::invalid_argument("Probabilistic sampling rate should be in the interval [0, 1].");
125126
return std::unique_ptr<Sampler>();
126127
}
127128
}

src/jaegertracing/samplers/SamplerTest.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "jaegertracing/Constants.h"
2222
#include "jaegertracing/Tag.h"
23+
#include "jaegertracing/samplers/Config.h"
2324
#include "jaegertracing/samplers/AdaptiveSampler.h"
2425
#include "jaegertracing/samplers/ConstSampler.h"
2526
#include "jaegertracing/samplers/GuaranteedThroughputProbabilisticSampler.h"
@@ -149,6 +150,26 @@ TEST(Sampler, testProbabilisticSamplerPerformance)
149150
std::cout << "Sampled: " << count << " rate=" << rate << '\n';
150151
}
151152

153+
TEST(Sampler, testProbabilisticSamplerInvalidRate)
154+
{
155+
Config samplerConfig1(kSamplerTypeProbabilistic,
156+
1.1,
157+
"",
158+
0,
159+
samplers::Config::Clock::duration());
160+
Config samplerConfig2(kSamplerTypeProbabilistic,
161+
-0.1,
162+
"",
163+
0,
164+
samplers::Config::Clock::duration());
165+
auto logger = logging::nullLogger();
166+
auto metrics = metrics::Metrics::makeNullMetrics();
167+
ASSERT_THROW(samplerConfig1.makeSampler("test-service", *logger, *metrics),
168+
std::invalid_argument);
169+
ASSERT_THROW(samplerConfig2.makeSampler("test-service", *logger, *metrics),
170+
std::invalid_argument);
171+
}
172+
152173
TEST(Sampler, testRateLimitingSampler)
153174
{
154175
{

0 commit comments

Comments
 (0)