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

Commit

Permalink
Throw exception on invalid sampling rate (fix #149) (#168)
Browse files Browse the repository at this point in the history
Signed-off-by: FR-MUREX-COM\mchaikhadouaihy <mehrez.douaihy@gmail.com>
  • Loading branch information
mdouaihy authored and yurishkuro committed Sep 5, 2019
1 parent fec4327 commit 2b5e4fb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/jaegertracing/samplers/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class Config {
oss << "Invalid parameter for probabilistic sampler: " << _param
<< ", expecting value between 0 and 1";
logger.error(oss.str());
throw std::invalid_argument("Probabilistic sampling rate should be in the interval [0, 1].");
return std::unique_ptr<Sampler>();
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/jaegertracing/samplers/SamplerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "jaegertracing/Constants.h"
#include "jaegertracing/Tag.h"
#include "jaegertracing/samplers/Config.h"
#include "jaegertracing/samplers/AdaptiveSampler.h"
#include "jaegertracing/samplers/ConstSampler.h"
#include "jaegertracing/samplers/GuaranteedThroughputProbabilisticSampler.h"
Expand Down Expand Up @@ -149,6 +150,26 @@ TEST(Sampler, testProbabilisticSamplerPerformance)
std::cout << "Sampled: " << count << " rate=" << rate << '\n';
}

TEST(Sampler, testProbabilisticSamplerInvalidRate)
{
Config samplerConfig1(kSamplerTypeProbabilistic,
1.1,
"",
0,
samplers::Config::Clock::duration());
Config samplerConfig2(kSamplerTypeProbabilistic,
-0.1,
"",
0,
samplers::Config::Clock::duration());
auto logger = logging::nullLogger();
auto metrics = metrics::Metrics::makeNullMetrics();
ASSERT_THROW(samplerConfig1.makeSampler("test-service", *logger, *metrics),
std::invalid_argument);
ASSERT_THROW(samplerConfig2.makeSampler("test-service", *logger, *metrics),
std::invalid_argument);
}

TEST(Sampler, testRateLimitingSampler)
{
{
Expand Down

0 comments on commit 2b5e4fb

Please sign in to comment.