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

Commit 9e1b39c

Browse files
author
Emmanuel Courreges
authored
Fix loading of sampling endpoint address from JAEGER_SAMPLING_ENDPOINT environment variable (#200)
* fix configuration from environment variables fix conversion to double of JAEGER_SAMPLER_PARAM rename env var JAEGER_SAMPLER_MANAGER_HOST_PORT to JAEGER_SAMPLER_SERVER_URL properly load JAEGER_SAMPLER_SERVER_URL Signed-off-by: CI-Bot for Emmanuel Courreges <[email protected]> * proper unit testing of RemotelyControlledSampler Signed-off-by: CI-Bot for Emmanuel Courreges <[email protected]> * include /sampling in all samplingServerURL examples to avoid confusion / or /whatever does not work for this driver: the agent answers slightly differently with a numerical strategyType Signed-off-by: CI-Bot for Emmanuel Courreges <[email protected]> * rename JAEGER_SAMPLER_MANAGER_HOST_PORT into JAEGER_SAMPLING_ENDPOINT as per jaegertracing/jaeger#1971 (comment) Signed-off-by: CI-Bot for Emmanuel Courreges <[email protected]>
1 parent 49568d4 commit 9e1b39c

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ JAEGER_REPORTER_LOG_SPANS | Whether the reporter should also log the spans
103103
JAEGER_REPORTER_MAX_QUEUE_SIZE | The reporter's maximum queue size
104104
JAEGER_REPORTER_FLUSH_INTERVAL | The reporter's flush interval (ms)
105105
JAEGER_SAMPLER_TYPE | The [sampler type](https://www.jaegertracing.io/docs/latest/sampling/#client-sampling-configuration)
106-
JAEGER_SAMPLER_PARAM | The sampler parameter (number)
107-
JAEGER_SAMPLER_MANAGER_HOST_PORT | The host name and port when using the remote controlled sampler
106+
JAEGER_SAMPLER_PARAM | The sampler parameter (double)
107+
JAEGER_SAMPLING_ENDPOINT | The url for the remote sampling conf when using sampler type remote. Default is http://127.0.0.1:5778/sampling
108108
JAEGER_TAGS | A comma separated list of `name = value` tracer level tags, which get added to all reported spans. The value can also refer to an environment variable using the format `${envVarName:default}`, where the `:default` is optional, and identifies a value to be used if the environment variable cannot be found
109109

110110
## License

src/jaegertracing/ConfigTest.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ TEST(Config, testFromEnv)
147147
setEnv("JAEGER_REPORTER_FLUSH_INTERVAL", "45");
148148
setEnv("JAEGER_REPORTER_LOG_SPANS", "true");
149149

150-
setEnv("JAEGER_SAMPLER_PARAM", "33");
151-
setEnv("JAEGER_SAMPLER_TYPE", "const");
150+
setEnv("JAEGER_SAMPLER_TYPE", "remote");
151+
setEnv("JAEGER_SAMPLER_PARAM", "0.33");
152+
setEnv("JAEGER_SAMPLING_ENDPOINT", "http://myagent:1234");
152153

153154
setEnv("JAEGER_SERVICE_NAME", "AService");
154155
setEnv("JAEGER_TAGS", "hostname=foobar,my.app.version=4.5.6");
@@ -163,8 +164,9 @@ TEST(Config, testFromEnv)
163164
config.reporter().bufferFlushInterval());
164165
ASSERT_EQ(true, config.reporter().logSpans());
165166

166-
ASSERT_EQ(33., config.sampler().param());
167-
ASSERT_EQ(std::string("const"), config.sampler().type());
167+
ASSERT_EQ(std::string("remote"), config.sampler().type());
168+
ASSERT_EQ(0.33, config.sampler().param());
169+
ASSERT_EQ(std::string("http://myagent:1234"), config.sampler().samplingServerURL());
168170

169171
ASSERT_EQ(std::string("AService"), config.serviceName());
170172

src/jaegertracing/samplers/Config.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@ void Config::fromEnv()
3636
const auto param = utils::EnvVariable::getStringVariable(kJAEGER_SAMPLER_PARAM_ENV_PROP);
3737
if (!param.empty()) {
3838
std::istringstream iss(param);
39-
int paramVal = 0;
39+
double paramVal = 0;
4040
if (iss >> paramVal) {
4141
_param = paramVal;
4242
}
4343
}
44+
const auto samplingServerURL = utils::EnvVariable::getStringVariable(kJAEGER_SAMPLING_ENDPOINT_ENV_PROP);
45+
if (!samplingServerURL.empty()) {
46+
_samplingServerURL = samplingServerURL;
47+
}
4448
}
4549

4650
} // namespace samplers

src/jaegertracing/samplers/Config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Config {
4747

4848
static constexpr auto kJAEGER_SAMPLER_TYPE_ENV_PROP = "JAEGER_SAMPLER_TYPE";
4949
static constexpr auto kJAEGER_SAMPLER_PARAM_ENV_PROP = "JAEGER_SAMPLER_PARAM";
50-
static constexpr auto kJAEGER_SAMPLER_MANAGER_HOST_PORT_ENV_PROP = "JAEGER_SAMPLER_MANAGER_HOST_PORT";
50+
static constexpr auto kJAEGER_SAMPLING_ENDPOINT_ENV_PROP = "JAEGER_SAMPLING_ENDPOINT";
5151

5252
static Clock::duration defaultSamplingRefreshInterval()
5353
{

src/jaegertracing/samplers/SamplerTest.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,17 @@ TEST(Sampler, testRemotelyControlledSampler)
331331
mockAgent->start();
332332
const auto logger = logging::nullLogger();
333333
const auto metrics = metrics::Metrics::makeNullMetrics();
334+
335+
// Make sure remote sampling probability is 1
336+
sampling_manager::thrift::SamplingStrategyResponse config;
337+
config.__set_strategyType(
338+
sampling_manager::thrift::SamplingStrategyType::PROBABILISTIC);
339+
sampling_manager::thrift::ProbabilisticSamplingStrategy probaStrategy;
340+
probaStrategy.__set_samplingRate(1.0);
341+
config.__set_probabilisticSampling(probaStrategy);
342+
mockAgent->addSamplingStrategy("test-service", config);
343+
344+
// Default probability of 0.5, switches to 1 when downloaded
334345
RemotelyControlledSampler sampler(
335346
"test-service",
336347
"http://" + mockAgent->samplingServerAddress().authority(),
@@ -339,6 +350,9 @@ TEST(Sampler, testRemotelyControlledSampler)
339350
std::chrono::milliseconds(100),
340351
*logger,
341352
*metrics);
353+
354+
// Wait a bit for remote config download to be done
355+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
342356
std::random_device device;
343357
std::mt19937_64 rng;
344358
rng.seed(device());
@@ -347,7 +361,8 @@ TEST(Sampler, testRemotelyControlledSampler)
347361
RemotelyControlledSampler::Clock::now() - startTime)
348362
.count() < 1;) {
349363
TraceID traceID(rng(), rng());
350-
sampler.isSampled(traceID, kTestOperationName);
364+
// If probability was 0.5 we could reasonnably assume one of 50 samples fail
365+
ASSERT_TRUE(sampler.isSampled(traceID, kTestOperationName).isSampled());
351366
std::this_thread::sleep_for(std::chrono::milliseconds(20));
352367
}
353368
sampler.close();

0 commit comments

Comments
 (0)