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 elasticsearch v8 cluster_settings unmarshal error #915

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

takahisa
Copy link

Closes #840

For example, the result of calling the _cluster/settings API on an off-the-shelf Elasticsearch might look like the following.

GET _cluster/settings?include_defaults | jq '.defaults.cluster.routing.allocation.disk'
{
  "threshold_enabled": "true",
  "watermark": {
    "flood_stage.frozen.max_headroom": "20GB",
    "flood_stage": "95%",
    "high": "90%",
    "low": "85%",
    "enable_for_single_data_node": "false",
    "flood_stage.frozen": "95%"
  },
  "include_relocations": "true",
  "reroute_interval": "60s"
}

When a custom setting related to cluster.routing.allocation.watermark.flood_stage is introduced in transient, the output changes as follows.

GET _cluster/settings?include_defaults | jq '.defaults.cluster.routing.allocation.disk'
{
  "threshold_enabled": "true",
  "watermark": {
    "flood_stage": {
      "frozen": "95%",
      "frozen.max_headroom": "20GB"
    },
    "high": "90%",
    "low": "85%",
    "enable_for_single_data_node": "false"
  },
  "include_relocations": "true",
  "reroute_interval": "60s"
}

As can be seen from this example, the JSON returned by the Elasticsearch _cluster/settings API is not uniform. Therefore, workarounds are necessary to unmarshal it into Go structures. This issue is also pointed out in #509.

This PR addresses the above issue in a general way. When unmarshalling JSON into Go structures, the JSON is converted into a flattened format. The flattened map (i.e., key-value pairs) is then remapped to Go structures using mitchellh/mapstructure. By doing this, it ensures that even non-uniform JSON can be unmarshalled reliably.

@sysadmind
Copy link
Contributor

I don't have time to do a full review at this moment, but I am always hesitant of adding more dependencies. Particularly in this case, the mapstructure project has been archived and no longer supported: https://github.com/mitchellh/mapstructure.

At a minimum, this would need to be a supported project for a dependency. I'll try to circle back to give a full review soon.

@takahisa
Copy link
Author

takahisa commented Aug 5, 2024

@sysadmind
Thank you for your comment. I've got it.
I would appreciate it if you could leave a review when you have time.

Particularly in this case, the mapstructure project has been archived and no longer supported: https://github.com/mitchellh/mapstructure.

Oh, sorry. Since the use of mapstructure is not an essential part, it can be removed. I will try removing the dependency on mapstructure and creating the PR again.

@sdevineau
Copy link

I came accross #840 in last version of the exporter, any idea when this fix could be available ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

elasticsearchv8 cluster_settings unmarshal error
3 participants