Skip to content

Commit 33dee93

Browse files
authored
fix application_pool metricset reader after pdh changes (#18477) (#18478)
* fix * changelog * mage fmt update (cherry picked from commit e20f856)
1 parent d279ff7 commit 33dee93

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
224224
- Fix overflow on Prometheus rates when new buckets are added on the go. {pull}17753[17753]
225225
- Add a switch to the driver definition on SQL module to use pretty names {pull}17378[17378]
226226
- Remove specific win32 api errors from events in perfmon. {issue}18292[18292] {pull}18361[18361]
227+
- Fix application_pool metricset after pdh changes. {pull}18477[18477]
227228

228229
*Packetbeat*
229230

x-pack/metricbeat/module/iis/application_pool/application_integration_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ func TestFetch(t *testing.T) {
2626
if len(errs) > 0 {
2727
t.Fatalf("Expected 0 error, had %d. %v\n", len(errs), errs)
2828
}
29-
assert.NotEmpty(t, events)
29+
if events != nil {
30+
assert.NotEmpty(t, events)
31+
}
32+
3033
}
3134

3235
func TestData(t *testing.T) {

x-pack/metricbeat/module/iis/application_pool/reader.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,20 @@ func (re *Reader) fetch(names []string) ([]mb.Event, error) {
150150
for _, val := range value {
151151
// 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.
152152
// For more information, see Collecting Performance Data (https://docs.microsoft.com/en-us/windows/desktop/PerfCtrs/collecting-performance-data).
153-
if val.Err != nil && !re.hasRun {
154-
re.log.Debugw("Ignoring the first measurement because the data isn't ready",
155-
"error", val.Err, logp.Namespace("website"), "query", counterPath)
156-
continue
153+
if val.Err.Error != nil {
154+
if !re.hasRun {
155+
re.log.Debugw("Ignoring the first measurement because the data isn't ready",
156+
"error", val.Err, logp.Namespace("application_pool"), "query", counterPath)
157+
continue
158+
}
159+
// The counter has a negative value or the counter was successfully found, but the data returned is not valid.
160+
// 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.)
161+
// This is not an error that stops the application from running successfully and a positive counter value should be retrieved in the later calls.
162+
if val.Err.Error == pdh.PDH_CALC_NEGATIVE_VALUE || val.Err.Error == pdh.PDH_INVALID_DATA {
163+
re.log.Debugw("Counter value retrieval returned",
164+
"error", val.Err.Error, "cstatus", pdh.PdhErrno(val.Err.CStatus), logp.Namespace("application_pool"), "query", counterPath)
165+
continue
166+
}
157167
}
158168
if val.Instance == appPool.Name {
159169
events[appPool.Name].MetricSetFields.Put(appPool.counters[counterPath], val.Measurement)

x-pack/metricbeat/module/iis/application_pool/reader_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestGetProcessIds(t *testing.T) {
4848
{
4949
Instance: "w3wp#1",
5050
Measurement: 124.00,
51-
Err: nil,
51+
Err: pdh.CounterValueError{},
5252
},
5353
}
5454
counterList := make(map[string][]pdh.CounterValue)

0 commit comments

Comments
 (0)