-
Notifications
You must be signed in to change notification settings - Fork 92
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
fix: allow config bools to default to true #969
Conversation
Do you want to make this a draft PR until you have code for it? |
Certainly! Drafted ... and there should be code for it shortly. UPDATE: Code added. As is my wont, walking our commits might help understanding the whys and whats of the changes. |
138ed07
to
4a6404a
Compare
Co-authored-by: Faith Chikwekwe <[email protected]>
Because bool's zero value is false, defaults library cannot determine if a field has not been set. Use a pointer instead! Zero for an unset pointer is nil. Co-authored-by: Faith Chikwekwe <[email protected]>
4a6404a
to
e2b420a
Compare
Co-authored-by: Faith Chikwekwe <[email protected]>
Co-authored-by: Faith Chikwekwe <[email protected]>
e2b420a
to
c33b520
Compare
return f.mainConfig.Specialized.CompressPeerCommunication | ||
var compressPeerCommunication bool | ||
if f.mainConfig.Specialized.CompressPeerCommunication == nil { | ||
compressPeerCommunication = true |
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.
These true values are hardcoded, but we should try and lookup these values from the struct tag. That will require us to use the reflect package mimicking some behavior from the defaults package. Is this something that we want in the scope of this fix?
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'm not sure I'm happy with the hardcoded true
values that are only present on struct values that are currently type bool
and default true
. It might be nice to write a helper function that we can add to add struct values to check is type is bool
and default is true
.
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.
@robbkidd suggested that we either add some code to the validate function to check for struct tag type and value. Or perhaps there is a test that we can add later on to validate any changes to struct tags.
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.
Instead of reading the tags, we talked about something like:
type BoolDefaultTrue *bool
That would give us the hook to do some more useful linting or other work to make sure that we keep the contract for those types.
@@ -890,6 +890,31 @@ func TestHoneycombIdFieldsConfigDefault(t *testing.T) { | |||
assert.Equal(t, []string{"trace.parent_id", "parentId"}, c.GetParentIdFieldNames()) | |||
} | |||
|
|||
func TestOverrideConfigDefaults(t *testing.T) { |
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.
Added in the first commit of this PR, demonstrate the 5 bools that default to true don't. Not sure if we keep this test long-term.
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.
Let's just add a comment to this explaining why it exists.
logger/honeycomb.go
Outdated
@@ -59,7 +59,7 @@ func (h *HoneycombLogger) Start() error { | |||
} | |||
} | |||
|
|||
if loggerConfig.SamplerEnabled { | |||
if *loggerConfig.SamplerEnabled { |
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.
We should consider adding a getter function for HoneycombLogger.SamplerEnabled so that we do not have to dereference in every time Sampler Enabled is used.
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 loggerConfig.GetSamplerEnabled()
function would also do away with the shenanigans used in test to get a pointer to a bool.
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.
During a chat this morning, @kentquirk, @fchikwekwe, and I agreed we should make the SamplerEnabled bool-pointer private and add a getter function to smooth the bool interface. That'll be work on this PR with other ideas to reduce tech debt in a follow-up issue.
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.
And I learn that I cannot make the SamplerEnabled field private without breaking the YAML marshal/unmarshal. Still adding the function, though!
@@ -119,10 +119,21 @@ type HoneycombLoggerConfig struct { | |||
APIHost string `yaml:"APIHost" default:"https://api.honeycomb.io"` |
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.
Not in scope for this PR, but accessor functions for all fields on HoneycomLoggerConfig
would be nice.
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 struggle with this; every accessor adds one form of tech debt to save another form of tech debt. In particular, when I broke up the config into subsections, I deliberately did not add accessors for everything.
I don't feel strongly against it, I just wish there was a better way (JS/java properties would be nice but Go doesn't give us those).
@@ -119,10 +119,21 @@ type HoneycombLoggerConfig struct { | |||
APIHost string `yaml:"APIHost" default:"https://api.honeycomb.io"` | |||
APIKey string `yaml:"APIKey" cmdenv:"HoneycombLoggerAPIKey,HoneycombAPIKey"` | |||
Dataset string `yaml:"Dataset" default:"Refinery Logs"` | |||
SamplerEnabled bool `yaml:"SamplerEnabled" default:"true"` | |||
SamplerEnabled *bool `yaml:"SamplerEnabled" default:"true"` // Avoid pointer woe on access, use GetSamplerEnabled() instead. |
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 tossed this comment on the field so that it would be shown by IDEs that do the hover box thing. Like a
🤔 ... which I suppose is a comment that could be added to all the new *bool
fields.
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.
Add this comment to all the *bool
s in a separate commit (easily removed from this PR if that's too much commentary).
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 this is pretty good, and the only thing I'd like to see changed is to define that type for a bool that defaults to true, and use that appropriately; we don't have to get into modifying the defaults package or validating specially unless you see a really easy solution. I wouldn't spend a lot more time on it.
@@ -890,6 +890,31 @@ func TestHoneycombIdFieldsConfigDefault(t *testing.T) { | |||
assert.Equal(t, []string{"trace.parent_id", "parentId"}, c.GetParentIdFieldNames()) | |||
} | |||
|
|||
func TestOverrideConfigDefaults(t *testing.T) { |
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.
Let's just add a comment to this explaining why it exists.
@@ -119,10 +119,21 @@ type HoneycombLoggerConfig struct { | |||
APIHost string `yaml:"APIHost" default:"https://api.honeycomb.io"` |
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 struggle with this; every accessor adds one form of tech debt to save another form of tech debt. In particular, when I broke up the config into subsections, I deliberately did not add accessors for everything.
I don't feel strongly against it, I just wish there was a better way (JS/java properties would be nice but Go doesn't give us those).
return f.mainConfig.Specialized.CompressPeerCommunication | ||
var compressPeerCommunication bool | ||
if f.mainConfig.Specialized.CompressPeerCommunication == nil { | ||
compressPeerCommunication = true |
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.
Instead of reading the tags, we talked about something like:
type BoolDefaultTrue *bool
That would give us the hook to do some more useful linting or other work to make sure that we keep the contract for those types.
Yes, I played around with adding the boolean |
Which problem is this PR solving?
Short description of the changes
Maybe TODO