Skip to content

Commit

Permalink
[metricbeat] Migrate nginx/substatus to reporterv2 with error (#13518)
Browse files Browse the repository at this point in the history
* migrate nginx/substatus to reporterv2 with error
  • Loading branch information
fearful-symmetry authored Sep 6, 2019
1 parent 44f4b3f commit 0d7adb0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions metricbeat/module/nginx/stubstatus/stubstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package stubstatus

import (
"github.com/pkg/errors"

"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/metricbeat/helper"
"github.com/elastic/beats/metricbeat/mb"
Expand Down Expand Up @@ -73,15 +75,13 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, 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) {
func (m *MetricSet) Fetch(reporter mb.ReporterV2) error {
scanner, err := m.http.FetchScanner()
if err != nil {
logger.Error(err)
reporter.Error(err)
return
return errors.Wrap(err, "error fetching status")
}
event, _ := eventMapping(scanner, m)
reporter.Event(mb.Event{MetricSetFields: event})

return
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
func TestFetch(t *testing.T) {
service := compose.EnsureUp(t, "nginx")

f := mbtest.NewReportingMetricSetV2(t, getConfig(service.Host()))
events, errs := mbtest.ReportingFetchV2(f)
f := mbtest.NewReportingMetricSetV2Error(t, getConfig(service.Host()))
events, errs := mbtest.ReportingFetchV2Error(f)
if len(errs) > 0 {
t.Fatalf("Expected 0 error, had %d. %v\n", len(errs), errs)
}
Expand All @@ -48,8 +48,8 @@ func TestFetch(t *testing.T) {
func TestData(t *testing.T) {
service := compose.EnsureUp(t, "nginx")

f := mbtest.NewReportingMetricSetV2(t, getConfig(service.Host()))
if err := mbtest.WriteEventsReporterV2(f, t, ""); err != nil {
f := mbtest.NewReportingMetricSetV2Error(t, getConfig(service.Host()))
if err := mbtest.WriteEventsReporterV2Error(f, t, ""); err != nil {
t.Fatal("write", err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/tests/system/test_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_modules_test_error(self):
assert exit_code == 0
try:
assert any((
self.log_contains("ERROR error making http request"),
self.log_contains("ERROR error fetching status"),
self.log_contains("ERROR timeout waiting for an event"),
))
except:
Expand Down

0 comments on commit 0d7adb0

Please sign in to comment.