Skip to content

Commit e99d0fa

Browse files
authored
[AGENT-13541] Properly support for custom tags in esxi (#20022)
* Add support for custom tags in esxi * Add changelog * update changelog and remove caplog fixture
1 parent 07aeaef commit e99d0fa

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

esxi/changelog.d/20022.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Properly support custom tags.

esxi/datadog_checks/esxi/check.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def __init__(self, name, init_config, instances):
6161
self.ssl_verify = is_affirmative(self.instance.get('ssl_verify', True))
6262
self.ssl_capath = self.instance.get("ssl_capath")
6363
self.ssl_cafile = self.instance.get("ssl_cafile")
64-
self.tags = [f"esxi_url:{self.host}"]
64+
self.tags = self.instance.get("tags", [])
65+
self.tags.append(f"esxi_url:{self.host}")
6566
self.proxy_host = None
6667
self.proxy_port = None
6768
proxy = self.instance.get('proxy', init_config.get('proxy'))

esxi/tests/test_unit.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,3 +1271,15 @@ def test_cant_get_version(vcsim_instance, dd_run_check, caplog, service_instance
12711271
)
12721272
aggregator.assert_metric('esxi.host.can_connect', 0, count=1)
12731273
aggregator.assert_all_metrics_covered()
1274+
1275+
1276+
@pytest.mark.usefixtures("service_instance")
1277+
def test_esxi_custom_tags(vcsim_instance, dd_run_check, aggregator):
1278+
vcsim_instance['tags'] = ['test:tag']
1279+
check = EsxiCheck('esxi', {}, [vcsim_instance])
1280+
dd_run_check(check)
1281+
1282+
base_tags = ["esxi_url:127.0.0.1:8989", "test:tag"]
1283+
aggregator.assert_metric("esxi.cpu.usage.avg", value=0.26, tags=base_tags, hostname="localhost.localdomain")
1284+
aggregator.assert_metric("esxi.mem.granted.avg", value=80, tags=base_tags, hostname="localhost.localdomain")
1285+
aggregator.assert_metric("esxi.host.can_connect", 1, count=2, tags=base_tags)

0 commit comments

Comments
 (0)