From aa7fdabe915856e78cb513db1746f5581a4711b1 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 10 Apr 2019 17:29:32 -0700 Subject: [PATCH] Refactoring: use logger from base metricset --- metricbeat/module/elasticsearch/ccr/ccr.go | 14 +++++++------- .../elasticsearch/cluster_stats/cluster_stats.go | 8 ++++---- metricbeat/module/elasticsearch/index/index.go | 10 +++++----- .../elasticsearch/index_recovery/index_recovery.go | 10 +++++----- .../elasticsearch/index_summary/index_summary.go | 10 +++++----- metricbeat/module/elasticsearch/metricset.go | 3 --- metricbeat/module/elasticsearch/ml_job/ml_job.go | 10 +++++----- metricbeat/module/elasticsearch/node/node.go | 6 +++--- .../module/elasticsearch/node_stats/node_stats.go | 8 ++++---- .../elasticsearch/pending_tasks/pending_tasks.go | 10 +++++----- metricbeat/module/elasticsearch/shard/shard.go | 8 ++++---- metricbeat/module/kibana/metricset.go | 3 --- metricbeat/module/kibana/stats/stats.go | 10 +++++----- metricbeat/module/kibana/status/status.go | 4 ++-- metricbeat/module/logstash/logstash.go | 3 --- metricbeat/module/logstash/node/node.go | 4 ++-- .../module/logstash/node_stats/node_stats.go | 4 ++-- 17 files changed, 58 insertions(+), 67 deletions(-) diff --git a/metricbeat/module/elasticsearch/ccr/ccr.go b/metricbeat/module/elasticsearch/ccr/ccr.go index 871237d85cf..ccd27112bf3 100644 --- a/metricbeat/module/elasticsearch/ccr/ccr.go +++ b/metricbeat/module/elasticsearch/ccr/ccr.go @@ -60,19 +60,19 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) { isMaster, err := elasticsearch.IsMaster(m.HTTP, m.GetServiceURI()) if err != nil { err = errors.Wrap(err, "error determining if connected Elasticsearch node is master") - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } // Not master, no event sent if !isMaster { - m.Log.Debug("trying to fetch ccr stats from a non-master node") + m.Logger().Debug("trying to fetch ccr stats from a non-master node") return } info, err := elasticsearch.GetInfo(m.HTTP, m.GetServiceURI()) if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } @@ -81,14 +81,14 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) { ccrUnavailableMessage, err := m.checkCCRAvailability(info.Version.Number) if err != nil { err = errors.Wrap(err, "error determining if CCR is available") - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } if ccrUnavailableMessage != "" { if time.Since(m.lastCCRLicenseMessageTimestamp) > 1*time.Minute { err := fmt.Errorf(ccrUnavailableMessage) - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) m.lastCCRLicenseMessageTimestamp = time.Now() } return @@ -96,7 +96,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) { content, err := m.HTTP.FetchContent() if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } @@ -107,7 +107,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) { } if err != nil { - m.Log.Error(err) + m.Logger().Error(err) return } } diff --git a/metricbeat/module/elasticsearch/cluster_stats/cluster_stats.go b/metricbeat/module/elasticsearch/cluster_stats/cluster_stats.go index f5daedd3467..28167c6822d 100644 --- a/metricbeat/module/elasticsearch/cluster_stats/cluster_stats.go +++ b/metricbeat/module/elasticsearch/cluster_stats/cluster_stats.go @@ -55,19 +55,19 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) { isMaster, err := elasticsearch.IsMaster(m.HTTP, m.HostData().SanitizedURI+clusterStatsPath) if err != nil { err := errors.Wrap(err, "error determining if connected Elasticsearch node is master") - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } // Not master, no event sent if !isMaster { - m.Log.Debug("trying to fetch cluster stats from a non-master node") + m.Logger().Debug("trying to fetch cluster stats from a non-master node") return } content, err := m.HTTP.FetchContent() if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } @@ -84,6 +84,6 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) { } if err != nil { - m.Log.Error(err) + m.Logger().Error(err) } } diff --git a/metricbeat/module/elasticsearch/index/index.go b/metricbeat/module/elasticsearch/index/index.go index c97df268baa..c426443aec8 100644 --- a/metricbeat/module/elasticsearch/index/index.go +++ b/metricbeat/module/elasticsearch/index/index.go @@ -60,26 +60,26 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) { isMaster, err := elasticsearch.IsMaster(m.HTTP, m.HostData().SanitizedURI+statsPath) if err != nil { err = errors.Wrap(err, "error determining if connected Elasticsearch node is master") - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } // Not master, no event sent if !isMaster { - m.Log.Debug("trying to fetch index stats from a non-master node") + m.Logger().Debug("trying to fetch index stats from a non-master node") return } content, err := m.HTTP.FetchContent() if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } info, err := elasticsearch.GetInfo(m.HTTP, m.HostData().SanitizedURI) if err != nil { err = errors.Wrap(err, "failed to get info from Elasticsearch") - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } @@ -90,7 +90,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) { } if err != nil { - m.Log.Error(err) + m.Logger().Error(err) return } } diff --git a/metricbeat/module/elasticsearch/index_recovery/index_recovery.go b/metricbeat/module/elasticsearch/index_recovery/index_recovery.go index 50ee9e45f1c..5eb9e36612d 100644 --- a/metricbeat/module/elasticsearch/index_recovery/index_recovery.go +++ b/metricbeat/module/elasticsearch/index_recovery/index_recovery.go @@ -71,25 +71,25 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) { isMaster, err := elasticsearch.IsMaster(m.HTTP, m.GetServiceURI()) if err != nil { err = errors.Wrap(err, "error determining if connected Elasticsearch node is master") - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } // Not master, no event sent if !isMaster { - m.Log.Debug("trying to fetch index recovery stats from a non-master node") + m.Logger().Debug("trying to fetch index recovery stats from a non-master node") return } info, err := elasticsearch.GetInfo(m.HTTP, m.GetServiceURI()) if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } content, err := m.HTTP.FetchContent() if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } @@ -100,7 +100,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) { } if err != nil { - m.Log.Error(err) + m.Logger().Error(err) return } } diff --git a/metricbeat/module/elasticsearch/index_summary/index_summary.go b/metricbeat/module/elasticsearch/index_summary/index_summary.go index 0e59c677082..665732492c8 100644 --- a/metricbeat/module/elasticsearch/index_summary/index_summary.go +++ b/metricbeat/module/elasticsearch/index_summary/index_summary.go @@ -66,26 +66,26 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) { isMaster, err := elasticsearch.IsMaster(m.HTTP, m.HostData().SanitizedURI+statsPath) if err != nil { err = errors.Wrap(err, "error determining if connected Elasticsearch node is master") - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } // Not master, no event sent if !isMaster { - m.Log.Debug("trying to fetch index summary stats from a non-master node") + m.Logger().Debug("trying to fetch index summary stats from a non-master node") return } content, err := m.HTTP.FetchContent() if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } info, err := elasticsearch.GetInfo(m.HTTP, m.HostData().SanitizedURI+statsPath) if err != nil { err = errors.Wrap(err, "failed to get info from Elasticsearch") - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } @@ -96,7 +96,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) { } if err != nil { - m.Log.Error(err) + m.Logger().Error(err) return } } diff --git a/metricbeat/module/elasticsearch/metricset.go b/metricbeat/module/elasticsearch/metricset.go index d7965647ec0..7477337adf7 100644 --- a/metricbeat/module/elasticsearch/metricset.go +++ b/metricbeat/module/elasticsearch/metricset.go @@ -18,7 +18,6 @@ package elasticsearch import ( - "github.com/elastic/beats/libbeat/logp" "github.com/elastic/beats/metricbeat/helper" "github.com/elastic/beats/metricbeat/mb" "github.com/elastic/beats/metricbeat/mb/parse" @@ -44,7 +43,6 @@ type MetricSet struct { servicePath string *helper.HTTP XPack bool - Log *logp.Logger } // NewMetricSet creates an metric set that can be used to build other metric @@ -69,7 +67,6 @@ func NewMetricSet(base mb.BaseMetricSet, servicePath string) (*MetricSet, error) servicePath, http, config.XPack, - logp.NewLogger(ModuleName), } ms.SetServiceURI(servicePath) diff --git a/metricbeat/module/elasticsearch/ml_job/ml_job.go b/metricbeat/module/elasticsearch/ml_job/ml_job.go index e885a099484..923063f7279 100644 --- a/metricbeat/module/elasticsearch/ml_job/ml_job.go +++ b/metricbeat/module/elasticsearch/ml_job/ml_job.go @@ -59,19 +59,19 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) { isMaster, err := elasticsearch.IsMaster(m.HTTP, m.GetServiceURI()) if err != nil { err = errors.Wrap(err, "error determining if connected Elasticsearch node is master") - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } // Not master, no event sent if !isMaster { - m.Log.Debug("trying to fetch machine learning job stats from a non-master node") + m.Logger().Debug("trying to fetch machine learning job stats from a non-master node") return } info, err := elasticsearch.GetInfo(m.HTTP, m.GetServiceURI()) if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } @@ -83,7 +83,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) { content, err := m.HTTP.FetchContent() if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } @@ -94,7 +94,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) { } if err != nil { - m.Log.Error(err) + m.Logger().Error(err) return } } diff --git a/metricbeat/module/elasticsearch/node/node.go b/metricbeat/module/elasticsearch/node/node.go index 8eb0c635bfe..9ca5fd6430e 100644 --- a/metricbeat/module/elasticsearch/node/node.go +++ b/metricbeat/module/elasticsearch/node/node.go @@ -67,20 +67,20 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(r mb.ReporterV2) { content, err := m.HTTP.FetchContent() if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } info, err := elasticsearch.GetInfo(m.HTTP, m.HostData().SanitizedURI+nodeStatsPath) if err != nil { err = errors.Wrap(err, "failed to get info from Elasticsearch") - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } err = eventsMapping(r, *info, content) if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } } diff --git a/metricbeat/module/elasticsearch/node_stats/node_stats.go b/metricbeat/module/elasticsearch/node_stats/node_stats.go index 5c7e23906d0..170f926708d 100644 --- a/metricbeat/module/elasticsearch/node_stats/node_stats.go +++ b/metricbeat/module/elasticsearch/node_stats/node_stats.go @@ -56,26 +56,26 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(r mb.ReporterV2) { content, err := m.HTTP.FetchContent() if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } info, err := elasticsearch.GetInfo(m.HTTP, m.GetServiceURI()) if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } if m.XPack { err = eventsMappingXPack(r, m, *info, content) if err != nil { - m.Log.Error(err) + m.Logger().Error(err) return } } else { err = eventsMapping(r, *info, content) if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } } diff --git a/metricbeat/module/elasticsearch/pending_tasks/pending_tasks.go b/metricbeat/module/elasticsearch/pending_tasks/pending_tasks.go index e3729f504a4..512bc91ee0c 100644 --- a/metricbeat/module/elasticsearch/pending_tasks/pending_tasks.go +++ b/metricbeat/module/elasticsearch/pending_tasks/pending_tasks.go @@ -63,31 +63,31 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) { isMaster, err := elasticsearch.IsMaster(m.HTTP, m.GetServiceURI()) if err != nil { err := errors.Wrap(err, "error determining if connected Elasticsearch node is master") - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } // Not master, no event sent if !isMaster { - m.Log.Debug("trying to fetch pending tasks from a non-master node") + m.Logger().Debug("trying to fetch pending tasks from a non-master node") return } info, err := elasticsearch.GetInfo(m.HTTP, m.GetServiceURI()) if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } content, err := m.HTTP.FetchContent() if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } err = eventsMapping(r, *info, content) if err != nil { - m.Log.Error(err) + m.Logger().Error(err) return } } diff --git a/metricbeat/module/elasticsearch/shard/shard.go b/metricbeat/module/elasticsearch/shard/shard.go index bb47d587808..8ab206a7add 100644 --- a/metricbeat/module/elasticsearch/shard/shard.go +++ b/metricbeat/module/elasticsearch/shard/shard.go @@ -57,19 +57,19 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) { isMaster, err := elasticsearch.IsMaster(m.HTTP, m.HostData().SanitizedURI+statePath) if err != nil { err := errors.Wrap(err, "error determining if connected Elasticsearch node is master") - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } // Not master, no event sent if !isMaster { - m.Log.Debug("trying to fetch shard stats from a non-master node") + m.Logger().Debug("trying to fetch shard stats from a non-master node") return } content, err := m.HTTP.FetchContent() if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } @@ -80,7 +80,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) { } if err != nil { - m.Log.Error(err) + m.Logger().Error(err) return } } diff --git a/metricbeat/module/kibana/metricset.go b/metricbeat/module/kibana/metricset.go index a4979133c21..f099bd77575 100644 --- a/metricbeat/module/kibana/metricset.go +++ b/metricbeat/module/kibana/metricset.go @@ -18,7 +18,6 @@ package kibana import ( - "github.com/elastic/beats/libbeat/logp" "github.com/elastic/beats/metricbeat/mb" ) @@ -26,7 +25,6 @@ import ( type MetricSet struct { mb.BaseMetricSet XPackEnabled bool - Log *logp.Logger } // NewMetricSet creates a metricset that can be used to build other metricsets @@ -40,6 +38,5 @@ func NewMetricSet(base mb.BaseMetricSet) (*MetricSet, error) { return &MetricSet{ base, config.XPackEnabled, - logp.NewLogger(ModuleName), }, nil } diff --git a/metricbeat/module/kibana/stats/stats.go b/metricbeat/module/kibana/stats/stats.go index b4526b9536d..acfed8c7a69 100644 --- a/metricbeat/module/kibana/stats/stats.go +++ b/metricbeat/module/kibana/stats/stats.go @@ -134,7 +134,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) { func (m *MetricSet) fetchStats(r mb.ReporterV2, now time.Time) { content, err := m.statsHTTP.FetchContent() if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } @@ -142,13 +142,13 @@ func (m *MetricSet) fetchStats(r mb.ReporterV2, now time.Time) { intervalMs := m.calculateIntervalMs() err = eventMappingStatsXPack(r, intervalMs, now, content) if err != nil { - m.Log.Error(err) + m.Logger().Error(err) return } } else { err = eventMapping(r, content) if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } } @@ -157,14 +157,14 @@ func (m *MetricSet) fetchStats(r mb.ReporterV2, now time.Time) { func (m *MetricSet) fetchSettings(r mb.ReporterV2, now time.Time) { content, err := m.settingsHTTP.FetchContent() if err != nil { - m.Log.Error(err) + m.Logger().Error(err) return } intervalMs := m.calculateIntervalMs() err = eventMappingSettingsXPack(r, intervalMs, now, content) if err != nil { - m.Log.Error(err) + m.Logger().Error(err) return } } diff --git a/metricbeat/module/kibana/status/status.go b/metricbeat/module/kibana/status/status.go index 65c36bdd3ed..96bc5eeddcd 100644 --- a/metricbeat/module/kibana/status/status.go +++ b/metricbeat/module/kibana/status/status.go @@ -72,14 +72,14 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(r mb.ReporterV2) { content, err := m.http.FetchContent() if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } err = eventMapping(r, content) if err != nil { - m.Log.Error(err) + m.Logger().Error(err) return } } diff --git a/metricbeat/module/logstash/logstash.go b/metricbeat/module/logstash/logstash.go index e1a35d67caa..4210afdff5e 100644 --- a/metricbeat/module/logstash/logstash.go +++ b/metricbeat/module/logstash/logstash.go @@ -18,7 +18,6 @@ package logstash import ( - "github.com/elastic/beats/libbeat/logp" "github.com/elastic/beats/metricbeat/mb" ) @@ -28,7 +27,6 @@ const ModuleName = "logstash" // MetricSet can be used to build other metricsets within the Logstash module. type MetricSet struct { mb.BaseMetricSet - Log *logp.Logger } // NewMetricSet creates a metricset that can be used to build other metricsets @@ -36,6 +34,5 @@ type MetricSet struct { func NewMetricSet(base mb.BaseMetricSet) (*MetricSet, error) { return &MetricSet{ base, - logp.NewLogger(ModuleName), }, nil } diff --git a/metricbeat/module/logstash/node/node.go b/metricbeat/module/logstash/node/node.go index 0a641b5eda9..db0cef279d5 100644 --- a/metricbeat/module/logstash/node/node.go +++ b/metricbeat/module/logstash/node/node.go @@ -72,13 +72,13 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(r mb.ReporterV2) { content, err := m.http.FetchContent() if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } err = eventMapping(r, content) if err != nil { - m.Log.Error(err) + m.Logger().Error(err) return } } diff --git a/metricbeat/module/logstash/node_stats/node_stats.go b/metricbeat/module/logstash/node_stats/node_stats.go index 8af52dd7896..373ca22add2 100644 --- a/metricbeat/module/logstash/node_stats/node_stats.go +++ b/metricbeat/module/logstash/node_stats/node_stats.go @@ -73,13 +73,13 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(r mb.ReporterV2) { content, err := m.http.FetchContent() if err != nil { - elastic.ReportAndLogError(err, r, m.Log) + elastic.ReportAndLogError(err, r, m.Logger()) return } err = eventMapping(r, content) if err != nil { - m.Log.Error(err) + m.Logger().Error(err) return } }