Skip to content

Commit 085a18b

Browse files
authored
Add infra mode config option (DataDog#24008)
* Add infra mode tag proxmox * Add changelog and update test * simplify test * change to enum and make test more general
1 parent 81f3e02 commit 085a18b

8 files changed

Lines changed: 57 additions & 1 deletion

File tree

proxmox/assets/configuration/spec.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ files:
3030
example: true
3131
display_default: false
3232
required: false
33+
- name: infrastructure_mode
34+
description: |
35+
The infrastructure mode to use. Valid values are 'full' (default) and 'basic'.
36+
fleet_configurable: true
37+
value:
38+
type: string
39+
example: full
40+
enum:
41+
- full
42+
- basic
3343
- name: resource_filters
3444
display_priority: 1
3545
description: |

proxmox/changelog.d/24008.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add infra_mode tag to proxmox metrics.

proxmox/datadog_checks/proxmox/check.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
ALLOWED_FILTER_PROPERTIES,
1616
ALLOWED_FILTER_TYPES,
1717
EVENT_TYPE_TO_TITLE,
18+
INFRA_MODE_METRIC,
1819
NODE_RESOURCE,
1920
OK_STATUS,
2021
PERF_METRIC_NAME,
@@ -138,7 +139,11 @@ def _submit_resource_metrics(self, resource, tags, hostname):
138139
metric_value = resource.get(metric_name)
139140
metric_method = self.count if metric_name in RESOURCE_COUNT_METRICS else self.gauge
140141
if metric_value is not None:
141-
metric_method(f'{metric_name_remapped}', metric_value, tags=tags, hostname=hostname)
142+
metric_tags = tags
143+
infra_mode = self.config.infrastructure_mode
144+
if metric_name_remapped == INFRA_MODE_METRIC and hostname and infra_mode != 'full':
145+
metric_tags = list(tags) + [f'infra_mode:{infra_mode}']
146+
metric_method(f'{metric_name_remapped}', metric_value, tags=metric_tags, hostname=hostname)
142147

143148
def _get_vm_hostname(self, vm_id, vm_name, node):
144149
try:

proxmox/datadog_checks/proxmox/config_models/defaults.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ def instance_enable_legacy_tags_normalization():
5858
return True
5959

6060

61+
def instance_infrastructure_mode():
62+
return 'full'
63+
64+
6165
def instance_kerberos_auth():
6266
return 'disabled'
6367

proxmox/datadog_checks/proxmox/config_models/instance.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class InstanceConfig(BaseModel):
8585
enable_legacy_tags_normalization: Optional[bool] = None
8686
extra_headers: Optional[MappingProxyType[str, Any]] = None
8787
headers: Optional[MappingProxyType[str, Any]] = None
88+
infrastructure_mode: Optional[Literal['full', 'basic']] = None
8889
kerberos_auth: Optional[Literal['required', 'optional', 'disabled']] = None
8990
kerberos_cache: Optional[str] = None
9091
kerberos_delegate: Optional[bool] = None

proxmox/datadog_checks/proxmox/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,5 @@
6767
ALLOWED_FILTER_PROPERTIES = ['resource_name']
6868
ADDITIONAL_FILTER_PROPERTIES = ['hostname']
6969
ALLOWED_FILTER_TYPES = ['include', 'exclude']
70+
71+
INFRA_MODE_METRIC = 'cpu'

proxmox/datadog_checks/proxmox/data/conf.yaml.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ instances:
150150
#
151151
# empty_default_hostname: true
152152

153+
## @param infrastructure_mode - string - optional - default: full
154+
## The infrastructure mode to use. Valid values are 'full' (default) and 'basic'.
155+
#
156+
# infrastructure_mode: full
157+
153158
## @param collected_task_types - list of strings - optional - default: ['qmstart', 'qmstop', 'qmshutdown', 'qmreboot', 'qmigrate', 'qmsuspend', 'vzstart', 'vzshutdown', 'vzsuspend', 'startall', 'stopall', 'suspendall', 'aptupdate']
154159
## Which Proxmox task types to collect.
155160
##

proxmox/tests/test_unit.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,34 @@ def test_events(get_current_datetime, dd_run_check, aggregator, instance, collec
576576
assert len(aggregator.events) == len(expected_events)
577577

578578

579+
@pytest.mark.parametrize(
580+
('infrastructure_mode', 'expected_count'),
581+
[
582+
pytest.param('basic', 2, id='basic mode adds infra_mode tag'),
583+
pytest.param('full', 0, id='full mode does not add infra_mode tag'),
584+
pytest.param(None, 0, id='unset mode does not add infra_mode tag'),
585+
],
586+
)
587+
@pytest.mark.usefixtures('mock_http_get')
588+
def test_infra_mode_tag(dd_run_check, aggregator, instance, infrastructure_mode, expected_count):
589+
instance = copy.deepcopy(instance)
590+
if infrastructure_mode is not None:
591+
instance['infrastructure_mode'] = infrastructure_mode
592+
check = ProxmoxCheck('proxmox', {}, [instance])
593+
dd_run_check(check)
594+
595+
aggregator.assert_metric_has_tag_prefix('proxmox.cpu', 'infra_mode:', count=expected_count)
596+
597+
# assert that no container metrics have an infra_mode tag
598+
for metric in aggregator.metrics('proxmox.cpu'):
599+
if 'proxmox_type:container' in metric.tags:
600+
assert not any(t.startswith('infra_mode:') for t in metric.tags)
601+
# assert only the cpu metric has an infra_mode tag
602+
for metric_name in ALL_METRICS:
603+
if metric_name != 'proxmox.cpu':
604+
aggregator.assert_metric_has_tag_prefix(metric_name, 'infra_mode:', count=0)
605+
606+
579607
@pytest.mark.parametrize(
580608
('resource_filters, expected_vms, expected_nodes'),
581609
[

0 commit comments

Comments
 (0)