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

Make elasticsearch/index_summary metricset more defensive #12489

Merged
merged 3 commits into from
Jun 11, 2019
Merged

Make elasticsearch/index_summary metricset more defensive #12489

merged 3 commits into from
Jun 11, 2019

Conversation

ycombinator
Copy link
Contributor

@ycombinator ycombinator commented Jun 10, 2019

Resolves #12487.

When there is absolutely no data in an Elasticsearch cluster, the elasticsearch/index_summary metricset, with xpack.enabled: true set, emits the following error in the Metricbeat log:

2019-06-10T03:00:47.439-0700    ERROR   [elasticsearch.index_summary]   index_summary/index_summary.go:92       failure applying stats schema: 8 errors: key `total.docs` not found; key `total.store` not found; key `total.indexing` not found; key `total.search` not found; key `primaries.docs` not found; key `primaries.store` not found; key `primaries.indexing` not found; key `primaries.search` not found

Having absolutely no data in the cluster is a "cold start" edge case that must be handled gracefully. This PR makes it so.

Concretely, this PR:

  • Adds a guard clause to check if the GET _stats API response being used by the elasticsearch/index_summary metricset contains any stats for primary shards. If it doesn't, it doesn't try to parse the API response any further.
  • Does a minor bit of refactoring, reusing the same schema structure in two places to avoid duplication of code.

Testing this PR

  1. Make sure Elasticsearch API is accessible on http://localhost:9200.

  2. Enable the elasticsearch-xpack Metricbeat module.

    ./metricbeat modules enable elasticsearch-xpack
    
  3. Make sure there is no data in Elasticsearch. If there is, make sure nothing is indexing to it, and then run:

    curl -X DELETE 'http://localhost:9200/*'
    
  4. Run Metricbeat.

    ./metricbeat -e
    
  5. Assert that no errors are thrown in the Metricbeat log.

  6. Assert that a .monitoring-es-*mb* index gets created in Elasticsearch.

    curl -s http://localhost:9200/_cat/indices/.monitoring*
    

@elasticmachine
Copy link
Collaborator

Pinging @elastic/stack-monitoring

Copy link
Collaborator

@ruflin ruflin left a comment

Choose a reason for hiding this comment

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

Code LGTM, did not test locally.

Do you want to add a changelog?

Copy link
Contributor

@cachedout cachedout left a comment

Choose a reason for hiding this comment

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

I tested this locally and it behaves as described. 👍

@ycombinator
Copy link
Contributor Author

Added CHANGELOG entry. Will merge when CI goes green again.

@ycombinator
Copy link
Contributor Author

jenkins, test this

@ycombinator ycombinator merged commit 0aaa3a7 into elastic:master Jun 11, 2019
ycombinator added a commit that referenced this pull request Jun 14, 2019
…2489) (#12507)

* Refactoring: extract common schema

* Don't try to parse stats API response further if there is no data in the cluster

* Adding CHANGELOG entry
ycombinator added a commit that referenced this pull request Jun 14, 2019
…2489) (#12508)

* Refactoring: extract common schema

* Don't try to parse stats API response further if there is no data in the cluster

* Adding CHANGELOG entry
@ycombinator ycombinator deleted the mb-es-index-stats-xp branch December 25, 2019 11:19
@ycombinator ycombinator removed the needs_backport PR is waiting to be backported to other branches. label Jan 15, 2020
leweafan pushed a commit to leweafan/beats that referenced this pull request Apr 28, 2023
…astic#12489) (elastic#12507)

* Refactoring: extract common schema

* Don't try to parse stats API response further if there is no data in the cluster

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

Successfully merging this pull request may close these issues.

Error thrown by elasticsearch/index_summary metricset when xpack.enabled is set to true
4 participants