Skip to content

Commit

Permalink
Add new RBAC metrics in Legacy check (#16432)
Browse files Browse the repository at this point in the history
* add new metrics

* changelog entry

* lint
  • Loading branch information
steveny91 authored Dec 14, 2023
1 parent 373087f commit bf72db2
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 7 deletions.
1 change: 1 addition & 0 deletions envoy/changelog.d/16432.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add new RBAC metrics in Legacy check
32 changes: 32 additions & 0 deletions envoy/datadog_checks/envoy/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3861,6 +3861,38 @@
),
'method': 'monotonic_count',
},
'http.rbac.allowed': {
'tags': (
('stat_prefix',),
(),
(),
),
'method': 'monotonic_count',
},
'http.rbac.denied': {
'tags': (
('stat_prefix',),
(),
(),
),
'method': 'monotonic_count',
},
'http.rbac.shadow_allowed': {
'tags': (
('stat_prefix',),
(),
(),
),
'method': 'monotonic_count',
},
'http.rbac.shadow_denied': {
'tags': (
('stat_prefix',),
(),
(),
),
'method': 'monotonic_count',
},
# "*." to match at the beginning of raw metric if it doesn't have a standard name
'*.http_local_rate_limit.enabled': {
'tags': (
Expand Down
4 changes: 4 additions & 0 deletions envoy/metadata.csv
Original file line number Diff line number Diff line change
Expand Up @@ -973,3 +973,7 @@ envoy.http_local_rate_limit.enabled,count,,request,,[Legacy] Total number of req
envoy.http_local_rate_limit.enforced,count,,request,,[Legacy] Total number of requests for which rate limiting was applied (e.g.: 429 returned),-1,envoy,,
envoy.http_local_rate_limit.rate_limited,count,,request,,[Legacy] Total number of responses without an available token (but not necessarily enforced),-1,envoy,,
envoy.http_local_rate_limit.ok,count,,request,,[Legacy] Total number of under the limit responses from the token bucket,-1,envoy,,
envoy.http.rbac.allowed,count,,request,,[Legacy] Total requests that were allowed access,-1,envoy,,
envoy.http.rbac.denied,count,,request,,[Legacy] Total requests that were denied access,-1,envoy,,
envoy.http.rbac.shadow_allowed,count,,request,,[Legacy] Total requests that would be allowed access by the filter's shadow rules,-1,envoy,,
envoy.http.rbac.shadow_denied,count,,request,,[Legacy] Total requests that would be denied access by the filter's shadow rules,-1,envoy,,
8 changes: 4 additions & 4 deletions envoy/tests/fixtures/legacy/local_rate_limit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ http_local_rate_limiter.http_local_rate_limit.enabled: 0
http_local_rate_limiter.http_local_rate_limit.enforced: 0
http_local_rate_limiter.http_local_rate_limit.ok: 0
http_local_rate_limiter.http_local_rate_limit.rate_limited: 0
foo.http_local_rate_limit.enabled: 0
foo.http_local_rate_limit.enforced: 0
foo.http_local_rate_limit.ok: 0
foo.http_local_rate_limit.rate_limited: 0
foo_buz_112.http_local_rate_limit.enabled: 0
foo_buz_112.http_local_rate_limit.enforced: 0
foo_buz_112.http_local_rate_limit.ok: 0
foo_buz_112.http_local_rate_limit.rate_limited: 0
4 changes: 4 additions & 0 deletions envoy/tests/fixtures/legacy/rbac_metric.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
http.foo_buz_112.rbac.allowed: 0
http.foo_buz_112.rbac.denied: 0
http.foo_buz_112.rbac.shadow_allowed: 0
http.foo_buz_112.rbac.shadow_denied: 0
9 changes: 8 additions & 1 deletion envoy/tests/legacy/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,11 @@
"envoy.http_local_rate_limit.ok",
]

RATE_LIMIT_STAT_PREFIX_TAG = ['stat_prefix:http_local_rate_limiter', 'stat_prefix:foo']
STAT_PREFIX_TAG = ['stat_prefix:http_local_rate_limiter', 'stat_prefix:foo_buz_112']

RBAC_METRICS = [
"envoy.http.rbac.allowed",
"envoy.http.rbac.denied",
"envoy.http.rbac.shadow_allowed",
"envoy.http.rbac.shadow_denied",
]
19 changes: 17 additions & 2 deletions envoy/tests/legacy/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
HOST,
INSTANCES,
LOCAL_RATE_LIMIT_METRICS,
RATE_LIMIT_STAT_PREFIX_TAG,
RBAC_METRICS,
STAT_PREFIX_TAG,
)

CHECK_NAME = 'envoy'
Expand Down Expand Up @@ -281,7 +282,21 @@ def test_local_rate_limit_metrics(aggregator, fixture_path, mock_http_response,

for metric in LOCAL_RATE_LIMIT_METRICS:
aggregator.assert_metric(metric)
for tag in RATE_LIMIT_STAT_PREFIX_TAG:
for tag in STAT_PREFIX_TAG:
aggregator.assert_metric_has_tag(metric, tag, count=1)

aggregator.assert_metrics_using_metadata(get_metadata_metrics())


def test_rbac_metrics(aggregator, fixture_path, mock_http_response, check, dd_run_check):
instance = INSTANCES['main']
c = check(instance)

mock_http_response(file_path=fixture_path('./legacy/rbac_metric.txt'))
dd_run_check(c)

for metric in RBAC_METRICS:
aggregator.assert_metric(metric)
aggregator.assert_metric_has_tag(metric, STAT_PREFIX_TAG[1], count=1)

aggregator.assert_metrics_using_metadata(get_metadata_metrics())

0 comments on commit bf72db2

Please sign in to comment.