This repository was archived by the owner on Jul 28, 2026. It is now read-only.
integrations-next: allow all integrations to be unmarshaled as an array or object - #1463
Merged
rfratto merged 1 commit intoMar 3, 2022
Conversation
… <name>_configs
This relaxes the restrictions on how integrations are unmarshaled so
that any integration, regardless of type, can be unmarshaled as an JSON
object or an array.
This makes configurations like this technically valid:
integrations:
node_exporter_configs:
- {}
Such a configuration would not be recommended to users, but as there is
only one defined instance of node_exporter, it still satisfies the
singleton requirements. It is unlikely that we would document this is
possible.
Introducing this change makes it *much* easier for the operator to
generate configs for integrations, as we no longer have to switch
between the _configs and non-_configs key based on the integration being
generated.
rfratto
commented
Mar 3, 2022
Comment on lines
+102
to
124
| // Ensure that no singleton integration is defined twice | ||
| var ( | ||
| duplicatedSingletons []string | ||
| singletonSet = make(map[string]struct{}) | ||
| ) | ||
| for _, cfg := range cfg { | ||
| if t, ok := RegisteredType(cfg.Name()); ok && t == TypeSingleton { | ||
| // Add to the map but if we find it already exists then create an error | ||
| if _, ok := singletonCheck[cfg.Name()]; ok { | ||
| returnError = multierror.Append(returnError, fmt.Errorf("found multiple instances of singleton integration %s", cfg.Name())) | ||
| } else { | ||
| singletonCheck[cfg.Name()] = struct{}{} | ||
| } | ||
| t, _ := RegisteredType(cfg.Name()) | ||
| if t != TypeSingleton { | ||
| continue | ||
| } | ||
|
|
||
| if _, exists := singletonSet[cfg.Name()]; exists { | ||
| duplicatedSingletons = append(duplicatedSingletons, cfg.Name()) | ||
| continue | ||
| } | ||
| singletonSet[cfg.Name()] = struct{}{} | ||
| } | ||
| if returnError != nil { | ||
| return returnError | ||
| if len(duplicatedSingletons) == 1 { | ||
| return fmt.Errorf("integration %q may only be defined once", duplicatedSingletons[0]) | ||
| } else if len(duplicatedSingletons) > 1 { | ||
| list := strings.Join(duplicatedSingletons, ", ") | ||
| return fmt.Errorf("the following integrations may only be defined once each: %s", list) | ||
| } |
Contributor
Author
There was a problem hiding this comment.
Just doing a little bit of tidying here so there's less indentation
rfratto
commented
Mar 3, 2022
Comment on lines
+89
to
+90
| // TypeInvalid is an invalid type. | ||
| TypeInvalid Type = iota |
Contributor
Author
There was a problem hiding this comment.
Introducing TypeInvalid as the zero value removes the need for examining ok from RegisteredType
mattdurham
approved these changes
Mar 3, 2022
mattdurham
left a comment
Contributor
There was a problem hiding this comment.
Looks good and nice simplification!
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This PR relaxes the restrictions on how v2 integrations are unmarshaled so that any integration, regardless of type, can be unmarshaled as an JSON object or an array.
Introducing this change makes it much easier for the operator to generate configs for integrations, as we no longer have to switch between the _configs and non-_configs key based on the integration being generated.
With this change, configurations like these are now valid:
Such a configuration would not be recommended to users, but as there is only one defined instance of node_exporter, it still satisfies the singleton requirements. It is unlikely that we would document this is possible.
Instead, the following configuration would still be documented and recommended for singleton integrations:
Re-marshaling
Regardless of how the integrations config is unmarshaled, it will be re-marshaled as the non-array type. This means this config:
Will display as the following at the
/-/configendpoint: