From 73b99df621d8fa425f878a6b773707a9a3c63041 Mon Sep 17 00:00:00 2001 From: Mariana Date: Wed, 13 May 2020 12:20:29 +0200 Subject: [PATCH 1/3] fix --- .../application_integration_test.go | 8 +++++--- .../module/iis/application_pool/reader.go | 18 ++++++++++++++---- .../module/iis/application_pool/reader_test.go | 2 +- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/x-pack/metricbeat/module/iis/application_pool/application_integration_test.go b/x-pack/metricbeat/module/iis/application_pool/application_integration_test.go index 0a4d7ece5ec2..196f2f2f6dbd 100644 --- a/x-pack/metricbeat/module/iis/application_pool/application_integration_test.go +++ b/x-pack/metricbeat/module/iis/application_pool/application_integration_test.go @@ -8,9 +8,8 @@ package application_pool import ( - "testing" - "github.com/stretchr/testify/assert" + "testing" "github.com/elastic/beats/v7/x-pack/metricbeat/module/iis/test" @@ -26,7 +25,10 @@ func TestFetch(t *testing.T) { if len(errs) > 0 { t.Fatalf("Expected 0 error, had %d. %v\n", len(errs), errs) } - assert.NotEmpty(t, events) + if events != nil { + assert.NotEmpty(t, events) + } + } func TestData(t *testing.T) { diff --git a/x-pack/metricbeat/module/iis/application_pool/reader.go b/x-pack/metricbeat/module/iis/application_pool/reader.go index 2c137c42d654..5124f45e7a32 100644 --- a/x-pack/metricbeat/module/iis/application_pool/reader.go +++ b/x-pack/metricbeat/module/iis/application_pool/reader.go @@ -150,10 +150,20 @@ func (re *Reader) fetch(names []string) ([]mb.Event, error) { for _, val := range value { // Some counters, such as rate counters, require two counter values in order to compute a displayable value. In this case we must call PdhCollectQueryData twice before calling PdhGetFormattedCounterValue. // For more information, see Collecting Performance Data (https://docs.microsoft.com/en-us/windows/desktop/PerfCtrs/collecting-performance-data). - if val.Err != nil && !re.hasRun { - re.log.Debugw("Ignoring the first measurement because the data isn't ready", - "error", val.Err, logp.Namespace("website"), "query", counterPath) - continue + if val.Err.Error != nil { + if !re.hasRun { + re.log.Debugw("Ignoring the first measurement because the data isn't ready", + "error", val.Err, logp.Namespace("application_pool"), "query", counterPath) + continue + } + // The counter has a negative value or the counter was successfully found, but the data returned is not valid. + // This error can occur if the counter value is less than the previous value. (Because counter values always increment, the counter value rolls over to zero when it reaches its maximum value.) + // This is not an error that stops the application from running successfully and a positive counter value should be retrieved in the later calls. + if val.Err.Error == pdh.PDH_CALC_NEGATIVE_VALUE || val.Err.Error == pdh.PDH_INVALID_DATA { + re.log.Debugw("Counter value retrieval returned", + "error", val.Err.Error, "cstatus", pdh.PdhErrno(val.Err.CStatus), logp.Namespace("application_pool"), "query", counterPath) + continue + } } if val.Instance == appPool.Name { events[appPool.Name].MetricSetFields.Put(appPool.counters[counterPath], val.Measurement) diff --git a/x-pack/metricbeat/module/iis/application_pool/reader_test.go b/x-pack/metricbeat/module/iis/application_pool/reader_test.go index b814f0070f03..64aa8f85941d 100644 --- a/x-pack/metricbeat/module/iis/application_pool/reader_test.go +++ b/x-pack/metricbeat/module/iis/application_pool/reader_test.go @@ -48,7 +48,7 @@ func TestGetProcessIds(t *testing.T) { { Instance: "w3wp#1", Measurement: 124.00, - Err: nil, + Err: pdh.CounterValueError{}, }, } counterList := make(map[string][]pdh.CounterValue) From e9450e871829643da0d3770e808539594d6b5680 Mon Sep 17 00:00:00 2001 From: Mariana Date: Wed, 13 May 2020 12:27:46 +0200 Subject: [PATCH 2/3] changelog --- CHANGELOG.next.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index d189637976de..b5d6c309ce1b 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -179,6 +179,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Add a switch to the driver definition on SQL module to use pretty names. {pull}17378[17378] - Fix overflow on Prometheus rates when new buckets are added on the go. {pull}17753[17753] - Remove specific win32 api errors from events in perfmon. {issue}18292[18292] {pull}18361[18361] +- Fix application_pool metricset after pdh changes. {pull}18477[18477] *Packetbeat* From 3430ed2df6a2140b6eea5b5034c076943c056746 Mon Sep 17 00:00:00 2001 From: Mariana Date: Wed, 13 May 2020 12:47:18 +0200 Subject: [PATCH 3/3] mage fmt update --- .../iis/application_pool/application_integration_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/metricbeat/module/iis/application_pool/application_integration_test.go b/x-pack/metricbeat/module/iis/application_pool/application_integration_test.go index 196f2f2f6dbd..e270880723a2 100644 --- a/x-pack/metricbeat/module/iis/application_pool/application_integration_test.go +++ b/x-pack/metricbeat/module/iis/application_pool/application_integration_test.go @@ -8,9 +8,10 @@ package application_pool import ( - "github.com/stretchr/testify/assert" "testing" + "github.com/stretchr/testify/assert" + "github.com/elastic/beats/v7/x-pack/metricbeat/module/iis/test" mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing"