Skip to content

Commit

Permalink
Only fetch shard metrics from master node (#7635)
Browse files Browse the repository at this point in the history
This PR makes it so that the `elasticsearch/shard` metricset only fetches information from the Elasticsearch node if that node is the master node.
  • Loading branch information
ycombinator authored and ruflin committed Jul 19, 2018
1 parent efb1b2a commit 182bddd
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion metricbeat/module/elasticsearch/shard/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
package shard

import (
"fmt"

"github.com/elastic/beats/libbeat/common/cfgwarn"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/metricbeat/mb"
"github.com/elastic/beats/metricbeat/module/elasticsearch"
)
Expand All @@ -32,7 +35,6 @@ func init() {
}

const (
// Get the stats from the local node
statePath = "/_cluster/state/version,master_node,routing_table"
)

Expand All @@ -55,6 +57,18 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {

// Fetch methods implements the data gathering and data conversion to the right format
func (m *MetricSet) Fetch(r mb.ReporterV2) {
isMaster, err := elasticsearch.IsMaster(m.HTTP, m.HostData().SanitizedURI+statePath)
if err != nil {
r.Error(fmt.Errorf("Error fetch master info: %s", err))
return
}

// Not master, no event sent
if !isMaster {
logp.Debug("elasticsearch", "Trying to fetch shard stats from a non master node.")
return
}

content, err := m.HTTP.FetchContent()
if err != nil {
r.Error(err)
Expand Down

0 comments on commit 182bddd

Please sign in to comment.