From 064835a1c1e41c6d46ffb32c5d58c5d8b3a7914d Mon Sep 17 00:00:00 2001 From: Hippolyte HENRY Date: Fri, 9 Jun 2017 13:59:53 -0400 Subject: [PATCH 1/4] [go_expvar] Fix path tag appended to all metrics matching path regex --- go_expvar/check.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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): From dfc7cd13dd1207efc568dc024d79130176c49d40 Mon Sep 17 00:00:00 2001 From: Hippolyte HENRY Date: Mon, 12 Jun 2017 15:07:43 -0400 Subject: [PATCH 2/4] Add test --- go_expvar/CHANGELOG.md | 1 + go_expvar/ci/fixtures/expvar_output | 3 ++- go_expvar/test_go_expvar.py | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/go_expvar/CHANGELOG.md b/go_expvar/CHANGELOG.md index b0542567be93d..041aede0cb18a 100644 --- a/go_expvar/CHANGELOG.md +++ b/go_expvar/CHANGELOG.md @@ -3,6 +3,7 @@ 1.0.2 / Unreleased ================== +* [BUGFIX] Fix path tag appended to all metrics matching path regex * [FEATURE] Make the hardcoded expvar URL path optional in the configuration 1.0.1 / 5-22-2017 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/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): From 1aecea0bd09b5416a7815f3827a8c3e146646a8c Mon Sep 17 00:00:00 2001 From: Hippolyte HENRY Date: Tue, 13 Jun 2017 11:58:10 -0400 Subject: [PATCH 3/4] Update changelog --- go_expvar/CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/go_expvar/CHANGELOG.md b/go_expvar/CHANGELOG.md index 041aede0cb18a..6ceb84969648f 100644 --- a/go_expvar/CHANGELOG.md +++ b/go_expvar/CHANGELOG.md @@ -1,9 +1,13 @@ # CHANGELOG - go_expvar -1.0.2 / Unreleased +1.0.3 / Unreleased ================== * [BUGFIX] Fix path tag appended to all metrics matching path regex + +1.0.2 / Unreleased +================== + * [FEATURE] Make the hardcoded expvar URL path optional in the configuration 1.0.1 / 5-22-2017 From 3a49f9e6d2bb08a03433c10cf54d3c4c85d2a08a Mon Sep 17 00:00:00 2001 From: Hippolyte HENRY Date: Tue, 13 Jun 2017 11:59:48 -0400 Subject: [PATCH 4/4] Update manifest.json --- go_expvar/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" }