-
Notifications
You must be signed in to change notification settings - Fork 396
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
Use typed config in v1alpha2 #2444
Conversation
apis/v1alpha2/config.go
Outdated
} | ||
|
||
// Config encapsulates collector config. | ||
type Config struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The struct will have methods to simplify parsing - e.g. extract enabled component, extract pipeline name etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was wondering if we could match what the collector's config looks like right prior to the naming of various components. This would mean having explicit fields set for telemetry, pipelines, extensions, etc. (see here).
Something like this:
type Config struct {
Receivers []receiverConfig `mapstructure:"receivers"`
Processors []processorConfig `mapstructure:"processors"`
Exporters []exporterConfig `mapstructure:"exporters"`
Connectors []connectorConfig `mapstructure:"connectors"`
Telemetry telemetryConfig `mapstructure:"telemetry"`
Extensions extensionsConfig `mapstructure:"extensions"`
Pipelines pipelinesConfig `mapstructure:"pipelines"`
}
which would let us know the type of each component when doing logic like the port parsing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On one hand, the more structured we can make this config, the more confident we can be about rejecting invalid ones, which is a major win for users.
The potential negative is that we'll be heavily coupled to the collector at the schema level. A breaking change in the collector config schema would require us to do a corresponding breaking change in the CRD. Maybe that's ok though? Realistically, we'd need to do something like that regardless.
It would also prevent us from easily supporting alternative syntax which the collector may add without breaking changes, like open-telemetry/opentelemetry-collector#9077.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like @jaronoff97's proposal. I was thinking about the same, but I wanted to do this gradually. I will play with it and add it to the current PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A breaking change in the collector config schema would require us to do a corresponding breaking change in the CRD
In the operator, we are trying to resolve breaking changes of the collector anyways. I believe that a strongly typed config will enable us to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed with pavol. I think if / when the collector does those types of syntax changes we should have first-party support for the version that includes said changes :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few small suggestions, the only one I think may be useful prior to merge is using the AnyConfig type
return nullKeys | ||
} | ||
|
||
func hasNullValue(cfg map[string]interface{}) []string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is great – in the future in the defaulting webhook we could set the empty map using this as well :)
return nullKeys | ||
} | ||
|
||
func hasNullValue(cfg map[string]interface{}) []string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should we just have this work on the AnyConfig
type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here is a recursive call on line 131 if the value is map, so it would not work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that AnyConfig is just map[string]interface{}, wouldn't we just change 131 to assert on v.(AnyConfig)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
regardless, i don't think this is blocking so it's fine as is ✅
b318fe0
to
2f402c8
Compare
Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
7ad4ad5
to
4ef3a45
Compare
}, | ||
|
||
warnings: []string{ | ||
"Collector config spec.config has null objects: extensions.foo:, processors.batch:, processors.foo:. For compatibility tooling (kustomize and kubectl edit) it is recommended to use empty obejects e.g. batch: {}.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is awesome :D
return nullKeys | ||
} | ||
|
||
func hasNullValue(cfg map[string]interface{}) []string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
regardless, i don't think this is blocking so it's fine as is ✅
* Use typed config in v1alpha2 Signed-off-by: Pavol Loffay <p.loffay@gmail.com> * Fix Signed-off-by: Pavol Loffay <p.loffay@gmail.com> * Add more types Signed-off-by: Pavol Loffay <p.loffay@gmail.com> * Fix Signed-off-by: Pavol Loffay <p.loffay@gmail.com> * Add more tests Signed-off-by: Pavol Loffay <p.loffay@gmail.com> * rewrite test Signed-off-by: Pavol Loffay <p.loffay@gmail.com> --------- Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
Description:
I have as well tried suggestions from kubernetes-sigs/controller-tools#636 (comment)
But nothing worked better than byte array
Link to tracking Issue:
Resolves #1707
Testing:
Documentation: