From 48bd5680f4add1bbcd0c5fa432ed22cc5074a8ba Mon Sep 17 00:00:00 2001 From: Alex Kristiansen Date: Thu, 5 Sep 2019 08:41:45 -0700 Subject: [PATCH 1/3] migrate windows/perfmon to reporterv2 with error --- .../windows/perfmon/pdh_integration_windows_test.go | 12 ++++++------ metricbeat/module/windows/perfmon/perfmon.go | 11 ++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/metricbeat/module/windows/perfmon/pdh_integration_windows_test.go b/metricbeat/module/windows/perfmon/pdh_integration_windows_test.go index 18ecaccb493..04e4a5b7b72 100644 --- a/metricbeat/module/windows/perfmon/pdh_integration_windows_test.go +++ b/metricbeat/module/windows/perfmon/pdh_integration_windows_test.go @@ -58,11 +58,11 @@ func TestData(t *testing.T) { }, } - ms := mbtest.NewReportingMetricSetV2(t, config) - mbtest.ReportingFetchV2(ms) + ms := mbtest.NewReportingMetricSetV2Error(t, config) + mbtest.ReportingFetchV2Error(ms) time.Sleep(60 * time.Millisecond) - events, errs := mbtest.ReportingFetchV2(ms) + events, errs := mbtest.ReportingFetchV2Error(ms) if len(errs) > 0 { t.Fatal(errs) } @@ -87,11 +87,11 @@ func TestCounterWithNoInstanceName(t *testing.T) { }, } - ms := mbtest.NewReportingMetricSetV2(t, config) - mbtest.ReportingFetchV2(ms) + ms := mbtest.NewReportingMetricSetV2Error(t, config) + mbtest.ReportingFetchV2Error(ms) time.Sleep(60 * time.Millisecond) - events, errs := mbtest.ReportingFetchV2(ms) + events, errs := mbtest.ReportingFetchV2Error(ms) if len(errs) > 0 { t.Fatal(errs) } diff --git a/metricbeat/module/windows/perfmon/perfmon.go b/metricbeat/module/windows/perfmon/perfmon.go index a73dbb57c46..6f64ed60ecc 100644 --- a/metricbeat/module/windows/perfmon/perfmon.go +++ b/metricbeat/module/windows/perfmon/perfmon.go @@ -88,16 +88,17 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { }, nil } -func (m *MetricSet) Fetch(report mb.ReporterV2) { +func (m *MetricSet) Fetch(report mb.ReporterV2) error { events, err := m.reader.Read() if err != nil { - m.log.Debugw("Failed reading counters", "error", err) - err = errors.Wrap(err, "failed reading counters") - report.Error(err) + return errors.Wrap(err, "failed reading counters") } for _, event := range events { - report.Event(event) + isOpen := report.Event(event) + if !isOpen { + break + } } } From 6e5b5445992c220f91d810426ec64ce4f7b2ab45 Mon Sep 17 00:00:00 2001 From: Alex Kristiansen Date: Thu, 5 Sep 2019 08:52:31 -0700 Subject: [PATCH 2/3] add godoc --- metricbeat/module/windows/perfmon/perfmon.go | 1 + 1 file changed, 1 insertion(+) diff --git a/metricbeat/module/windows/perfmon/perfmon.go b/metricbeat/module/windows/perfmon/perfmon.go index 6f64ed60ecc..85bfd1cef58 100644 --- a/metricbeat/module/windows/perfmon/perfmon.go +++ b/metricbeat/module/windows/perfmon/perfmon.go @@ -88,6 +88,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { }, nil } +// Fetch fetches events and reports them upstream func (m *MetricSet) Fetch(report mb.ReporterV2) error { events, err := m.reader.Read() if err != nil { From b467a73ca34546af435f5d9a241db5d013e4346d Mon Sep 17 00:00:00 2001 From: Alex Kristiansen Date: Thu, 5 Sep 2019 10:40:51 -0700 Subject: [PATCH 3/3] add return --- metricbeat/module/windows/perfmon/perfmon.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/metricbeat/module/windows/perfmon/perfmon.go b/metricbeat/module/windows/perfmon/perfmon.go index 85bfd1cef58..93645ee77b4 100644 --- a/metricbeat/module/windows/perfmon/perfmon.go +++ b/metricbeat/module/windows/perfmon/perfmon.go @@ -101,6 +101,8 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error { break } } + + return nil } // Close will be called when metricbeat is stopped, should close the query.