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

Refactoring: use logger from base metricset #11754

Merged
merged 1 commit into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions metricbeat/module/elasticsearch/ccr/ccr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Copy link
Member

Choose a reason for hiding this comment

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

Why not directly go to func (m *MetricSet) Fetch(r mb.ReporterV2) error { interface and return the error so you don't have to do this additional code as the new interface will do it for you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I was planning on putting up a PR following your work in #10727 today.

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())
Copy link
Member

Choose a reason for hiding this comment

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

See comment above.

return
}

Expand All @@ -81,22 +81,22 @@ 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())
Copy link
Member

Choose a reason for hiding this comment

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

See comment above.

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
}

content, err := m.HTTP.FetchContent()
if err != nil {
elastic.ReportAndLogError(err, r, m.Log)
elastic.ReportAndLogError(err, r, m.Logger())
return
}

Expand All @@ -107,7 +107,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) {
}

if err != nil {
m.Log.Error(err)
m.Logger().Error(err)
return
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -84,6 +84,6 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) {
}

if err != nil {
m.Log.Error(err)
m.Logger().Error(err)
}
}
10 changes: 5 additions & 5 deletions metricbeat/module/elasticsearch/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -90,7 +90,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) {
}

if err != nil {
m.Log.Error(err)
m.Logger().Error(err)
return
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -100,7 +100,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) {
}

if err != nil {
m.Log.Error(err)
m.Logger().Error(err)
return
}
}
10 changes: 5 additions & 5 deletions metricbeat/module/elasticsearch/index_summary/index_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -96,7 +96,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) {
}

if err != nil {
m.Log.Error(err)
m.Logger().Error(err)
return
}
}
3 changes: 0 additions & 3 deletions metricbeat/module/elasticsearch/metricset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -69,7 +67,6 @@ func NewMetricSet(base mb.BaseMetricSet, servicePath string) (*MetricSet, error)
servicePath,
http,
config.XPack,
logp.NewLogger(ModuleName),
}

ms.SetServiceURI(servicePath)
Expand Down
10 changes: 5 additions & 5 deletions metricbeat/module/elasticsearch/ml_job/ml_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -94,7 +94,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) {
}

if err != nil {
m.Log.Error(err)
m.Logger().Error(err)
return
}
}
6 changes: 3 additions & 3 deletions metricbeat/module/elasticsearch/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
8 changes: 4 additions & 4 deletions metricbeat/module/elasticsearch/node_stats/node_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
10 changes: 5 additions & 5 deletions metricbeat/module/elasticsearch/pending_tasks/pending_tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
8 changes: 4 additions & 4 deletions metricbeat/module/elasticsearch/shard/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -80,7 +80,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) {
}

if err != nil {
m.Log.Error(err)
m.Logger().Error(err)
return
}
}
Loading