-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[chore][docs/coding-guidelines] Document approach to optional fields #12352
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,14 @@ To keep naming patterns consistent across the project, enumeration patterns are | |
- `pcommon.ValueTypeStr` for `pcommon.ValueType` | ||
- `pmetric.MetricTypeGauge` for `pmetric.MetricType` | ||
|
||
## Optional fields | ||
|
||
When representing optional fields in the configuration, we distinguish two cases: | ||
1. For scalars (e.g. `int`, `string`, `bool`, `time.Duration`...), the zero value of the base type | ||
is used to represent the absence of the field. The default value for this field may be different | ||
from the zero value, so, when using the Go API you MUST follow the guidance on the "Default | ||
Configuration" section below. | ||
2. For struct fields, you may use a pointer to struct to represent an optional sections. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we should suggest just using non-pointer values for now so we can be consistent across structs. Our stable config modules don't use pointers for any struct fields, so this would allow us to be consistent. Once we've arrived at a decision, we can later indicate that pointer values (or optional types) should be used for types where zero values don't indicate absence of the field. |
||
|
||
## Recommended Libraries / Defaults | ||
|
||
|
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 think we should limit this to only applying to the case where the zero value is not a valid value for the field and can indicate absence of the field. For cases where this doesn't apply, I think we still need to evaluate whether to use pointers or an optional type.