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

Ensure config structs can be marshaled into YAML #11711

Open
evan-bradley opened this issue Nov 19, 2024 · 0 comments
Open

Ensure config structs can be marshaled into YAML #11711

evan-bradley opened this issue Nov 19, 2024 · 0 comments

Comments

@evan-bradley
Copy link
Contributor

Is your feature request related to a problem? Please describe.

It is possible for structs to contain fields that cannot be marshaled into YAML. We recently went through the process of updating or removing some of these (e.g. #10310), but there are currently no tests in place to ensure non-marshalable fields will be added in the future.

In particular, I want do so something like this:

// Programmatically-generated config
cfg := otelcol.Config{...}

// Should marshal to YAML
conf := confmap.New()
conf.Marshal(cfg)

// Should be equivalent to cfg
cfg2 := unmarshal(conf)

Describe the solution you'd like

Add tests to mdatagen that test that we can marshal/unmarshal all config structs. Ideally, we put the config structs through an iteration of marshaling and unmarshaling to ensure the structs can't easily enter a state where conversion is impossible.

Describe alternatives you've considered

Some kind of integration test that happens in a secondary package could be a possible way to do this, and would forgo the need for a direct confmap dependency in every package that for use only in tests.

pellared pushed a commit to open-telemetry/opentelemetry-go-contrib that referenced this issue Nov 20, 2024
This updates the generated config types to be created with go-jsonschema
v0.17.0, which includes an update to add a struct tag the
`AdditionalProperties` field that allows it to be marshaled.

Making this change fixes the following error that occurs when I marshal
a basic `otelcol.Config` struct, then run it with the Collector:
```
'metrics.readers[0].pull.exporter' has invalid keys: additionalproperties
```

Related to
open-telemetry/opentelemetry-collector#11711.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant