]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/jaeger-client-cpp/src/jaegertracing/ConfigTest.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / jaegertracing / jaeger-client-cpp / src / jaegertracing / ConfigTest.cpp
1 /*
2 * Copyright (c) 2017 Uber Technologies, Inc.
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
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>
24
25 #include <cstdlib>
26
27 namespace jaegertracing {
28
29 #ifdef JAEGERTRACING_WITH_YAML_CPP
30
31 TEST(Config, testParse)
32 {
33 {
34 constexpr auto kConfigYAML = R"cfg(
35 disabled: true
36 sampler:
37 type: probabilistic
38 param: 0.001
39 reporter:
40 queueSize: 100
41 bufferFlushInterval: 10
42 logSpans: false
43 localAgentHostPort: 127.0.0.1:6831
44 headers:
45 jaegerDebugHeader: debug-id
46 jaegerBaggageHeader: baggage
47 TraceContextHeaderName: trace-id
48 traceBaggageHeaderPrefix: "testctx-"
49 baggage_restrictions:
50 denyBaggageOnInitializationFailure: false
51 hostPort: 127.0.0.1:5778
52 refreshInterval: 60
53 )cfg";
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());
60 }
61
62 {
63 Config::parse(YAML::Load(R"cfg(
64 disabled: false
65 sampler: 1
66 reporter: 2
67 headers: 3
68 baggage_restrictions: 4
69 )cfg"));
70 }
71 }
72
73 TEST(Config, testDefaultSamplingProbability)
74 {
75 ASSERT_EQ(samplers::Config::kDefaultSamplingProbability,
76 Config().sampler().param());
77 }
78
79 TEST(Config, testDefaultSamplingServerURL)
80 {
81 ASSERT_EQ("http://127.0.0.1:5778/sampling",
82 Config().sampler().samplingServerURL());
83 }
84
85 TEST(Config, testZeroSamplingParam)
86 {
87 {
88 constexpr auto kConfigYAML = R"cfg(
89 sampler:
90 param: 0
91 )cfg";
92 const auto config = Config::parse(YAML::Load(kConfigYAML));
93 ASSERT_EQ(0, config.sampler().param());
94 }
95 }
96
97 #endif // JAEGERTRACING_WITH_YAML_CPP
98
99 TEST(Config, testFromEnv)
100 {
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"));
104
105 Config config(false,
106 samplers::Config("probabilistic",
107 0.7,
108 "http://host34:57/sampling",
109 0,
110 samplers::Config::Clock::duration()),
111 reporters::Config(10,
112 std::chrono::milliseconds(100),
113 false,
114 "host35:77",
115 "http://host36:56568"),
116 propagation::HeadersConfig(),
117 baggage::RestrictionsConfig(),
118 "test-service",
119 tags);
120
121 config.fromEnv();
122
123 ASSERT_EQ(std::string("http://host36:56568"), config.reporter().endpoint());
124 ASSERT_EQ(std::string("host35:77"), config.reporter().localAgentHostPort());
125
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());
130
131 ASSERT_EQ(.7, config.sampler().param());
132 ASSERT_EQ(std::string("probabilistic"), config.sampler().type());
133
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");
137
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");
141
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");
145
146 testutils::EnvVariable::setEnv("JAEGER_SERVICE_NAME", "AService");
147 testutils::EnvVariable::setEnv("JAEGER_TAGS", "hostname=foobar,my.app.version=4.5.6");
148
149 config.fromEnv();
150
151 ASSERT_EQ(std::string("http://host34:56567"), config.reporter().endpoint());
152 ASSERT_EQ(std::string("host33:45"), config.reporter().localAgentHostPort());
153
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());
158
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());
162
163 ASSERT_EQ(std::string("AService"), config.serviceName());
164
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());
171
172 ASSERT_EQ(false, config.disabled());
173
174 testutils::EnvVariable::setEnv("JAEGER_DISABLED", "TRue"); // case-insensitive
175 testutils::EnvVariable::setEnv("JAEGER_AGENT_PORT", "445");
176
177 config.fromEnv();
178 ASSERT_EQ(true, config.disabled());
179 ASSERT_EQ(std::string("host33:445"),
180 config.reporter().localAgentHostPort());
181
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", "");
193 }
194
195 } // namespace jaegertracing