Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Allow null settings in ES when using SetClusterSetting#74

Merged
nickcanz merged 4 commits intogithub:masterfrom
leosunmo:es-null-settings
Jan 16, 2020
Merged

Allow null settings in ES when using SetClusterSetting#74
nickcanz merged 4 commits intogithub:masterfrom
leosunmo:es-null-settings

Conversation

@leosunmo
Copy link
Copy Markdown
Contributor

@leosunmo leosunmo commented Jan 13, 2020

Sorry I've been sitting on this one for a while, got busy.

This adds the ability to "null" settings when using SetClusterSetting().
fixes #68

The function signature is now

SetClusterSetting(setting string, value *string) (*string, *string, error)

and if you pass a nil *string as the new value it will reset that setting in Elasticsearch to its default value.

It also returns a *string as the existingValue and newValue. This allows you to save the original state of a potential null/unset setting and use it in a second call to SetClusterSetting() to reset the original state after the operation has finished.

oldSetting, _, err := v.SetClusterSetting("indices.recovery.max_bytes_per_sec", "1000mb")
  if err != nil {
    log.Printf("failed to set recovery max bytes cluster setting")
    return
}
defer func() {
  v.SetClusterSetting("indices.recovery.max_bytes_per_sec", oldSetting)
}()

In this example the indices.recovery.max_bytes_per_sec is probably unset (default) and should be reset to its null state when the shard migration is complete.

Other random stuff:

  • Added debug message if there's an issue in the test server function buildTestServer, I had an extra space in the body and it took me way too long to figure it out.
  • Added a small check to the integration test script file.
  • Added stringToPointer(v string) *string helper function.
  • New go.mod entry for github.com/spf13/pflag, not sure how this one wasn't already there as it's required by github.com/spf13/cobra.

Passes unit tests and integration tests.

This function now takes *string where a nil value is treated as a JSON null value.
It allows you to pass the nil *string that is returned as "existingValue" back in as the "newValue" to reset it at the end of an operation.

This allows you to "remove" settings by setting them to JSON null. This is the recommended way to remove an explicit configuration to
fall back to defaults in Elasticsearch.
This implements the new "null"ing function in the CLI to allow the user to reset a configuration back to its defaults by
using the "--remove" flag.

Also adds logic to manage the "--remove" and "--value|-v" flags.

Adds a helper function to print nil *strings in a nicer manner.
go mod why:
github.com/github/vulcanizer/pkg/cli
github.com/spf13/cobra
github.com/spf13/pflag
Add a check at the beginning of integration check to make sure vm.max_map_count is set correctly as it will cause silent Elasticsearch Docker failures otherwise
Copy link
Copy Markdown
Contributor

@nickcanz nickcanz left a comment

Choose a reason for hiding this comment

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

Thanks a lot @leosunmo, this looks great!

@nickcanz nickcanz merged commit 2d6113a into github:master Jan 16, 2020
@leosunmo leosunmo deleted the es-null-settings branch June 15, 2020 08:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow setting cluster settings to null

2 participants