From 7447b557241017adb8b5033220ed7dcffc92a69e Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Mon, 11 Feb 2013 18:22:40 -0500 Subject: [PATCH] bugfix: make sure histogram metric path is correct also slight optimisation in the metric setting loop for timers --- backends/graphite.js | 13 ++++++++++--- test/graphite_tests.js | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/backends/graphite.js b/backends/graphite.js index 1208433..3220739 100644 --- a/backends/graphite.js +++ b/backends/graphite.js @@ -99,10 +99,17 @@ var flush_stats = function graphite_flush(ts, metrics) { for (key in timer_data) { if (Object.keys(timer_data).length > 0) { + var namespace = timerNamespace.concat(key); + var the_key = namespace.join("."); for (timer_data_key in timer_data[key]) { - var namespace = timerNamespace.concat(key); - var the_key = namespace.join("."); - statString += the_key + '.' + timer_data_key + ' ' + timer_data[key][timer_data_key] + ' ' + ts + "\n"; + if (typeof(timer_data_key) === 'string') { + statString += the_key + '.' + timer_data_key + ' ' + timer_data[key][timer_data_key] + ' ' + ts + "\n"; + } else { + for (timer_data_sub_key in timer_data[key][timer_data_key]) { + statString += the_key + '.' + timer_data_key + '.' + timer_data_sub_key + ' ' + + timer_data[key][timer_data_key][timer_data_sub_key] + ' ' + ts + "\n"; + } + } } numStats += 1; diff --git a/test/graphite_tests.js b/test/graphite_tests.js index c0a9b05..4cb1dab 100644 --- a/test/graphite_tests.js +++ b/test/graphite_tests.js @@ -76,6 +76,7 @@ module.exports = { , batch: 200 \n\ , flushInterval: " + this.myflush + " \n\ , percentThreshold: 90\n\ + , timer: {histogram: [ { metric: \"a_test_value\", bins: [10] } ]}\n\ , port: 8125\n\ , dumpMessages: false \n\ , debug: false\n\ @@ -214,6 +215,7 @@ module.exports = { var mykey = 'stats.timers.a_test_value.mean_90'; return _.include(_.keys(post),mykey) && (post[mykey] == testvalue); }; + //TODO: test here that one of the histogram datapoints is also correct test.ok(_.any(hashes,testtimervalue_test), 'stats.timers.a_test_value.mean should be ' + testvalue); test.done();