-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[confighttp] Review usage of 'pointer to type' #9478
Comments
Some background: Lots of these were added after the initial release of the confighttp, and authors/reviewers decide to use pointers to signal the presence of the field. I do agree that this is not ideal, but would like to have a concrete option/design on how we would support adding new members to the config when we need to know the presence. I believe we can do some tricks with |
Maybe not fully idiomatic Go, but OTTL makes signaling field presence a little easier using an Optional type, which are available out-of-the-box in other languages. We could potentially use a type like this to help make it more obvious when a field is optional, since pointers may not immediately make that intention clear.
I think for config structs the reasons are:
The field docs in confighttp indicate that these fields are optional because there's a default, so I think we can keep these.
It's possible we could do this, but it would be nice if we could make the definition of whether a field is optional exist on the type itself and let the libraries handle the unmarshaling. If we do that we would need to indicate presence, either through a sentinel value, another field on the struct, or a type that supports indicating value presence. I think pointers are a fine way to do this, but would personally prefer a type that is explicitly intended for that purpose, e.g. an |
This reminds me of something. We should add a So we can say that in order to guarantee "backwards compatible behavior" user should always initialize the config with default and overwrite anything as needed instead of creating a struct with "initial value" and leave others unset. |
+1 to using something like Optional, we can probably use @bogdandrutu can you open a separate issue for #9478 (comment) ? (edit: Done, see #9508) |
I recommend we go at this in multiple PRs:
|
) #### Description Set the defaults on `NewDefaultClientConfig`. This change is a no-op since those defaults are set if the value is not set. Add documentation to all fields as well. #### Link to tracking issue #9478 --------- Co-authored-by: Pablo Baeyens <[email protected]>
…ually creating struct This PR makes usage of `NewDefaultClientConfig` instead of manually creating the confighttp.ClientConfig struct. The updates to defaults are maintained (Timeout, Compression, WriteBufferSize) whereas the fields that match the default are not manually set anymore (Endpoint, Headers). Issue: open-telemetry#9478 (comment)
There are a few fields in
confighttp
structs that use e.g. a pointer to int instead of an int. This is an unusual pattern in configuration from components, so I think we should review why we use it and whether it is justified.To fix this issue we need to:
confighttp
based on this.On
configgrpc
we have a similar pattern for theconfigtls
configuration.The text was updated successfully, but these errors were encountered: