2 * Copyright (c) 2017 Uber Technologies, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "jaegertracing/Config.h"
18 #include "jaegertracing/Constants.h"
19 #include "jaegertracing/propagation/HeadersConfig.h"
20 #include "jaegertracing/samplers/Config.h"
21 #include "jaegertracing/utils/YAML.h"
22 #include "jaegertracing/testutils/EnvVariable.h"
23 #include <gtest/gtest.h>
27 namespace jaegertracing
{
29 #ifdef JAEGERTRACING_WITH_YAML_CPP
31 TEST(Config
, testParse
)
34 constexpr auto kConfigYAML
= R
"cfg(
41 bufferFlushInterval: 10
43 localAgentHostPort: 127.0.0.1:6831
45 jaegerDebugHeader: debug-id
46 jaegerBaggageHeader: baggage
47 TraceContextHeaderName: trace-id
48 traceBaggageHeaderPrefix: "testctx
-"
50 denyBaggageOnInitializationFailure: false
51 hostPort: 127.0.0.1:5778
54 const auto config
= Config::parse(YAML::Load(kConfigYAML
));
55 ASSERT_EQ("probabilistic", config
.sampler().type());
56 ASSERT_EQ("debug-id", config
.headers().jaegerDebugHeader());
57 ASSERT_EQ("baggage", config
.headers().jaegerBaggageHeader());
58 ASSERT_EQ("trace-id", config
.headers().traceContextHeaderName());
59 ASSERT_EQ("testctx-", config
.headers().traceBaggageHeaderPrefix());
63 Config::parse(YAML::Load(R
"cfg(
68 baggage_restrictions: 4
73 TEST(Config
, testDefaultSamplingProbability
)
75 ASSERT_EQ(samplers::Config::kDefaultSamplingProbability
,
76 Config().sampler().param());
79 TEST(Config
, testDefaultSamplingServerURL
)
81 ASSERT_EQ("http://127.0.0.1:5778/sampling",
82 Config().sampler().samplingServerURL());
85 TEST(Config
, testZeroSamplingParam
)
88 constexpr auto kConfigYAML
= R
"cfg(
92 const auto config
= Config::parse(YAML::Load(kConfigYAML
));
93 ASSERT_EQ(0, config
.sampler().param());
97 #endif // JAEGERTRACING_WITH_YAML_CPP
99 TEST(Config
, testFromEnv
)
101 std::vector
<Tag
> tags
;
102 tags
.emplace_back("hostname", std::string("foo"));
103 tags
.emplace_back("my.app.version", std::string("1.2.3"));
106 samplers::Config("probabilistic",
108 "http://host34:57/sampling",
110 samplers::Config::Clock::duration()),
111 reporters::Config(10,
112 std::chrono::milliseconds(100),
115 "http://host36:56568"),
116 propagation::HeadersConfig(),
117 baggage::RestrictionsConfig(),
123 ASSERT_EQ(std::string("http://host36:56568"), config
.reporter().endpoint());
124 ASSERT_EQ(std::string("host35:77"), config
.reporter().localAgentHostPort());
126 ASSERT_EQ(10, config
.reporter().queueSize());
127 ASSERT_EQ(std::chrono::milliseconds(100),
128 config
.reporter().bufferFlushInterval());
129 ASSERT_EQ(false, config
.reporter().logSpans());
131 ASSERT_EQ(.7, config
.sampler().param());
132 ASSERT_EQ(std::string("probabilistic"), config
.sampler().type());
134 testutils::EnvVariable::setEnv("JAEGER_AGENT_HOST", "host33");
135 testutils::EnvVariable::setEnv("JAEGER_AGENT_PORT", "45");
136 testutils::EnvVariable::setEnv("JAEGER_ENDPOINT", "http://host34:56567");
138 testutils::EnvVariable::setEnv("JAEGER_REPORTER_MAX_QUEUE_SIZE", "33");
139 testutils::EnvVariable::setEnv("JAEGER_REPORTER_FLUSH_INTERVAL", "45");
140 testutils::EnvVariable::setEnv("JAEGER_REPORTER_LOG_SPANS", "true");
142 testutils::EnvVariable::setEnv("JAEGER_SAMPLER_TYPE", "remote");
143 testutils::EnvVariable::setEnv("JAEGER_SAMPLER_PARAM", "0.33");
144 testutils::EnvVariable::setEnv("JAEGER_SAMPLING_ENDPOINT", "http://myagent:1234");
146 testutils::EnvVariable::setEnv("JAEGER_SERVICE_NAME", "AService");
147 testutils::EnvVariable::setEnv("JAEGER_TAGS", "hostname=foobar,my.app.version=4.5.6");
151 ASSERT_EQ(std::string("http://host34:56567"), config
.reporter().endpoint());
152 ASSERT_EQ(std::string("host33:45"), config
.reporter().localAgentHostPort());
154 ASSERT_EQ(33, config
.reporter().queueSize());
155 ASSERT_EQ(std::chrono::milliseconds(45),
156 config
.reporter().bufferFlushInterval());
157 ASSERT_EQ(true, config
.reporter().logSpans());
159 ASSERT_EQ(std::string("remote"), config
.sampler().type());
160 ASSERT_EQ(0.33, config
.sampler().param());
161 ASSERT_EQ(std::string("http://myagent:1234"), config
.sampler().samplingServerURL());
163 ASSERT_EQ(std::string("AService"), config
.serviceName());
165 std::vector
<Tag
> expectedTags
;
166 expectedTags
.emplace_back("hostname", std::string("foo"));
167 expectedTags
.emplace_back("my.app.version", std::string("1.2.3"));
168 expectedTags
.emplace_back("hostname", std::string("foobar"));
169 expectedTags
.emplace_back("my.app.version", std::string("4.5.6"));
170 ASSERT_EQ(expectedTags
, config
.tags());
172 ASSERT_EQ(false, config
.disabled());
174 testutils::EnvVariable::setEnv("JAEGER_DISABLED", "TRue"); // case-insensitive
175 testutils::EnvVariable::setEnv("JAEGER_AGENT_PORT", "445");
178 ASSERT_EQ(true, config
.disabled());
179 ASSERT_EQ(std::string("host33:445"),
180 config
.reporter().localAgentHostPort());
182 testutils::EnvVariable::setEnv("JAEGER_AGENT_HOST", "");
183 testutils::EnvVariable::setEnv("JAEGER_AGENT_PORT", "");
184 testutils::EnvVariable::setEnv("JAEGER_ENDPOINT", "");
185 testutils::EnvVariable::setEnv("JAEGER_REPORTER_MAX_QUEUE_SIZE", "");
186 testutils::EnvVariable::setEnv("JAEGER_REPORTER_FLUSH_INTERVAL", "");
187 testutils::EnvVariable::setEnv("JAEGER_REPORTER_LOG_SPANS", "");
188 testutils::EnvVariable::setEnv("JAEGER_SAMPLER_PARAM", "");
189 testutils::EnvVariable::setEnv("JAEGER_SAMPLER_TYPE", "");
190 testutils::EnvVariable::setEnv("JAEGER_SERVICE_NAME", "");
191 testutils::EnvVariable::setEnv("JAEGER_TAGS", "");
192 testutils::EnvVariable::setEnv("JAEGER_DISABLED", "");
195 } // namespace jaegertracing