Skip to content

Commit c12e744

Browse files
authored
Collect prism central version metadata (DataDog#23071)
* collect prism central version metadata * changelog
1 parent 1509847 commit c12e744

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

nutanix/changelog.d/23071.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Collect prism central version metadata

nutanix/datadog_checks/nutanix/infrastructure_monitor.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def collect_cluster_metrics(self) -> None:
140140

141141
if self._is_prism_central_cluster(cluster):
142142
self.check.log.info("[%s] Skipping Prism Central cluster: %s", pc_label, cluster_name)
143+
self._collect_pc_version_metadata(cluster)
143144
skipped += 1
144145
continue
145146

@@ -191,6 +192,18 @@ def _is_prism_central_cluster(self, cluster: dict) -> bool:
191192
cluster_function = get_nested(cluster, "config/clusterFunction") or []
192193
return "PRISM_CENTRAL" in cluster_function
193194

195+
def _collect_pc_version_metadata(self, pc_cluster: dict) -> None:
196+
"""Collect and report version metadata from the Prism Central cluster."""
197+
version = get_nested(pc_cluster, "config/buildInfo/version")
198+
if version:
199+
self.check.set_metadata(
200+
'version',
201+
version,
202+
scheme='regex',
203+
pattern=r'(?P<major>\d+)\.(?P<minor>\d+)',
204+
final_scheme='semver',
205+
)
206+
194207
def _process_cluster(self, cluster: dict, pc_label: str) -> None:
195208
"""Process and report metrics for a single cluster."""
196209
cluster_id = cluster.get("extId", "unknown")

nutanix/tests/test_metadata.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,46 @@
3939
OPTIONAL_METRICS = CLUSTER_STATS_METRICS_OPTIONAL + HOST_STATS_METRICS_OPTIONAL + VM_STATS_METRICS_OPTIONAL
4040

4141

42+
@pytest.mark.unit
43+
def test_version_metadata(dd_run_check, mock_instance, mock_http_get, datadog_agent):
44+
check = NutanixCheck('nutanix', {}, [mock_instance])
45+
check.check_id = 'test:123'
46+
dd_run_check(check)
47+
48+
datadog_agent.assert_metadata(
49+
'test:123',
50+
{'version.scheme': 'semver', 'version.major': '7', 'version.minor': '3', 'version.raw': '7.3'},
51+
)
52+
53+
54+
@pytest.mark.unit
55+
@pytest.mark.parametrize(
56+
'version, expected_major, expected_minor',
57+
[
58+
('7.3', '7', '3'),
59+
('pc.7.3', '7', '3'),
60+
('pc.7.5', '7', '5'),
61+
('pc.2024.3', '2024', '3'),
62+
],
63+
)
64+
def test_version_metadata_formats(mock_instance, datadog_agent, version, expected_major, expected_minor):
65+
check = NutanixCheck('nutanix', {}, [mock_instance])
66+
check.check_id = 'test:123'
67+
68+
pc_cluster = {'config': {'buildInfo': {'version': version}, 'clusterFunction': ['PRISM_CENTRAL']}}
69+
check.infrastructure_monitor._collect_pc_version_metadata(pc_cluster)
70+
71+
datadog_agent.assert_metadata(
72+
'test:123',
73+
{
74+
'version.scheme': 'semver',
75+
'version.major': expected_major,
76+
'version.minor': expected_minor,
77+
'version.raw': version,
78+
},
79+
)
80+
81+
4282
@pytest.mark.unit
4383
def test_all_metrics(dd_run_check, aggregator, mock_instance, mock_http_get):
4484
check = NutanixCheck('nutanix', {}, [mock_instance])

0 commit comments

Comments
 (0)