signalfx / signalfx-go

Go client library and instrumentation bindings for SignalFx
https://www.signalfx.com
Apache License 2.0
14 stars 51 forks source link

Fix sendAlertsOnceMutingPeriodHasEnded JSON marshaling bug #169

Closed spenceral closed 1 year ago

spenceral commented 2 years ago

The AlertMutingRule SendAlertsOnceMutingPeriodHasEnded currently has the "omitempty" JSON tag. Because false is the boolean zero value, setting SendAlertsOnceMutingPeriodHasEnded to false causes the field to be omitted when marshaled as JSON. Since the API defaults this value to true, it is not possible to set it to false using the Create or UpdateAlertMutingRule functions.

Removing the "omitempty" tag will allow users to set this field to false.


You can see a reproduction of the bug here https://go.dev/play/p/70cNPv6y7jV

The biggest drawback of this PR is that it changes the behavior of not explicitly setting SendAlertsOnceMutingPeriodHasEnded. Before, if the field was unset, the API would default the value to true. Now, leaving the value unset will result in false being sent to the API server. I think this is a reasonable tradeoff given that it was previously impossible to set the value to false, but let me know if you disagree.

spenceral commented 1 year ago

Fair enough!