Skip to content

Commit

Permalink
[Metricbeat] Migrate Kubernetes node Metricset to use ReporterV2 inte…
Browse files Browse the repository at this point in the history
…rface
  • Loading branch information
sayden authored Feb 28, 2019
1 parent 218a131 commit 12e2959
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions metricbeat/module/kubernetes/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package node
import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/kubernetes"
"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 @@ -36,6 +37,8 @@ var (
DefaultScheme: defaultScheme,
DefaultPath: defaultPath,
}.Build()

logger = logp.NewLogger("kubernetes.node")
)

// init registers the MetricSet with the central registry.
Expand Down Expand Up @@ -73,25 +76,31 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
}, nil
}

// Fetch methods implements the data gathering and data conversion to the right format
// It returns the event which is then forward to the output. In case of an error, a
// descriptive error must be returned.
func (m *MetricSet) Fetch() (common.MapStr, error) {
// Fetch methods implements the data gathering and data conversion to the right
// format. It publishes the event which is then forwarded to the output. In case
// of an error set the Error field of mb.Event or simply call report.Error().
func (m *MetricSet) Fetch(reporter mb.ReporterV2) {
m.enricher.Start()

body, err := m.http.FetchContent()
if err != nil {
return nil, err
logger.Error(err)
reporter.Error(err)
return
}

event, err := eventMapping(body)
if err != nil {
return nil, err
logger.Error(err)
reporter.Error(err)
return
}

m.enricher.Enrich([]common.MapStr{event})

return event, nil
reporter.Event(mb.Event{MetricSetFields: event})

return
}

// Close stops this metricset
Expand Down

0 comments on commit 12e2959

Please sign in to comment.