Exclude expires field from federation definition when value is zero.#154
Merged
michaelklishin merged 1 commit intoMay 30, 2020
Merged
Conversation
- value must be a positive integer.
Owner
|
Travis failures have to do with Bintray host resolution by apt. Testing this locally. |
michaelklishin
approved these changes
May 30, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
expiresandmessage-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
0forexpires(inttype) 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:
curl -i -u guest:guest \ http://localhost:15672/api/federation-links/%2f [ { "node": "rabbit@fb688184ee38", "exchange": "foo", "upstream_exchange": "", "type": "exchange", "vhost": "/", "upstream": "foo", "id": "14362399", "status": "shutdown", "error": "{server_initiated_close,406,\n <<\"PRECONDITION_FAILED - invalid arg 'x-expires' for queue 'federation: -> rabbit@fb688184ee38:foo' in vhost '/': {value_zero,0}\">>}", "uri": "amqp://localhost", "timestamp": "2020-05-26 17:03:04" } ]The easiest way to resolve this is to add the
omitemptytag to theexpiresfield (0is 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:0is there again when theFederationDefinitionis 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
omitemptyflag? To ensure valid default values forprefetch-countorreconnect-delay, I set the recommended defaults in the terraform provider, otherwise the go zero value of0would be set instead of the recommended default value. However, onlyexpiresactually 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