Skip to content

Commit

Permalink
[go_expvar] Fix path tag appended to all metrics matching path regex (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
zippolyte authored Jun 13, 2017
1 parent d07b98d commit bae30da
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
5 changes: 5 additions & 0 deletions go_expvar/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
==================

Expand Down
5 changes: 2 additions & 3 deletions go_expvar/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -191,7 +190,7 @@ def parse_expvar_data(self, data, tags, metrics, max_metrics, namespace):
"Please contact [email protected] 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):
Expand Down
3 changes: 2 additions & 1 deletion go_expvar/ci/fixtures/expvar_output
Original file line number Diff line number Diff line change
Expand Up @@ -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}]
}
2 changes: 1 addition & 1 deletion go_expvar/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"mac_os",
"windows"
],
"version": "1.0.2",
"version": "1.0.3",
"guid": "33557f7a-5f24-43f3-9551-78432894e539"
}
20 changes: 20 additions & 0 deletions go_expvar/test_go_expvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down

0 comments on commit bae30da

Please sign in to comment.