Skip to content
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
4 changes: 0 additions & 4 deletions metricbeat/module/ceph/pool_disk/_meta/data.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"@timestamp": "2017-10-12T08:05:34.853Z",
"agent": {
"hostname": "host.example.com",
"name": "host.example.com"
},
"ceph": {
"pool_disk": {
"id": 0,
Expand Down
18 changes: 13 additions & 5 deletions metricbeat/module/ceph/pool_disk/pool_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package pool_disk

import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/metricbeat/helper"
"github.com/elastic/beats/metricbeat/mb"
"github.com/elastic/beats/metricbeat/mb/parse"
Expand Down Expand Up @@ -61,12 +60,21 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
}, nil
}

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) {
content, err := m.HTTP.FetchContent()

if err != nil {
return nil, err
m.Logger().Error(err)
reporter.Error(err)
return
}

events := eventsMapping(content)
for _, event := range events {
reporter.Event(mb.Event{MetricSetFields: event})
}

return eventsMapping(content), nil
return
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
)

func TestData(t *testing.T) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We have realized that this call mbtest.ReportingFetchV2(f) must be omitted here because this test must not be launched in CI and check is happening in mbtest.WriteEventsReporterV2 so it should end up looking more or less like this:

func TestData(t *testing.T) {
	f := mbtest.NewReportingMetricSetV2(t, getConfig())

	if err := mbtest.WriteEventsReporterV2(f, t, ""); err != nil {
		t.Fatal("write", err)
	}
}

This is the only important change here to avoid a flaky test that was happening

f := mbtest.NewEventsFetcher(t, getConfig())
err := mbtest.WriteEvents(f, t)
if err != nil {
f := mbtest.NewReportingMetricSetV2(t, getConfig())

if err := mbtest.WriteEventsReporterV2(f, t, ""); err != nil {
t.Fatal("write", err)
}
}
Expand Down
12 changes: 7 additions & 5 deletions metricbeat/module/ceph/pool_disk/pool_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

func TestFetchEventContents(t *testing.T) {
absPath, err := filepath.Abs("../_meta/testdata/")
assert.NoError(t, err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good catch!


response, err := ioutil.ReadFile(absPath + "/df_sample_response.json")
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -47,12 +48,13 @@ func TestFetchEventContents(t *testing.T) {
"hosts": []string{server.URL},
}

f := mbtest.NewEventsFetcher(t, config)
events, err := f.Fetch()
event := events[0]
if !assert.NoError(t, err) {
t.FailNow()
f := mbtest.NewReportingMetricSetV2(t, config)
events, errs := mbtest.ReportingFetchV2(f)
if len(errs) > 0 {
t.Fatalf("Expected 0 error, had %d. %v\n", len(errs), errs)
}
assert.NotEmpty(t, events)
event := events[0].MetricSetFields

t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), event.StringToPrint())

Expand Down