Skip to content

Commit 603e308

Browse files
authored
update perf count to ignore case (#22028)
* update perf count to ignore case * change log * add tests * update tests * lint * fix test
1 parent 5dd5206 commit 603e308

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Updates perf counters to ignore case. Fixes an error with double counting in exchange.activemanager.database_mounted metric.

datadog_checks_base/datadog_checks/base/checks/windows/perf_counters/counter.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ def __init__(self, check, connection, name, config, use_localized_counters, tags
5151
f'Pattern #{i} of option `include` for performance object `{self.name}` must be a string'
5252
)
5353

54-
self.include_pattern = re.compile('|'.join(include_patterns))
54+
# Instance names are not case-sensitive, so instances should not have names that differ only in case.
55+
# See: https://learn.microsoft.com/en-us/windows/win32/perfctrs/about-performance-counters
56+
self.include_pattern = re.compile('|'.join(include_patterns), re.IGNORECASE)
5557

5658
# List of regex patterns to filter multi-instance counters AFTER ALL data
5759
# is collected and retrieved from PDH layer
@@ -67,7 +69,9 @@ def __init__(self, check, connection, name, config, use_localized_counters, tags
6769

6870
final_exclude_patterns = [r'\b_Total\b']
6971
final_exclude_patterns.extend(exclude_patterns)
70-
self.exclude_pattern = re.compile('|'.join(final_exclude_patterns))
72+
# Instance names are not case-sensitive, so instances should not have names that differ only in case.
73+
# See: https://learn.microsoft.com/en-us/windows/win32/perfctrs/about-performance-counters
74+
self.exclude_pattern = re.compile('|'.join(final_exclude_patterns), re.IGNORECASE)
7175

7276
# List of wildcards or instance name directly to filter multi-instance counters by PDH layer itself.
7377
# Thus it is faster and and less resource intensive than regex-based include filtering.

datadog_checks_base/tests/base/checks/windows/perf_counters/test_filter.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,29 @@ def test_exclude_default(aggregator, dd_run_check, mock_performance_objects):
4949
dd_run_check(check)
5050

5151
aggregator.assert_all_metrics_covered()
52+
53+
54+
def test_exclude_case_insensitive(aggregator, dd_run_check, mock_performance_objects):
55+
mock_performance_objects({'Foo': (['0,_total', 'baz'], {'Bar': [1, 2]})})
56+
check = get_check({'metrics': {'Foo': {'name': 'foo', 'exclude': ['Baz'], 'counters': [{'Bar': 'bar'}]}}})
57+
dd_run_check(check)
58+
59+
aggregator.assert_all_metrics_covered()
60+
61+
62+
def test_include_case_insensitive(aggregator, dd_run_check, mock_performance_objects):
63+
mock_performance_objects({'Foo': (['Foobar', 'Bar', 'Barbat'], {'Bar': [1, 2, 3]})})
64+
check = get_check({'metrics': {'Foo': {'name': 'foo', 'include': ['bar$'], 'counters': [{'Bar': 'bar'}]}}})
65+
dd_run_check(check)
66+
67+
tags = ['instance:Foobar']
68+
tags.extend(GLOBAL_TAGS)
69+
aggregator.assert_metric('test.foo.bar', 1, tags=tags)
70+
71+
tags = ['instance:Bar']
72+
tags.extend(GLOBAL_TAGS)
73+
aggregator.assert_metric('test.foo.bar', 2, tags=tags)
74+
75+
aggregator.assert_metric_has_tag('test.foo.bar', 'instance:Barbat', count=0)
76+
77+
aggregator.assert_all_metrics_covered()

exchange_server/tests/test_unit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test(aggregator, dd_default_hostname, dd_run_check, mock_performance_objects
4646
if instance is None:
4747
tags = global_tags
4848
else:
49-
if '_Total' in instance:
49+
if '_total' in instance.lower():
5050
continue
5151

5252
tags = ['instance:{}'.format(instance)]

0 commit comments

Comments
 (0)