-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathconfiguration.cpp
More file actions
167 lines (137 loc) · 5.27 KB
/
configuration.cpp
File metadata and controls
167 lines (137 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include <datadog/config.h>
#include <datadog/environment.h>
#include <datadog/telemetry/configuration.h>
#include <datadog/version.h>
#include "parse_util.h"
using namespace datadog::tracing;
namespace datadog::telemetry {
namespace {
tracing::Expected<Configuration> load_telemetry_env_config() {
Configuration env_cfg;
if (auto enabled_env =
lookup(environment::DD_INSTRUMENTATION_TELEMETRY_ENABLED)) {
env_cfg.enabled = !falsy(*enabled_env);
}
if (auto metrics_enabled =
lookup(environment::DD_TELEMETRY_METRICS_ENABLED)) {
env_cfg.report_metrics = !falsy(*metrics_enabled);
}
if (auto logs_enabled =
lookup(environment::DD_TELEMETRY_LOG_COLLECTION_ENABLED)) {
env_cfg.report_logs = !falsy(*logs_enabled);
}
if (auto metrics_interval_seconds =
lookup(environment::DD_TELEMETRY_METRICS_INTERVAL_SECONDS)) {
auto maybe_value = parse_double(*metrics_interval_seconds);
if (auto error = maybe_value.if_error()) {
return *error;
}
env_cfg.metrics_interval_seconds = *maybe_value;
}
if (auto heartbeat_interval_seconds =
lookup(environment::DD_TELEMETRY_HEARTBEAT_INTERVAL)) {
auto maybe_value = parse_double(*heartbeat_interval_seconds);
if (auto error = maybe_value.if_error()) {
return *error;
}
env_cfg.heartbeat_interval_seconds = *maybe_value;
}
if (auto extended_heartbeat_interval_seconds =
lookup(environment::DD_TELEMETRY_EXTENDED_HEARTBEAT_INTERVAL)) {
auto maybe_value = parse_double(*extended_heartbeat_interval_seconds);
if (auto error = maybe_value.if_error()) {
return *error;
}
env_cfg.extended_heartbeat_interval_seconds = *maybe_value;
}
return env_cfg;
}
} // namespace
tracing::Expected<FinalizedConfiguration> finalize_config(
const Configuration& user_config) {
auto env_config = load_telemetry_env_config();
if (auto error = env_config.if_error()) {
return *error;
}
ConfigMetadata::Origin origin;
FinalizedConfiguration result;
// enabled
std::tie(origin, result.enabled) =
pick(env_config->enabled, user_config.enabled, true);
if (!result.enabled) {
// NOTE(@dmehala): if the telemetry module is disabled then report metrics
// is also disabled.
result.report_metrics = false;
result.report_logs = false;
} else {
// report_metrics
std::tie(origin, result.report_metrics) =
pick(env_config->report_metrics, user_config.report_metrics, true);
// report_logs
std::tie(origin, result.report_logs) =
pick(env_config->report_logs, user_config.report_logs, true);
}
// debug
if (auto enabled_debug_env = lookup(environment::DD_TELEMETRY_DEBUG)) {
result.debug = !falsy(*enabled_debug_env);
} else {
result.debug = false;
}
// metrics_interval_seconds
auto metrics_interval = pick(env_config->metrics_interval_seconds,
user_config.metrics_interval_seconds, 60);
if (metrics_interval.second <= 0.) {
return Error{Error::Code::OUT_OF_RANGE_INTEGER,
"Telemetry metrics polling interval must be a positive value"};
}
result.metrics_interval =
std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::duration<double>(metrics_interval.second));
// heartbeat_interval_seconds
auto heartbeat_interval = pick(env_config->heartbeat_interval_seconds,
user_config.heartbeat_interval_seconds, 10);
if (heartbeat_interval.second <= 0.) {
return Error{
Error::Code::OUT_OF_RANGE_INTEGER,
"Telemetry heartbeat polling interval must be a positive value"};
}
result.heartbeat_interval =
std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::duration<double>(heartbeat_interval.second));
// extended_heartbeat_interval_seconds
auto extended_heartbeat_interval =
pick(env_config->extended_heartbeat_interval_seconds,
user_config.extended_heartbeat_interval_seconds, 86400);
if (extended_heartbeat_interval.second <= 0.) {
return Error{Error::Code::OUT_OF_RANGE_INTEGER,
"Telemetry extended heartbeat polling interval must be a "
"positive value"};
}
result.extended_heartbeat_interval =
std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::duration<double>(extended_heartbeat_interval.second));
// integration_name
std::tie(origin, result.integration_name) =
pick(env_config->integration_name, user_config.integration_name,
std::string("datadog"));
// integration_version
std::tie(origin, result.integration_version) =
pick(env_config->integration_version, user_config.integration_version,
tracing::tracer_version);
// products
result.products = user_config.products;
// onboarding data
if (auto install_id = lookup(environment::DD_INSTRUMENTATION_INSTALL_ID)) {
result.install_id = std::string(*install_id);
}
if (auto install_type =
lookup(environment::DD_INSTRUMENTATION_INSTALL_TYPE)) {
result.install_type = std::string(*install_type);
}
if (auto install_time =
lookup(environment::DD_INSTRUMENTATION_INSTALL_TIME)) {
result.install_time = std::string(*install_time);
}
return result;
}
} // namespace datadog::telemetry