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 container Metricset to use ReporterV2 interface #10855

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
29 changes: 21 additions & 8 deletions metricbeat/module/kubernetes/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
package container

import (
"github.com/elastic/beats/libbeat/common"
"github.com/pkg/errors"

"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 @@ -35,6 +37,8 @@ var (
DefaultScheme: defaultScheme,
DefaultPath: defaultPath,
}.Build()

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

// init registers the MetricSet with the central registry.
Expand Down Expand Up @@ -71,25 +75,34 @@ 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
err = errors.Wrap(err, "error doing HTTP request to fetch 'container' Metricset data")
logger.Error(err)
kaiyan-sheng marked this conversation as resolved.
Show resolved Hide resolved
reporter.Error(err)
return
}

events, err := eventMapping(body, util.PerfMetrics)
if err != nil {
return nil, err
logger.Error(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

should we add a err= errors.wrap(err, "eventMapping failed") here to give more content?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. I'm not sure about it because I usually like to print errors that are relevant for the users (not for us) to help them fix their config issues or similar things.

But I'm also sure that I'm not probably consistent about this 😄

reporter.Error(err)
return
}

m.enricher.Enrich(events)

return events, nil
for _, e := range events {
reporter.Event(mb.Event{MetricSetFields: e})
}

return
}

// Close stops this metricset
Expand Down