Exclude expires field from federation definition when value is zero. #154
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
How to deal with default values, especially for federation definition attributes like
expires
andmessage-ttl
?This is a follow up to a question I buried in the Federation Runtime Parameters PR.
Turns out, that the go zero value of
0
forexpires
(int
type) throws an error when the federation link is created. The docs state that it must be a positive integer. This is not captured by any current tests, since it only happens when you also create a policy that matches a federation upstream and then view the status of the link that is created.I suspected this would become an issue but it only came to light when doing a complete end-to-end test using the
terraform-provider-rabbitmq
.Here is an example of the error returned:
The easiest way to resolve this is to add the
omitempty
tag to theexpires
field (0
is a valid value formessage_ttl
). This resolves the error when creating an upstream, which I think is sufficient at this time.Comments
The following comments are just some additional thoughts. I'm not suggesting any other changes to this PR.
Because of the way zero values work, the
Expires:0
is there again when theFederationDefinition
is read. I'm not sure if this needs to be changed, but it you wanted to, it may require changing the field type (tostring
) and introducing more robust checks for valid numeric values, etc.Should other optional fields also include the
omitempty
flag? To ensure valid default values forprefetch-count
orreconnect-delay
, I set the recommended defaults in the terraform provider, otherwise the go zero value of0
would be set instead of the recommended default value. However, onlyexpires
actually results in an error, which is why I changed it.I was unsure how to test for this scenario. If the API included support for
federation-links
, perhaps it would be possible to check the status of the link in an end-to-end test (but using a single broker)? You could add this feature quite easily by marshalling to aninterface{}
instead of a predefined struct type, since the response for a federation link has numerous fields. Alternatively, you could select only the most important attributes as fields. If you think this feature is worth adding, then I can pursue it as part of a separate PR. See Added federation-links endpoints #155