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

[Metricbeat] Migrate Kubernetes node Metricset to use ReporterV2 interface #10856

Merged
Merged
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
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