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 RabbitMQ test to use ReporterV2 interface #10827

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
22 changes: 14 additions & 8 deletions metricbeat/module/rabbitmq/metricset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ package rabbitmq
import (
"testing"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"

"github.com/elastic/beats/metricbeat/mb"
mbtest "github.com/elastic/beats/metricbeat/mb/testing"
"github.com/elastic/beats/metricbeat/module/rabbitmq/mtest"

"github.com/stretchr/testify/assert"
)

var logger = logp.NewLogger("rabbitmq")

func init() {
mb.Registry.MustAddMetricSet("rabbitmq", "test", newTestMetricSet,
mb.WithHostParser(HostParser),
Expand All @@ -47,9 +48,12 @@ func newTestMetricSet(base mb.BaseMetricSet) (mb.MetricSet, error) {
}

// Fetch makes an HTTP request to fetch connections metrics from the connections endpoint.
func (m *testMetricSet) Fetch() ([]common.MapStr, error) {
func (m *testMetricSet) Fetch(reporter mb.ReporterV2) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, why we have a fetch function here in the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeap, this is weird. I have no idea. Maybe it's related with the fact that this modules uses mocked data https://github.com/elastic/beats/tree/master/metricbeat/module/rabbitmq/_meta/testdata

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

func TestManagementPathPrefix(t *testing.T) {
Expand All @@ -66,7 +70,9 @@ func TestManagementPathPrefix(t *testing.T) {
pathConfigKey: "/management_prefix",
}

f := mbtest.NewEventsFetcher(t, config)
_, err := f.Fetch()
assert.NoError(t, err)
f := mbtest.NewReportingMetricSetV2(t, config)
_, errs := mbtest.ReportingFetchV2(f)
if len(errs) > 0 {
t.Fatalf("Expected 0 error, had %d. %v\n", len(errs), errs)
}
}