|
21 | 21 | #include "jaegertracing/utils/YAML.h"
|
22 | 22 | #include <gtest/gtest.h>
|
23 | 23 |
|
| 24 | +#include <cstdlib> |
| 25 | + |
24 | 26 | namespace jaegertracing {
|
25 | 27 |
|
26 | 28 | #ifdef JAEGERTRACING_WITH_YAML_CPP
|
@@ -93,4 +95,95 @@ TEST(Config, testZeroSamplingParam)
|
93 | 95 |
|
94 | 96 | #endif // JAEGERTRACING_WITH_YAML_CPP
|
95 | 97 |
|
| 98 | + |
| 99 | +void setEnv(const char *variable, const char *value) { |
| 100 | +#ifdef WIN32 |
| 101 | + _putenv_s(variable, value); |
| 102 | +#else |
| 103 | + setenv(variable, value, true); |
| 104 | +#endif |
| 105 | +} |
| 106 | + |
| 107 | +TEST(Config, testFromEnv) |
| 108 | +{ |
| 109 | + std::vector<Tag> tags; |
| 110 | + tags.emplace_back("hostname", std::string("foo")); |
| 111 | + tags.emplace_back("my.app.version", std::string("1.2.3")); |
| 112 | + |
| 113 | + Config config(false, |
| 114 | + samplers::Config("probabilistic", |
| 115 | + 0.7, |
| 116 | + "http://host34:57/sampling", |
| 117 | + 0, |
| 118 | + samplers::Config::Clock::duration()), |
| 119 | + reporters::Config(10, |
| 120 | + std::chrono::milliseconds(100), |
| 121 | + false, |
| 122 | + "host35:77", |
| 123 | + "http://host36:56568"), |
| 124 | + propagation::HeadersConfig(), |
| 125 | + baggage::RestrictionsConfig(), |
| 126 | + "test-service", |
| 127 | + tags); |
| 128 | + |
| 129 | + config.fromEnv(); |
| 130 | + |
| 131 | + ASSERT_EQ(std::string("http://host36:56568"), config.reporter().endpoint()); |
| 132 | + ASSERT_EQ(std::string("host35:77"), config.reporter().localAgentHostPort()); |
| 133 | + |
| 134 | + ASSERT_EQ(10, config.reporter().queueSize()); |
| 135 | + ASSERT_EQ(std::chrono::milliseconds(100), |
| 136 | + config.reporter().bufferFlushInterval()); |
| 137 | + ASSERT_EQ(false, config.reporter().logSpans()); |
| 138 | + |
| 139 | + ASSERT_EQ(.7, config.sampler().param()); |
| 140 | + ASSERT_EQ(std::string("probabilistic"), config.sampler().type()); |
| 141 | + |
| 142 | + setEnv("JAEGER_AGENT_HOST", "host33"); |
| 143 | + setEnv("JAEGER_AGENT_PORT", "45"); |
| 144 | + setEnv("JAEGER_ENDPOINT", "http://host34:56567"); |
| 145 | + |
| 146 | + setEnv("JAEGER_REPORTER_MAX_QUEUE_SIZE", "33"); |
| 147 | + setEnv("JAEGER_REPORTER_FLUSH_INTERVAL", "45"); |
| 148 | + setEnv("JAEGER_REPORTER_LOG_SPANS", "true"); |
| 149 | + |
| 150 | + setEnv("JAEGER_SAMPLER_PARAM", "33"); |
| 151 | + setEnv("JAEGER_SAMPLER_TYPE", "const"); |
| 152 | + |
| 153 | + setEnv("JAEGER_SERVICE_NAME", "AService"); |
| 154 | + setEnv("JAEGER_TAGS", "hostname=foobar,my.app.version=4.5.6"); |
| 155 | + |
| 156 | + config.fromEnv(); |
| 157 | + |
| 158 | + ASSERT_EQ(std::string("http://host34:56567"), config.reporter().endpoint()); |
| 159 | + ASSERT_EQ(std::string("host33:45"), config.reporter().localAgentHostPort()); |
| 160 | + |
| 161 | + ASSERT_EQ(33, config.reporter().queueSize()); |
| 162 | + ASSERT_EQ(std::chrono::milliseconds(45), |
| 163 | + config.reporter().bufferFlushInterval()); |
| 164 | + ASSERT_EQ(true, config.reporter().logSpans()); |
| 165 | + |
| 166 | + ASSERT_EQ(33., config.sampler().param()); |
| 167 | + ASSERT_EQ(std::string("const"), config.sampler().type()); |
| 168 | + |
| 169 | + ASSERT_EQ(std::string("AService"), config.serviceName()); |
| 170 | + |
| 171 | + std::vector<Tag> expectedTags; |
| 172 | + expectedTags.emplace_back("hostname", std::string("foo")); |
| 173 | + expectedTags.emplace_back("my.app.version", std::string("1.2.3")); |
| 174 | + expectedTags.emplace_back("hostname", std::string("foobar")); |
| 175 | + expectedTags.emplace_back("my.app.version", std::string("4.5.6")); |
| 176 | + ASSERT_EQ(expectedTags, config.tags()); |
| 177 | + |
| 178 | + ASSERT_EQ(false, config.disabled()); |
| 179 | + |
| 180 | + setEnv("JAEGER_DISABLED", "TRue"); // case-insensitive |
| 181 | + setEnv("JAEGER_AGENT_PORT", "445"); |
| 182 | + |
| 183 | + config.fromEnv(); |
| 184 | + ASSERT_EQ(true, config.disabled()); |
| 185 | + ASSERT_EQ(std::string("host33:445"), |
| 186 | + config.reporter().localAgentHostPort()); |
| 187 | +} |
| 188 | + |
96 | 189 | } // namespace jaegertracing
|
0 commit comments