-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add catalog for common configs and metrics in metadata #19244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...main/java/io/opentelemetry/instrumentation/docs/internal/SharedConfigurationRegistry.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.docs.internal; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.UncheckedIOException; | ||
| import java.util.ArrayList; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Loads the shared configuration definitions ("globals") from {@code | ||
| * shared-config-definitions.yaml} and resolves {@code ref} entries in a module's configuration list | ||
| * into full {@link ConfigurationOption}s. | ||
| * | ||
| * <p>This class is internal and is hence not for public use. Its APIs are unstable and can change | ||
| * at any time. | ||
| */ | ||
| public final class SharedConfigurationRegistry { | ||
|
|
||
| private static final String RESOURCE = "/shared-config-definitions.yaml"; | ||
|
|
||
| private static final SharedConfigurationRegistry INSTANCE = | ||
| new SharedConfigurationRegistry(load()); | ||
|
|
||
| private final Map<String, ConfigurationOption> definitions; | ||
|
|
||
| SharedConfigurationRegistry(Map<String, ConfigurationOption> definitions) { | ||
| this.definitions = definitions; | ||
| } | ||
|
|
||
| public static SharedConfigurationRegistry getInstance() { | ||
| return INSTANCE; | ||
| } | ||
|
|
||
| /** Returns the shared definitions keyed by id. */ | ||
| public Map<String, ConfigurationOption> definitions() { | ||
| return definitions; | ||
| } | ||
|
|
||
| /** | ||
| * Expands each {@code ref} entry into its shared definition (tagged with the definition id) and | ||
| * passes non-ref entries through unchanged. Throws {@link IllegalArgumentException} on an unknown | ||
| * ref id so a mistyped ref fails the build rather than silently dropping a config. | ||
| */ | ||
| public List<ConfigurationOption> resolve(List<ConfigurationOption> configurations) { | ||
| List<ConfigurationOption> resolved = new ArrayList<>(configurations.size()); | ||
| for (ConfigurationOption configuration : configurations) { | ||
| if (configuration.ref() != null) { | ||
| ConfigurationOption definition = definitions.get(configuration.ref()); | ||
| if (definition == null) { | ||
| throw new IllegalArgumentException( | ||
| "Unknown shared configuration ref: '" | ||
| + configuration.ref() | ||
| + "'. Known ids: " | ||
| + definitions.keySet()); | ||
| } | ||
| resolved.add(definition); | ||
| } else { | ||
| resolved.add(configuration); | ||
| } | ||
| } | ||
| return resolved; | ||
| } | ||
|
|
||
| private static Map<String, ConfigurationOption> load() { | ||
| ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); | ||
| try (InputStream stream = SharedConfigurationRegistry.class.getResourceAsStream(RESOURCE)) { | ||
| if (stream == null) { | ||
| throw new IllegalStateException("Missing shared config definitions resource: " + RESOURCE); | ||
| } | ||
| RegistryFile file = mapper.readValue(stream, RegistryFile.class); | ||
| Map<String, ConfigurationOption> byId = new LinkedHashMap<>(); | ||
| Map<String, ConfigurationOption> configurations = file.configurations(); | ||
| if (configurations != null) { | ||
| configurations.forEach((id, option) -> byId.put(id, option.withId(id))); | ||
| } | ||
| return byId; | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException("Failed to read " + RESOURCE, e); | ||
| } | ||
| } | ||
|
|
||
| private record RegistryFile(Map<String, ConfigurationOption> configurations) {} | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.