From bae30da9659c0e4b70b8fb4ee999f37126c811c4 Mon Sep 17 00:00:00 2001 From: Hippolyte HENRY Date: Tue, 13 Jun 2017 13:46:00 -0400 Subject: [PATCH] [go_expvar] Fix path tag appended to all metrics matching path regex (#472) --- go_expvar/CHANGELOG.md | 5 +++++ go_expvar/check.py | 5 ++--- go_expvar/ci/fixtures/expvar_output | 3 ++- go_expvar/manifest.json | 2 +- go_expvar/test_go_expvar.py | 20 ++++++++++++++++++++ 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/go_expvar/CHANGELOG.md b/go_expvar/CHANGELOG.md index b0542567be93d..6ceb84969648f 100644 --- a/go_expvar/CHANGELOG.md +++ b/go_expvar/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG - go_expvar +1.0.3 / Unreleased +================== + +* [BUGFIX] Fix path tag appended to all metrics matching path regex + 1.0.2 / Unreleased ================== diff --git a/go_expvar/check.py b/go_expvar/check.py index 9818fe5dd6232..6d6cce7259296 100644 --- a/go_expvar/check.py +++ b/go_expvar/check.py @@ -175,8 +175,7 @@ def parse_expvar_data(self, data, tags, metrics, max_metrics, namespace): for traversed_path, value in values: actual_path = ".".join(traversed_path) - if tag_by_path: - metric_tags.append("path:%s" % actual_path) + path_tag = ["path:%s" % actual_path] if tag_by_path else [] metric_name = alias or self.normalize(actual_path, namespace, fix_case=True) @@ -191,7 +190,7 @@ def parse_expvar_data(self, data, tags, metrics, max_metrics, namespace): "Please contact support@datadoghq.com for more information.") return - SUPPORTED_TYPES[metric_type](self, metric_name, value, metric_tags) + SUPPORTED_TYPES[metric_type](self, metric_name, value, metric_tags + path_tag) count += 1 def deep_get(self, content, keys, traversed_path=None): diff --git a/go_expvar/ci/fixtures/expvar_output b/go_expvar/ci/fixtures/expvar_output index e60a32a77599f..94bc8d4cbe7ba 100644 --- a/go_expvar/ci/fixtures/expvar_output +++ b/go_expvar/ci/fixtures/expvar_output @@ -4,5 +4,6 @@ "random_walk": 0.2813217443279966, "steps": 5, "public": {"bla": 1}, -"random_value": 0.6868230728671094 +"random_value": 0.6868230728671094, +"array": [{"key":10},{"key":15}] } \ No newline at end of file diff --git a/go_expvar/manifest.json b/go_expvar/manifest.json index 0a3c66f68eb62..590db4f918100 100644 --- a/go_expvar/manifest.json +++ b/go_expvar/manifest.json @@ -11,6 +11,6 @@ "mac_os", "windows" ], - "version": "1.0.2", + "version": "1.0.3", "guid": "33557f7a-5f24-43f3-9551-78432894e539" } diff --git a/go_expvar/test_go_expvar.py b/go_expvar/test_go_expvar.py index e3286ab16d5dc..1ea9018d80c9d 100644 --- a/go_expvar/test_go_expvar.py +++ b/go_expvar/test_go_expvar.py @@ -249,6 +249,26 @@ def test_deep_get(self): results = self.check.deep_get(content, ['list', '.*', 'value'], []) self.assertEqual(sorted(results), sorted(expected)) + # Test that the path tags get correctly added when metric has alias + def test_alias_tag_path(self): + mock_config = { + "instances": [{ + "expvar_url": self._expvar_url, + "metrics": [ + { + "path": "array/\d+/key", + "alias": "array.dict.key", + "type": "gauge", + } + ] + }] + } + self.run_check(mock_config, mocks=self.mocks) + + shared_tags = ['expvar_url:{0}'.format(self._expvar_url)] + self.assertMetric("array.dict.key", count=1, tags=shared_tags + ["path:array.0.key"]) + self.assertMetric("array.dict.key", count=1, tags=shared_tags + ["path:array.1.key"]) + @attr(requires='go_expvar') class TestGoExpVar(AgentCheckTest):