Skip to content
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 defaults for autopilot config update #10559

Conversation

jkirschner-hashicorp
Copy link
Contributor

Closes #10558

Previously, for a POST request to the /v1/operator/autopilot/configuration
endpoint, any fields not included in the payload were set to a zero-initialized
value rather than the documented default value.

Now, if an optional field is not included in the payload, it will be set to its
documented default value:

- CleanupDeadServers:      true
- LastContactThreshold:    "200ms"
- MaxTrailingLogs:         250
- MinQuorum:               0
- ServerStabilizationTime: "10s"
- RedundancyZoneTag:       ""
- DisableUpgradeMigration: false
- UpgradeVersionTag:       ""

@jkirschner-hashicorp jkirschner-hashicorp added type/bug Feature does not function as expected theme/api Relating to the HTTP API interface labels Jul 6, 2021
@vercel vercel bot temporarily deployed to Preview – consul July 6, 2021 15:20 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging July 6, 2021 15:20 Inactive
@vercel vercel bot temporarily deployed to Preview – consul July 6, 2021 15:26 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging July 6, 2021 15:26 Inactive
Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks good, just a couple small comments

Comment on lines 459 to 463
if reply.LastContactThreshold != 200 * time.Millisecond ||
reply.MaxTrailingLogs != 250 ||
reply.ServerStabilizationTime != 10 * time.Second {
t.Fatalf("optional parameters not set to defaults: %#v", reply)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This particular test uses the stdlib style of checking values but most of our new tests use testify/require. The linter is complaining about the formatting here, but I think instead of simply fixing the formatting using the following would make for a stricter test:

expected := structs.AutopilotConfig{
...
}
require.Equal(t, expected, reply)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that comparing all fields would be a much better test

@@ -0,0 +1,3 @@
```release-note:bug
api: Fix default values used for optional fields in autopilot configuration update (POST to `/v1/operator/autopilot/configuration`) [[GH-10558](https://github.com/hashicorp/consul/issues/10558)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the changelog tool will add the github link for us. I guess it's not strictly necessary to remove it, just an FYI that you don't need to add it

Suggested change
api: Fix default values used for optional fields in autopilot configuration update (POST to `/v1/operator/autopilot/configuration`) [[GH-10558](https://github.com/hashicorp/consul/issues/10558)]
api: Fix default values used for optional fields in autopilot configuration update (POST to `/v1/operator/autopilot/configuration`)

Comment on lines 61 to 63
func NewAutopilotConfiguration() AutopilotConfiguration {
// Defines default values for this type, consistent with
// https://www.consul.io/api-docs/operator/autopilot#parameters-1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally it is preferred to use godoc comments instead of inline comments. Godoc comments will end up in the generated docs at https://pkg.go.dev/github.com/hashicorp/consul/api. More details here: https://blog.golang.org/godoc

Suggested change
func NewAutopilotConfiguration() AutopilotConfiguration {
// Defines default values for this type, consistent with
// https://www.consul.io/api-docs/operator/autopilot#parameters-1
// NewAutopilotConfiguration returns a AutopilotConfiguration with all fields set to the default values.
// See https://www.consul.io/api-docs/operator/autopilot#parameters-1
func NewAutopilotConfiguration() AutopilotConfiguration {

@jkirschner-hashicorp
Copy link
Contributor Author

Will address these comments later today - thanks!

Previously, for a POST request to the /v1/operator/autopilot/configuration
endpoint, any fields not included in the payload were set to a zero-initialized
value rather than the documented default value.

Now, if an optional field is not included in the payload, it will be set to its
documented default value:
- CleanupDeadServers:      true
- LastContactThreshold:    "200ms"
- MaxTrailingLogs:         250
- MinQuorum:               0
- ServerStabilizationTime: "10s"
- RedundancyZoneTag:       ""
- DisableUpgradeMigration: false
- UpgradeVersionTag:       ""
@jkirschner-hashicorp jkirschner-hashicorp force-pushed the fix-autopilot-config-post-default-values branch from 8468d4b to 1353ee4 Compare July 6, 2021 22:39
@vercel vercel bot temporarily deployed to Preview – consul July 6, 2021 22:39 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging July 6, 2021 22:39 Inactive
@@ -58,6 +58,23 @@ type AutopilotConfiguration struct {
ModifyIndex uint64
}

// Defines default values for the AutopilotConfiguration type, consistent with
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved function description above declaration, per review

body := bytes.NewBuffer([]byte(`{"CleanupDeadServers": false}`))
expected := structs.AutopilotConfig{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved test by forcing comparison of full configuration object (except CreateIndex and ModifyIndex), per review

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: I got a bit tripped up between AutopilotConfig and AutopilotConfiguration

Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jkirschner-hashicorp jkirschner-hashicorp merged commit e517e74 into hashicorp:master Jul 6, 2021
@jkirschner-hashicorp jkirschner-hashicorp deleted the fix-autopilot-config-post-default-values branch July 6, 2021 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/api Relating to the HTTP API interface type/bug Feature does not function as expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autopilot: PUT to /v1/operator/autopilot/configuration sets unspecified params to zero/false
2 participants