Skip to content

Commit 9859372

Browse files
authored
feat(config): migrate supported_configurations.json file to v2 format (#4374)
Co-authored-by: benjamin.debernardi <benjamin.debernardi@datadoghq.com>
1 parent a65a152 commit 9859372

File tree

9 files changed

+1299
-282
lines changed

9 files changed

+1299
-282
lines changed

.gitlab-ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ variables:
1414
BENCHMARK_TARGETS: "BenchmarkStartRequestSpan|BenchmarkHttpServeTrace|BenchmarkTracerAddSpans|BenchmarkStartSpan|BenchmarkSingleSpanRetention|BenchmarkOTelApiWithCustomTags|BenchmarkInjectW3C|BenchmarkExtractW3C|BenchmarkPartialFlushing|BenchmarkConfig|BenchmarkStartSpanConfig|BenchmarkGraphQL|BenchmarkSampleWAFContext|BenchmarkCaptureStackTrace|BenchmarkSetTagString|BenchmarkSetTagStringPtr|BenchmarkSetTagMetric|BenchmarkSetTagStringer|BenchmarkSerializeSpanLinksInMeta|BenchmarkLogs|BenchmarkParallelLogs|BenchmarkMetrics|BenchmarkParallelMetrics"
1515

1616
workflow:
17-
auto_cancel:
17+
auto_cancel:
1818
on_new_commit: interruptible
19-
19+
2020
# In order to run benchmarks in parallel, we generate a matrix of test names based on the BENCHMARK_TARGETS variable.
2121
# This will be used in tandem with bp-runner in benchmarks.yml.
2222
# This will allow us to spin up a child job in GitLab CI that handles running all of the benchmarks in parallel.
@@ -104,7 +104,7 @@ analyze-benchmark-results:
104104
ls -la "${ARTIFACTS_DIR}/"
105105
./steps/analyze-results.sh
106106
./steps/post-pr-comment.sh
107-
107+
108108
artifacts:
109109
name: "reports"
110110
when: always
@@ -122,8 +122,8 @@ validate_supported_configurations_v2_local_file:
122122
- when: on_success
123123
extends: .validate_supported_configurations_v2_local_file
124124
variables:
125-
LOCAL_JSON_PATH: "internal/env/supported_configurations.json"
126-
BACKFILLED: "false"
125+
LOCAL_JSON_PATH: internal/env/supported_configurations.json
126+
BACKFILLED: true
127127

128128
update_central_configurations_version_range_v2:
129129
stage: config-validation

.gitlab/configuration-central-validation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This URL is available in the dd-gitlab/publish-content-addresable-templates job whenever
33
# a change is made on the one-pipeline template.
44
variables:
5-
SCRIPTS_BASE_URL: https://gitlab-templates.ddbuild.io/libdatadog/one-pipeline/ca/1c0dd2e9e6e173100cf3ce89b1d2dd11c5d3ae74ff46ce9f262faf371fd0e736/scripts/config-inversion/
5+
SCRIPTS_BASE_URL: https://gitlab-templates.ddbuild.io/libdatadog/one-pipeline/ca/f14ac28614630d12bcfe6cba4fd8d72dce142c62ff0b053ba7c323622104ebd7/scripts/config-inversion/
66

77
.download-scripts-from-template: &download-scripts-from-template
88
- mkdir -p scripts

internal/config/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ func loadConfig() *Config {
137137
cfg.statsComputationEnabled = provider.getBool("DD_TRACE_STATS_COMPUTATION_ENABLED", true)
138138
cfg.dataStreamsMonitoringEnabled = provider.getBool("DD_DATA_STREAMS_ENABLED", false)
139139
cfg.dynamicInstrumentationEnabled = provider.getBool("DD_DYNAMIC_INSTRUMENTATION_ENABLED", false)
140-
cfg.globalSampleRate = provider.getFloat("DD_TRACE_SAMPLE_RATE", 0.0)
141140
cfg.ciVisibilityEnabled = provider.getBool(constants.CIVisibilityEnabledEnvironmentVariable, false)
142141
cfg.ciVisibilityAgentless = provider.getBool("DD_CIVISIBILITY_AGENTLESS_ENABLED", false)
143142
cfg.logDirectory = provider.getString("DD_TRACE_LOG_DIRECTORY", "")

internal/env/env_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ func TestVerifySupportedConfiguration(t *testing.T) {
6868
cfg, err := readSupportedConfigurations(getConfigFilePath())
6969
require.NoError(t, err)
7070
require.Contains(t, cfg.SupportedConfigurations, "DD_UNKNOWN_CONFIGURATION_KEY")
71-
require.Equal(t, []string{"A"}, cfg.SupportedConfigurations["DD_UNKNOWN_CONFIGURATION_KEY"])
71+
defaultValue := "FIX_ME"
72+
require.EqualValues(t, []configurationImplementation{{
73+
Implementation: "A",
74+
Type: defaultValue,
75+
Default: &defaultValue,
76+
}}, cfg.SupportedConfigurations["DD_UNKNOWN_CONFIGURATION_KEY"])
7277

7378
// Remove the env var from the supported configurations file
7479
delete(cfg.SupportedConfigurations, "DD_UNKNOWN_CONFIGURATION_KEY")

internal/env/supported_configurations.gen.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/env/supported_configurations.go

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package env
77

88
import (
9+
"bytes"
910
"encoding/json"
1011
"fmt"
1112
"os"
@@ -16,17 +17,23 @@ import (
1617
"github.com/DataDog/dd-trace-go/v2/internal/log"
1718
)
1819

20+
type configurationImplementation struct {
21+
Implementation string `json:"implementation"`
22+
Type string `json:"type"`
23+
Default *string `json:"default"`
24+
Aliases []string `json:"aliases,omitempty"`
25+
}
26+
1927
// SupportedConfiguration represents the content of the supported_configurations.json file.
20-
type SupportedConfiguration struct {
21-
SupportedConfigurations map[string][]string `json:"supportedConfigurations"`
22-
Aliases map[string][]string `json:"aliases"`
28+
type supportedConfiguration struct {
29+
Version string `json:"version"`
30+
SupportedConfigurations map[string][]configurationImplementation `json:"supportedConfigurations"`
2331
}
2432

2533
var (
2634
configFilePath string
2735
once sync.Once
2836
mu sync.Mutex
29-
skipLock bool
3037
)
3138

3239
// getConfigFilePath returns the path to the supported_configurations.json file
@@ -65,34 +72,47 @@ func addSupportedConfigurationToFile(name string) {
6572
}
6673

6774
if _, ok := cfg.SupportedConfigurations[name]; !ok {
68-
cfg.SupportedConfigurations[name] = []string{"A"}
75+
defaultValue := "FIX_ME"
76+
cfg.SupportedConfigurations[name] = []configurationImplementation{
77+
{
78+
Implementation: "A",
79+
Type: defaultValue,
80+
Default: &defaultValue,
81+
},
82+
}
6983
}
7084

7185
if err := writeSupportedConfigurations(filePath, cfg); err != nil {
7286
log.Error("config: failed to write supported configurations: %s", err.Error())
7387
}
7488
}
7589

76-
func readSupportedConfigurations(filePath string) (*SupportedConfiguration, error) {
90+
func readSupportedConfigurations(filePath string) (*supportedConfiguration, error) {
7791
// read the json file
7892
jsonFile, err := os.ReadFile(filePath)
7993
if err != nil {
8094
return nil, fmt.Errorf("failed to open supported_configurations.json: %w", err)
8195
}
8296

83-
var cfg SupportedConfiguration
97+
var cfg supportedConfiguration
8498
if err := json.Unmarshal(jsonFile, &cfg); err != nil {
8599
return nil, fmt.Errorf("failed to unmarshal SupportedConfiguration: %w", err)
86100
}
87101
return &cfg, nil
88102
}
89103

90-
func writeSupportedConfigurations(filePath string, cfg *SupportedConfiguration) error {
91-
// write the json file - Go's json.MarshalIndent automatically sorts map keys
92-
jsonFile, err := json.MarshalIndent(cfg, "", " ")
93-
if err != nil {
104+
func writeSupportedConfigurations(filePath string, cfg *supportedConfiguration) error {
105+
// Write the JSON file. We explicitly disable HTML escaping so strings like "&"
106+
// remain readable (and stable across test runs) instead of being rendered as
107+
// "\u0026". Map keys are still deterministically sorted by encoding/json.
108+
var buf bytes.Buffer
109+
enc := json.NewEncoder(&buf)
110+
enc.SetEscapeHTML(false)
111+
enc.SetIndent("", " ")
112+
if err := enc.Encode(cfg); err != nil {
94113
return fmt.Errorf("failed to marshal SupportedConfiguration: %w", err)
95114
}
115+
jsonFile := bytes.TrimRight(buf.Bytes(), "\n")
96116

97117
if err := os.WriteFile(filePath, jsonFile, 0644); err != nil {
98118
return fmt.Errorf("failed to write supported_configurations.json: %w", err)

0 commit comments

Comments
 (0)