Skip to content
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

Merged
merged 6 commits into from
Jan 8, 2024

Conversation

pavolloffay
Copy link
Member

Description:

I have as well tried suggestions from kubernetes-sigs/controller-tools#636 (comment)

runtime.RawExtension
	// +kubebuilder:pruning:PreserveUnknownFields
        // +kubebuilder:validation:Schemaless
	Spec interface{} `json:"spec"`

But nothing worked better than byte array

Link to tracking Issue:

Resolves #1707

Testing:

Documentation:

@pavolloffay pavolloffay requested a review from a team as a code owner December 15, 2023 15:35
@pavolloffay pavolloffay added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Dec 15, 2023
}

// Config encapsulates collector config.
type Config struct {
Copy link
Member Author

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.

Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Contributor

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 :)

Copy link
Contributor

@jaronoff97 jaronoff97 left a 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

apis/v1alpha2/collector_webhook_test.go Outdated Show resolved Hide resolved
return nullKeys
}

func hasNullValue(cfg map[string]interface{}) []string {
Copy link
Contributor

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 {
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

@jaronoff97 jaronoff97 Jan 8, 2024

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)

Copy link
Contributor

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 ✅

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>
Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
},

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: {}.",
Copy link
Contributor

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 {
Copy link
Contributor

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 ✅

@pavolloffay pavolloffay merged commit e56f45e into open-telemetry:main Jan 8, 2024
27 checks passed
ItielOlenick pushed a commit to ItielOlenick/opentelemetry-operator that referenced this pull request May 1, 2024
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[collector] Specify the collector's configuration with structure yaml instead of a string
4 participants