Skip to content

Commit d87cccf

Browse files
committed
Change supported-configurations.json to v2 format
1 parent 49cee89 commit d87cccf

File tree

7 files changed

+2938
-1290
lines changed

7 files changed

+2938
-1290
lines changed

docs/AccessEnvironmentVariables.md

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,36 +72,29 @@ Edit the `supported-configurations.json` file and add your variable (Please keep
7272
```json
7373
{
7474
"supportedConfigurations": {
75-
"DD_YOUR_NEW_VARIABLE": {
76-
"version": ["A"]
77-
}
75+
"DD_YOUR_NEW_VARIABLE": [
76+
{
77+
"version": "A",
78+
"type": "boolean",
79+
"propertyKeys": ["tracing.new_variable"],
80+
"defaultValue": "true", # optional, default value in string format that will be parsed
81+
"aliases": ["DD_ALIAS_1", "DD_ALIAS_2"], # optional, these env vars can be set, but not used in dd-trace-rb code
82+
"deprecated": true, # optional, true | false, will log a deprecation message if the env var is set
83+
}
84+
]
7885
}
7986
}
8087
```
8188

8289
#### Configuration Structure
8390

84-
- **supportedConfigurations**: Maps variable names to configuration metadata
85-
- `version`: (Defaults to `["A"]`) Array indicating which implementations the tracer supports. Implementations are defined in the Configuration Registry and multiple implementations could be set for a single environment variable (e.g. the base one `A`, and an extra one `B` that adds new possible values). Versions are non-numeric to avoid confusion with library versions.
86-
87-
In the future, the structure will also contain more information such as the type, the default value...
88-
89-
- **aliases**: Maps canonical variable names to arrays of alias names
90-
91-
```json
92-
"aliases": {
93-
"DD_SERVICE": ["OTEL_SERVICE_NAME"]
94-
}
95-
```
96-
97-
- **deprecations**: Adds a log message to deprecated environment variables.
98-
99-
```json
100-
"deprecations": {
101-
"DD_OLD_VARIABLE": "Please use DD_NEW_VARIABLE",
102-
"DD_REMOVED_VARIABLE": "This feature will be removed in the next release"
103-
}
104-
```
91+
- **supportedConfigurations**: Maps variable names to configuration metadata. For now, we only support a single version per configuration but it is an array for future usage.
92+
- `version`: String indicating which implementations the tracer supports. Implementations are defined in the Configuration Registry. Versions are non-numeric to avoid confusion with library versions.
93+
- `type`: Optional, one of `boolean | int | float | string | array | map`. Indicates the type of the configuration value. This will tells the parser how to parse the environment variable value.
94+
- `propertyKeys`: Optional, array containing a single value, the path to access the configuration from `Datadog.configuration`. This is an array for future usage.
95+
- `defaultValue`: Optional, the default value, as a string, that will be parsed like an environment variable value.
96+
- `aliases`: Optional, maps the config to an array of alias names. These environment variables should not be used in dd-trace-rb code. These aliases are by default considered deprecated. To accept non-deprecated environment variables, you must also add them as a separate configuration.
97+
- `deprecated`: Optional, true | false, adds a log message to deprecated environment variables.
10598

10699
### Step 2: Generate Configuration Assets
107100

lib/datadog/core/configuration/supported_configurations.rb

Lines changed: 340 additions & 308 deletions
Large diffs are not rendered by default.

sig/datadog/core/configuration/config_helper.rbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ module Datadog
66

77
@source_env: env_hash
88
@raise_on_unknown_env_var: bool
9-
@supported_configurations: Hash[String, config]
9+
@supported_configurations: Hash[String, configs]
1010
@aliases: Hash[String, Array[String]]
1111
@deprecations: Hash[String, String]
1212
@alias_to_canonical: Hash[String, String]
1313

1414
def initialize: (
1515
?source_env: env_hash,
16-
?supported_configurations: Hash[String, config],
16+
?supported_configurations: Hash[String, configs],
1717
?aliases: Hash[String, Array[String]],
1818
?alias_to_canonical: Hash[String, String],
1919
?raise_on_unknown_env_var: bool

sig/datadog/core/configuration/supported_configurations.rbs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ module Datadog
22
module Core
33
module Configuration
44
type env_var_name = String
5-
type config = Hash[Symbol, Array[String]]
5+
type configs = Array[config]
6+
type config = Hash[Symbol, String | Array[String | nil] | nil]
67

7-
SUPPORTED_CONFIGURATIONS: Hash[env_var_name, config]
8+
SUPPORTED_CONFIGURATIONS: Hash[env_var_name, configs]
89
ALIASES: Hash[env_var_name, Array[env_var_name]]
9-
DEPRECATIONS: Hash[env_var_name, String]
10+
DEPRECATIONS: Array[env_var_name]
1011
ALIAS_TO_CANONICAL: Hash[env_var_name, env_var_name]
1112
end
1213
end

spec/datadog/core/configuration/supported_configurations_spec.rb

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,41 @@
77
describe 'consistency validation' do
88
it 'validates that the generated data matches the JSON file' do
99
json_data = JSON.parse(File.read('supported-configurations.json')).transform_keys(&:to_sym)
10-
json_data[:supportedConfigurations].each_value { |config| config.transform_keys!(&:to_sym) }
11-
alias_to_canonical = json_data[:aliases].each_with_object({}) do |(canonical, alias_list), h|
12-
alias_list.each do |alias_name|
13-
raise "The alias #{alias_name} is already used for #{h[alias_name]}." if h[alias_name]
10+
aliases = {}
11+
deprecations = Set.new
12+
alias_to_canonical = {}
13+
supported_configurations = json_data[:supportedConfigurations].each.with_object({}) do |(name, configs), h|
14+
configs.each do |config|
15+
config.transform_keys!(&:to_sym)
16+
config[:aliases]&.each do |alias_name|
17+
aliases[name] ||= []
18+
aliases[name] << alias_name
19+
alias_to_canonical[alias_name] = name
1420

15-
h[alias_name] = canonical
21+
# If an alias is not registered as its own config, it is by default deprecated
22+
deprecations.add(alias_name) unless json_data.dig(:supportedConfigurations, alias_name)
23+
end
24+
# Add deprecated configs with no replacement provided
25+
deprecations.add(name) if config[:deprecations]
26+
config.delete(:aliases)
27+
config.delete(:deprecations)
1628
end
29+
h[name] = configs
1730
end
1831

1932
error_message = <<~ERROR_MESSAGE
2033
Configuration map mismatch between the JSON file and the generated file, please run `rake local_config_map:generate` and commit the changes.
2134
Please refer to `docs/AccessEnvironmentVariables.md` for more information.
2235
ERROR_MESSAGE
2336

24-
expect(json_data[:supportedConfigurations]).to eq(Datadog::Core::Configuration::SUPPORTED_CONFIGURATIONS), error_message
25-
expect(json_data[:aliases]).to eq(Datadog::Core::Configuration::ALIASES), error_message
26-
expect(json_data[:deprecations]).to eq(Datadog::Core::Configuration::DEPRECATIONS), error_message
37+
expect(supported_configurations).to eq(Datadog::Core::Configuration::SUPPORTED_CONFIGURATIONS), error_message
38+
# check order of the keys
39+
expect(supported_configurations.keys).to eq(Datadog::Core::Configuration::SUPPORTED_CONFIGURATIONS.keys),
40+
"The keys in supported-configurations.json are not correctly sorted. Please keep the keys sorted alphabetically."
41+
42+
# no need to check the order for these as they don't appear in the JSON file
43+
expect(aliases).to eq(Datadog::Core::Configuration::ALIASES), error_message
44+
expect(deprecations.to_a.sort).to eq(Datadog::Core::Configuration::DEPRECATIONS), error_message
2745
expect(alias_to_canonical).to eq(Datadog::Core::Configuration::ALIAS_TO_CANONICAL), error_message
2846
end
2947
end

0 commit comments

Comments
 (0)