Skip to content

Commit a728db4

Browse files
committed
fix(config-inversion): preserve implementation versions from existing JSON
1 parent a345bd0 commit a728db4

2 files changed

Lines changed: 39 additions & 13 deletions

File tree

supported-configurations.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@
5959
"DD_PROPAGATION_STYLE_EXTRACT": [
6060
{
6161
"default": "datadog,tracecontext,baggage",
62-
"implementation": "A",
62+
"implementation": "C",
6363
"type": "array"
6464
}
6565
],
6666
"DD_PROPAGATION_STYLE_INJECT": [
6767
{
6868
"default": "datadog,tracecontext,baggage",
69-
"implementation": "A",
69+
"implementation": "C",
7070
"type": "array"
7171
}
7272
],
@@ -87,7 +87,7 @@
8787
"DD_SERVICE": [
8888
{
8989
"default": "",
90-
"implementation": "A",
90+
"implementation": "F",
9191
"type": "string"
9292
}
9393
],
@@ -101,7 +101,7 @@
101101
"DD_SPAN_SAMPLING_RULES_FILE": [
102102
{
103103
"default": "",
104-
"implementation": "A",
104+
"implementation": "B",
105105
"type": "string"
106106
}
107107
],
@@ -129,7 +129,7 @@
129129
"DD_TELEMETRY_HEARTBEAT_INTERVAL": [
130130
{
131131
"default": "10",
132-
"implementation": "A",
132+
"implementation": "D",
133133
"type": "decimal"
134134
}
135135
],
@@ -206,21 +206,21 @@
206206
"DD_TRACE_PROPAGATION_STYLE": [
207207
{
208208
"default": "datadog,tracecontext,baggage",
209-
"implementation": "A",
209+
"implementation": "D",
210210
"type": "array"
211211
}
212212
],
213213
"DD_TRACE_PROPAGATION_STYLE_EXTRACT": [
214214
{
215215
"default": "datadog,tracecontext,baggage",
216-
"implementation": "A",
216+
"implementation": "D",
217217
"type": "array"
218218
}
219219
],
220220
"DD_TRACE_PROPAGATION_STYLE_INJECT": [
221221
{
222222
"default": "datadog,tracecontext,baggage",
223-
"implementation": "A",
223+
"implementation": "D",
224224
"type": "array"
225225
}
226226
],
@@ -255,14 +255,14 @@
255255
"DD_TRACE_SAMPLE_RATE": [
256256
{
257257
"default": "1",
258-
"implementation": "A",
258+
"implementation": "C",
259259
"type": "decimal"
260260
}
261261
],
262262
"DD_TRACE_SAMPLING_RULES": [
263263
{
264264
"default": "[]",
265-
"implementation": "A",
265+
"implementation": "D",
266266
"type": "array"
267267
}
268268
],

tools/config-inversion/main.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,23 @@ std::string to_string_any(const T& value) {
1818
return oss.str();
1919
}
2020

21-
nlohmann::json build_configuration() {
21+
// Look up the existing implementation version for a config name from a
22+
// previously generated JSON. Returns "A" if not found.
23+
std::string existing_version(const nlohmann::json& existing,
24+
const std::string& name) {
25+
if (existing.contains("supportedConfigurations")) {
26+
const auto& sc = existing["supportedConfigurations"];
27+
if (sc.contains(name) && sc[name].is_array() && !sc[name].empty()) {
28+
const auto& first = sc[name][0];
29+
if (first.contains("implementation")) {
30+
return first["implementation"].get<std::string>();
31+
}
32+
}
33+
}
34+
return "A";
35+
}
36+
37+
nlohmann::json build_configuration(const nlohmann::json& existing) {
2238
nlohmann::json j;
2339
j["version"] = "2";
2440

@@ -33,7 +49,7 @@ nlohmann::json build_configuration() {
3349
do { \
3450
auto obj = nlohmann::json::object(); \
3551
obj["default"] = to_string_any(DEFAULT_VALUE); \
36-
obj["implementation"] = "A"; \
52+
obj["implementation"] = existing_version(existing, QUOTED(NAME)); \
3753
{ \
3854
std::string type_str = QUOTED(TYPE); \
3955
std::transform(type_str.begin(), type_str.end(), type_str.begin(), \
@@ -70,7 +86,17 @@ int main(int argc, char** argv) {
7086

7187
const fs::path output_file = result["output-file"].as<std::string>();
7288

73-
const auto j = build_configuration();
89+
// Read existing file to preserve implementation versions.
90+
nlohmann::json existing;
91+
{
92+
std::ifstream in(output_file);
93+
if (in) {
94+
existing = nlohmann::json::parse(in, nullptr, false);
95+
if (existing.is_discarded()) existing = nlohmann::json::object();
96+
}
97+
}
98+
99+
const auto j = build_configuration(existing);
74100
std::ofstream file(output_file, std::ios::binary);
75101
if (!file) {
76102
std::cerr << "Unable to write configuration file";

0 commit comments

Comments
 (0)