]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/jaeger-client-cpp/src/jaegertracing/reporters/Config.h
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / jaeger-client-cpp / src / jaegertracing / reporters / Config.h
CommitLineData
f67539c2
TL
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#ifndef JAEGERTRACING_REPORTERS_CONFIG_H
18#define JAEGERTRACING_REPORTERS_CONFIG_H
19
20#include <chrono>
21#include <memory>
22#include <string>
23#include <utility>
24
25#include "jaegertracing/Logging.h"
26#include "jaegertracing/metrics/Metrics.h"
27#include "jaegertracing/reporters/Reporter.h"
28#include "jaegertracing/utils/YAML.h"
29#include "jaegertracing/utils/HTTPTransporter.h"
30#include "jaegertracing/utils/UDPTransporter.h"
31
32namespace jaegertracing {
33namespace reporters {
34
35class Config {
36 public:
37 using Clock = std::chrono::steady_clock;
38
39 static constexpr auto kDefaultQueueSize = 100;
40 static constexpr auto kDefaultLocalAgentHostPort = "127.0.0.1:6831";
41 static constexpr auto kDefaultEndpoint = "";
42
43 static constexpr auto kJAEGER_AGENT_HOST_ENV_PROP = "JAEGER_AGENT_HOST";
44 static constexpr auto kJAEGER_AGENT_PORT_ENV_PROP = "JAEGER_AGENT_PORT";
45 static constexpr auto kJAEGER_ENDPOINT_ENV_PROP = "JAEGER_ENDPOINT";
46
47 static constexpr auto kJAEGER_REPORTER_LOG_SPANS_ENV_PROP = "JAEGER_REPORTER_LOG_SPANS";
48 static constexpr auto kJAEGER_REPORTER_FLUSH_INTERVAL_ENV_PROP = "JAEGER_REPORTER_FLUSH_INTERVAL";
49 static constexpr auto kJAEGER_REPORTER_MAX_QUEUE_SIZE_ENV_PROP = "JAEGER_REPORTER_MAX_QUEUE_SIZE";
50
51
52
53 static Clock::duration defaultBufferFlushInterval()
54 {
55 return std::chrono::seconds(10);
56 }
57
58#ifdef JAEGERTRACING_WITH_YAML_CPP
59
60 static Config parse(const YAML::Node& configYAML)
61 {
62 if (!configYAML.IsDefined() || !configYAML.IsMap()) {
63 return Config();
64 }
65
66 const auto queueSize =
67 utils::yaml::findOrDefault<int>(configYAML, "queueSize", 0);
68 const auto bufferFlushInterval =
69 std::chrono::seconds(utils::yaml::findOrDefault<int>(
70 configYAML, "bufferFlushInterval", 0));
71 const auto logSpans =
72 utils::yaml::findOrDefault<bool>(configYAML, "logSpans", false);
73 const auto localAgentHostPort = utils::yaml::findOrDefault<std::string>(
74 configYAML, "localAgentHostPort", "");
75 const auto endpoint = utils::yaml::findOrDefault<std::string>(
76 configYAML, "endpoint", "");
77 return Config(
78 queueSize, bufferFlushInterval, logSpans, localAgentHostPort, endpoint);
79 }
80
81#endif // JAEGERTRACING_WITH_YAML_CPP
82
83 explicit Config(
84 int queueSize = kDefaultQueueSize,
85 const Clock::duration& bufferFlushInterval =
86 defaultBufferFlushInterval(),
87 bool logSpans = false,
88 const std::string& localAgentHostPort = kDefaultLocalAgentHostPort, const std::string& endpoint = kDefaultEndpoint)
89 : _queueSize(queueSize > 0 ? queueSize : kDefaultQueueSize)
90 , _bufferFlushInterval(bufferFlushInterval.count() > 0
91 ? bufferFlushInterval
92 : defaultBufferFlushInterval())
93 , _logSpans(logSpans)
94 , _localAgentHostPort(localAgentHostPort.empty()
95 ? kDefaultLocalAgentHostPort
96 : localAgentHostPort)
97 , _endpoint(endpoint)
98 {
99 }
100
101 std::unique_ptr<Reporter> makeReporter(const std::string& serviceName,
102 logging::Logger& logger,
103 metrics::Metrics& metrics) const;
104
105 int queueSize() const { return _queueSize; }
106
107 const Clock::duration& bufferFlushInterval() const
108 {
109 return _bufferFlushInterval;
110 }
111
112 bool logSpans() const { return _logSpans; }
113
114 const std::string& localAgentHostPort() const
115 {
116 return _localAgentHostPort;
117 }
118
119 const std::string& endpoint() const
120 {
121 return _endpoint;
122 }
123
124 void fromEnv();
125
126 private:
127 int _queueSize;
128 Clock::duration _bufferFlushInterval;
129 bool _logSpans;
130 std::string _localAgentHostPort;
131 std::string _endpoint;
132};
133
134} // namespace reporters
135} // namespace jaegertracing
136
137#endif // JAEGERTRACING_REPORTERS_CONFIG_H