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

Adding x-pack code for elasticsearch/index metricset #8260

Merged

Conversation

ycombinator
Copy link
Contributor

@ycombinator ycombinator commented Sep 7, 2018

This PR teaches metricbeat to index index_stats documents into .monitoring-es-6-mb-* indices.

@ycombinator ycombinator added in progress Pull request is currently in progress. Metricbeat Metricbeat needs_backport PR is waiting to be backported to other branches. v7.0.0-alpha1 monitoring v6.5.0 labels Sep 7, 2018
@ycombinator ycombinator added review and removed in progress Pull request is currently in progress. labels Sep 7, 2018
Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

I have added some comments, mostly suggestions. There is also a test failing that seems related.

event := mb.Event{}
indexStats, err := xpackSchema.Apply(index)
if err != nil {
continue
Copy link
Member

Choose a reason for hiding this comment

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

log the error here? even if it is only on debug?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the x-pack path, we decided not to report the error (via r mb.ReporterV2) as it would end up in the metricbeat-* index instead of the .monitoring-es-6-mb-* index, where all the other data ends up.

However, I think you are referring to logging the error in the metricbeat log, right?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I refer to logging the error 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 will do that here and other places in this PR where you have noted.

BTW, all the other metricsets (with x-pack monitoring code paths) will need this too so I'm going to make their logging part of a separate PR.

Copy link
Member

Choose a reason for hiding this comment

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

Ok


err = addClusterStateFields(name, indexStats, clusterState)
if err != nil {
continue
Copy link
Member

Choose a reason for hiding this comment

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

log error?

return err
}

// TODO:
Copy link
Member

Choose a reason for hiding this comment

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

Empty TODO? 🙂

// "index_stats.shards.unassigned_primaries",
// "index_stats.shards.unassigned_replicas",
// "index_stats.shards.initializing",
// "index_stats.shards.relocating",
Copy link
Member

Choose a reason for hiding this comment

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

Are these comments needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably not. I was using them to make sure I was computing the same fields that are currently being computed by the internal ES collector. Perhaps I will replace them with a link to the internal ES code, just for future reference?

Copy link
Member

Choose a reason for hiding this comment

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

A comment referencing the source of the list could be nice yes 👍

// "index_stats.version.created", <--- don't think this is being used in the UI, so can we skip it?
// "index_stats.version.upgraded", <--- don't think this is being used in the UI, so can we skip it?

// "index_stats.status",
Copy link
Member

Choose a reason for hiding this comment

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

This comment may indicate that the following lines could be in its own funcion, as you do with getIndexStatus() and getIndexShardsStats() (even if here it'd be a smaller function). The same for index_stats.created before.

// "index_stats.shards.relocating",
shardStats, err := getIndexShardStats(shards)
if err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

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

This function returns errors in several places, you may want to make use of errors.Wrap() or similar to give more info about when it failed, for example here it could be return errors.Wrap(err, "failed to get index shard stats").

"primaries": {
"docs": {
"count": 1257,
"deleted": 11
Copy link
Member

Choose a reason for hiding this comment

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

We should probably "standardise" on the indentation of .json files. Do you use .editorconfig? https://github.com/elastic/beats/blob/master/.editorconfig#L15

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm guessing I don't right now. I'll look into it so formatting can be standardized.

@@ -33,7 +33,7 @@ func init() {
}

const (
statsPath = "/_stats"
statsPath = "/_stats/docs,fielddata,indexing,merge,search,segments,store,refresh,query_cache,request_cache"
Copy link
Member

Choose a reason for hiding this comment

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

Could we define the "items" as a separate const to separate the path from the params? (I know, technically it's part of the path)

@ycombinator
Copy link
Contributor Author

ycombinator commented Sep 11, 2018

@jsoriano @ruflin Because GitHub will collapse these two comments, I want to re-mention them here:

Besides that, I need to fix the failing CI as well on this PR.

@@ -29,6 +29,10 @@ import (
"github.com/elastic/beats/metricbeat/module/elasticsearch"
)

type IndicesStruct struct {

Choose a reason for hiding this comment

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

exported type IndicesStruct should have comment or be unexported

@ycombinator
Copy link
Contributor Author

The Elasticsearch team has decided not to move forward with elastic/elasticsearch#33614 for now so the logic to compute index status will have to remain in the metricbeat code for now. I've closed the ES PR and removed it as a dependency of this PR.

ycombinator added a commit to elastic/elasticsearch that referenced this pull request Sep 18, 2018
This PR removes fields that are not actually used by the Monitoring UI. This will greatly simplify the eventual migration to using Metricbeat for monitoring Elasticsearch (see elastic/beats#8260 (comment) for more context and discussion around removing these fields from ES collection).
@ycombinator
Copy link
Contributor Author

elastic/elasticsearch#33584, which was a dependency of this PR has now been merged into master. So merging this PR now...

@ycombinator ycombinator merged commit cfee760 into elastic:master Sep 18, 2018
@ycombinator ycombinator deleted the metricbeat-elasticsearch-index-x-pack branch September 18, 2018 01:38
ycombinator added a commit to ycombinator/beats that referenced this pull request Sep 18, 2018
* Updating test fixture

* Extract indicesStruct for reuse within package

* Only request specific stats

* Add X-Pack switch

* Adding explanatory comment

* Fleshing it out some more

* Remove empty TODO

* Adding reference comment for fields + refactoring into helper funcs

* Re-formatting

* Extract stats API metrics into own const

* Using errors.Wrap

* Adding logger to elasticsearch metricset

* Log errors

* Sharing the type not the variable 🤦

(cherry picked from commit cfee760)
@ycombinator ycombinator added v6.5.0 and removed needs_backport PR is waiting to be backported to other branches. labels Sep 18, 2018
ycombinator added a commit to ycombinator/elasticsearch that referenced this pull request Sep 18, 2018
This PR removes fields that are not actually used by the Monitoring UI. This will greatly simplify the eventual migration to using Metricbeat for monitoring Elasticsearch (see elastic/beats#8260 (comment) for more context and discussion around removing these fields from ES collection).
ycombinator added a commit to elastic/elasticsearch that referenced this pull request Sep 18, 2018
* [Monitoring] Removing unused version.* fields (#33584)

This PR removes fields that are not actually used by the Monitoring UI. This will greatly simplify the eventual migration to using Metricbeat for monitoring Elasticsearch (see elastic/beats#8260 (comment) for more context and discussion around removing these fields from ES collection).

* Fixing assertions in integration test
ycombinator added a commit that referenced this pull request Sep 19, 2018
…` metricset (#8337)

Cherry-pick of PR #8260 to 6.x branch. Original message: 

This PR teaches metricbeat to index `index_stats` documents into `.monitoring-es-6-mb-*` indices.
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.

None yet

6 participants