Skip to content

Commit 07a278e

Browse files
authored
Add support for specifying tenants in avi_vantage (#19825)
* add tenant property to the config * tenant admin case working * multiple tenants working * add empty tenant test + small cleanup * ddev validate config models test -fs * cleanup * changelog * ddev test -fs * fix metrics path in e2e flask app * change tenant property to a list * add test for default config * lint * update default value to be empty list
1 parent e2833e1 commit 07a278e

24 files changed

+6842
-29
lines changed

avi_vantage/assets/configuration/spec.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ files:
3131
items:
3232
type: string
3333
enum: *avi_entities
34+
- name: tenants
35+
required: false
36+
description: |
37+
A list of tenant names to collect metrics for. If empty, it defaults to the admin tenant.
38+
value:
39+
type: array
40+
items:
41+
type: string
42+
example: [admin, tenant_a, tenant_b]
43+
display_default: []
3444
- template: instances/openmetrics
3545
overrides:
3646
persist_connections.hidden: true

avi_vantage/changelog.d/19825.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support for specifying tenants in avi_vantage

avi_vantage/datadog_checks/avi_vantage/check.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44
from contextlib import contextmanager
55
from copy import deepcopy
6+
from urllib.parse import urlencode
67

78
from datadog_checks.avi_vantage import metrics
89
from datadog_checks.base import AgentCheck, OpenMetricsBaseCheckV2
@@ -29,6 +30,9 @@ def __init__(self, name, init_config, instances):
2930
# Required for storing the auth cookie
3031
self.instance['persist_connections'] = True
3132
self._base_url = None
33+
self.tenant = None
34+
if self.instance.get("tenants"):
35+
self.tenant = ",".join(self.instance.get("tenants"))
3236

3337
@property
3438
def base_url(self):
@@ -46,7 +50,14 @@ def configure_scrapers(self):
4650
)
4751
resource_metrics = RESOURCE_METRICS[entity]
4852
instance_copy = deepcopy(self.instance)
53+
54+
# GET /api/analytics/prometheus-metrics/{entity_type}/?{query_params}"
4955
endpoint = self.base_url + "/api/analytics/prometheus-metrics/" + entity
56+
if self.tenant:
57+
query_params = {"tenant": self.tenant}
58+
encoded_params = urlencode(query_params)
59+
endpoint += f"/?{encoded_params}"
60+
5061
instance_copy['openmetrics_endpoint'] = endpoint
5162
instance_copy['metrics'] = [resource_metrics]
5263
instance_copy['rename_labels'] = LABELS_REMAPPER.copy()

avi_vantage/datadog_checks/avi_vantage/config_models/defaults.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ def instance_telemetry():
108108
return False
109109

110110

111+
def instance_tenants():
112+
return []
113+
114+
111115
def instance_timeout():
112116
return 10
113117

avi_vantage/datadog_checks/avi_vantage/config_models/instance.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class InstanceConfig(BaseModel):
141141
tag_by_endpoint: Optional[bool] = None
142142
tags: Optional[tuple[str, ...]] = None
143143
telemetry: Optional[bool] = None
144+
tenants: Optional[tuple[str, ...]] = None
144145
timeout: Optional[float] = None
145146
tls_ca_cert: Optional[str] = None
146147
tls_cert: Optional[str] = None

avi_vantage/datadog_checks/avi_vantage/data/conf.yaml.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ instances:
6161
# - serviceengine
6262
# - virtualservice
6363

64+
## @param tenants - list of strings - optional - default: []
65+
## A list of tenant names to collect metrics for. If empty, it defaults to the admin tenant.
66+
#
67+
# tenants:
68+
# - admin
69+
# - tenant_a
70+
# - tenant_b
71+
6472
## @param raw_metric_prefix - string - optional
6573
## A prefix that is removed from all exposed metric names, if present.
6674
## All configuration options will use the prefix-less name.

0 commit comments

Comments
 (0)