2012-12-10 01:59:00 +04:00
|
|
|
var pm = require('../lib/process_metrics'),
|
|
|
|
_ = require('underscore');
|
2012-10-13 08:33:05 +04:00
|
|
|
|
2012-10-15 09:53:50 +04:00
|
|
|
module.exports = {
|
|
|
|
setUp: function (callback) {
|
|
|
|
this.time_stamp = Math.round(new Date().getTime() / 1000);
|
2012-10-13 08:33:05 +04:00
|
|
|
|
2012-10-15 09:53:50 +04:00
|
|
|
var counters = {};
|
|
|
|
var gauges = {};
|
|
|
|
var timers = {};
|
2013-02-01 20:43:50 +04:00
|
|
|
var timer_counters = {};
|
2012-10-15 09:53:50 +04:00
|
|
|
var sets = {};
|
|
|
|
var pctThreshold = null;
|
2012-10-13 08:33:05 +04:00
|
|
|
|
2012-10-15 09:53:50 +04:00
|
|
|
this.metrics = {
|
|
|
|
counters: counters,
|
|
|
|
gauges: gauges,
|
|
|
|
timers: timers,
|
2013-02-01 20:43:50 +04:00
|
|
|
timer_counters: timer_counters,
|
2012-10-15 09:53:50 +04:00
|
|
|
sets: sets,
|
|
|
|
pctThreshold: pctThreshold
|
|
|
|
}
|
|
|
|
callback();
|
|
|
|
},
|
2012-10-13 08:33:05 +04:00
|
|
|
counters_has_stats_count: function(test) {
|
|
|
|
test.expect(1);
|
2012-10-15 09:53:50 +04:00
|
|
|
this.metrics.counters['a'] = 2;
|
|
|
|
pm.process_metrics(this.metrics, 1000, this.time_stamp, function(){});
|
|
|
|
test.equal(2, this.metrics.counters['a']);
|
2012-10-13 08:33:05 +04:00
|
|
|
test.done();
|
|
|
|
},
|
|
|
|
counters_has_correct_rate: function(test) {
|
|
|
|
test.expect(1);
|
2012-10-15 09:53:50 +04:00
|
|
|
this.metrics.counters['a'] = 2;
|
|
|
|
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
|
|
|
|
test.equal(20, this.metrics.counter_rates['a']);
|
2012-10-13 08:33:05 +04:00
|
|
|
test.done();
|
|
|
|
},
|
|
|
|
timers_handle_empty: function(test) {
|
|
|
|
test.expect(1);
|
2012-10-15 09:53:50 +04:00
|
|
|
this.metrics.timers['a'] = [];
|
2013-02-01 20:43:50 +04:00
|
|
|
this.metrics.timer_counters['a'] = 0;
|
2012-10-15 09:53:50 +04:00
|
|
|
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
|
|
|
|
//potentially a cleaner way to check this
|
|
|
|
test.equal(undefined, this.metrics.counter_rates['a']);
|
2012-10-13 08:33:05 +04:00
|
|
|
test.done();
|
|
|
|
},
|
|
|
|
timers_single_time: function(test) {
|
2013-12-11 04:09:58 +04:00
|
|
|
test.expect(9);
|
2012-10-15 09:53:50 +04:00
|
|
|
this.metrics.timers['a'] = [100];
|
2013-02-01 20:43:50 +04:00
|
|
|
this.metrics.timer_counters['a'] = 1;
|
2012-10-15 09:53:50 +04:00
|
|
|
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
|
|
|
|
timer_data = this.metrics.timer_data['a'];
|
2012-10-13 08:33:05 +04:00
|
|
|
test.equal(0, timer_data.std);
|
|
|
|
test.equal(100, timer_data.upper);
|
|
|
|
test.equal(100, timer_data.lower);
|
|
|
|
test.equal(1, timer_data.count);
|
2013-02-01 20:43:50 +04:00
|
|
|
test.equal(10, timer_data.count_ps);
|
2012-10-13 08:33:05 +04:00
|
|
|
test.equal(100, timer_data.sum);
|
2013-12-11 04:09:58 +04:00
|
|
|
test.equal(100 * 100, timer_data.sum_squares);
|
2012-10-13 08:33:05 +04:00
|
|
|
test.equal(100, timer_data.mean);
|
2013-03-22 09:10:26 +04:00
|
|
|
test.equal(100, timer_data.median);
|
2012-10-13 08:33:05 +04:00
|
|
|
test.done();
|
|
|
|
},
|
|
|
|
timers_multiple_times: function(test) {
|
2013-12-11 04:09:58 +04:00
|
|
|
test.expect(9);
|
2012-10-15 09:53:50 +04:00
|
|
|
this.metrics.timers['a'] = [100, 200, 300];
|
2013-02-01 20:43:50 +04:00
|
|
|
this.metrics.timer_counters['a'] = 3;
|
2012-10-15 09:53:50 +04:00
|
|
|
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
|
|
|
|
timer_data = this.metrics.timer_data['a'];
|
2012-10-13 08:33:05 +04:00
|
|
|
test.equal(81.64965809277261, timer_data.std);
|
|
|
|
test.equal(300, timer_data.upper);
|
|
|
|
test.equal(100, timer_data.lower);
|
|
|
|
test.equal(3, timer_data.count);
|
2013-02-01 20:43:50 +04:00
|
|
|
test.equal(30, timer_data.count_ps);
|
2012-10-13 08:33:05 +04:00
|
|
|
test.equal(600, timer_data.sum);
|
2013-12-11 04:09:58 +04:00
|
|
|
test.equal(100 * 100 + 200 * 200 + 300 * 300,
|
|
|
|
timer_data.sum_squares);
|
2012-10-13 08:33:05 +04:00
|
|
|
test.equal(200, timer_data.mean);
|
2013-03-22 09:10:26 +04:00
|
|
|
test.equal(200, timer_data.median);
|
2012-10-13 08:33:05 +04:00
|
|
|
test.done();
|
|
|
|
},
|
|
|
|
timers_single_time_single_percentile: function(test) {
|
2013-12-11 04:09:58 +04:00
|
|
|
test.expect(4);
|
2012-10-15 09:53:50 +04:00
|
|
|
this.metrics.timers['a'] = [100];
|
2013-02-01 20:43:50 +04:00
|
|
|
this.metrics.timer_counters['a'] = 1;
|
2012-10-15 09:53:50 +04:00
|
|
|
this.metrics.pctThreshold = [90];
|
|
|
|
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
|
|
|
|
timer_data = this.metrics.timer_data['a'];
|
2012-10-13 08:33:05 +04:00
|
|
|
test.equal(100, timer_data.mean_90);
|
|
|
|
test.equal(100, timer_data.upper_90);
|
|
|
|
test.equal(100, timer_data.sum_90);
|
2013-12-11 04:09:58 +04:00
|
|
|
test.equal(100 * 100, timer_data.sum_squares_90);
|
2012-10-13 08:33:05 +04:00
|
|
|
test.done();
|
|
|
|
},
|
|
|
|
timers_single_time_multiple_percentiles: function(test) {
|
2013-12-11 04:09:58 +04:00
|
|
|
test.expect(9);
|
2012-10-15 09:53:50 +04:00
|
|
|
this.metrics.timers['a'] = [100];
|
2013-02-01 20:43:50 +04:00
|
|
|
this.metrics.timer_counters['a'] = 1;
|
2012-10-15 09:53:50 +04:00
|
|
|
this.metrics.pctThreshold = [90, 80];
|
|
|
|
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
|
|
|
|
timer_data = this.metrics.timer_data['a'];
|
2013-12-11 03:21:58 +04:00
|
|
|
test.equal(1, timer_data.count_90);
|
2012-10-13 08:33:05 +04:00
|
|
|
test.equal(100, timer_data.mean_90);
|
|
|
|
test.equal(100, timer_data.upper_90);
|
|
|
|
test.equal(100, timer_data.sum_90);
|
2013-12-11 04:09:58 +04:00
|
|
|
test.equal(100 * 100, timer_data.sum_squares_90);
|
2012-10-13 08:33:05 +04:00
|
|
|
test.equal(100, timer_data.mean_80);
|
|
|
|
test.equal(100, timer_data.upper_80);
|
|
|
|
test.equal(100, timer_data.sum_80);
|
2013-12-11 04:09:58 +04:00
|
|
|
test.equal(100 * 100, timer_data.sum_squares_80);
|
2012-10-13 08:33:05 +04:00
|
|
|
test.done();
|
|
|
|
},
|
|
|
|
timers_multiple_times_single_percentiles: function(test) {
|
2013-12-11 04:09:58 +04:00
|
|
|
test.expect(5);
|
2012-10-15 09:53:50 +04:00
|
|
|
this.metrics.timers['a'] = [100, 200, 300];
|
2013-02-01 20:43:50 +04:00
|
|
|
this.metrics.timer_counters['a'] = 3;
|
2012-10-15 09:53:50 +04:00
|
|
|
this.metrics.pctThreshold = [90];
|
|
|
|
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
|
|
|
|
timer_data = this.metrics.timer_data['a'];
|
2013-12-11 03:21:58 +04:00
|
|
|
test.equal(3, timer_data.count_90);
|
2012-10-13 08:33:05 +04:00
|
|
|
test.equal(200, timer_data.mean_90);
|
|
|
|
test.equal(300, timer_data.upper_90);
|
|
|
|
test.equal(600, timer_data.sum_90);
|
2013-12-11 04:09:58 +04:00
|
|
|
test.equal(100 * 100 + 200 * 200 + 300 * 300,
|
|
|
|
timer_data.sum_squares_90);
|
2012-10-13 08:33:05 +04:00
|
|
|
test.done();
|
|
|
|
},
|
|
|
|
timers_multiple_times_multiple_percentiles: function(test) {
|
2013-12-11 04:09:58 +04:00
|
|
|
test.expect(11);
|
2012-10-15 09:53:50 +04:00
|
|
|
this.metrics.timers['a'] = [100, 200, 300];
|
2013-02-01 20:43:50 +04:00
|
|
|
this.metrics.timer_counters['a'] = 3;
|
|
|
|
this.metrics.pctThreshold = [90, 80];
|
|
|
|
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
|
|
|
|
timer_data = this.metrics.timer_data['a'];
|
2013-12-11 03:21:58 +04:00
|
|
|
test.equal(3, timer_data.count);
|
|
|
|
test.equal(3, timer_data.count_90);
|
2013-02-01 20:43:50 +04:00
|
|
|
test.equal(200, timer_data.mean_90);
|
|
|
|
test.equal(300, timer_data.upper_90);
|
|
|
|
test.equal(600, timer_data.sum_90);
|
2013-12-11 04:09:58 +04:00
|
|
|
test.equal(100 * 100 + 200 * 200 + 300 * 300,
|
|
|
|
timer_data.sum_squares_90);
|
2013-12-11 03:21:58 +04:00
|
|
|
|
|
|
|
test.equal(2, timer_data.count_80);
|
2013-02-01 20:43:50 +04:00
|
|
|
test.equal(150, timer_data.mean_80);
|
|
|
|
test.equal(200, timer_data.upper_80);
|
|
|
|
test.equal(300, timer_data.sum_80);
|
2013-12-11 04:09:58 +04:00
|
|
|
test.equal(100 * 100 + 200 * 200,
|
|
|
|
timer_data.sum_squares_80);
|
2013-02-01 20:43:50 +04:00
|
|
|
test.done();
|
|
|
|
},
|
|
|
|
timers_sampled_times: function(test) {
|
|
|
|
test.expect(8);
|
|
|
|
this.metrics.timers['a'] = [100, 200, 300];
|
|
|
|
this.metrics.timer_counters['a'] = 50;
|
2012-10-15 09:53:50 +04:00
|
|
|
this.metrics.pctThreshold = [90, 80];
|
|
|
|
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
|
|
|
|
timer_data = this.metrics.timer_data['a'];
|
2013-02-01 20:43:50 +04:00
|
|
|
test.equal(50, timer_data.count);
|
|
|
|
test.equal(500, timer_data.count_ps);
|
2012-10-13 08:33:05 +04:00
|
|
|
test.equal(200, timer_data.mean_90);
|
|
|
|
test.equal(300, timer_data.upper_90);
|
|
|
|
test.equal(600, timer_data.sum_90);
|
|
|
|
test.equal(150, timer_data.mean_80);
|
|
|
|
test.equal(200, timer_data.upper_80);
|
|
|
|
test.equal(300, timer_data.sum_80);
|
2012-12-10 00:24:57 +04:00
|
|
|
test.done();
|
|
|
|
}, // check if the correct settings are being applied. as well as actual counts
|
|
|
|
timers_histogram: function (test) {
|
2012-12-10 01:59:00 +04:00
|
|
|
test.expect(13);
|
2012-12-10 00:24:57 +04:00
|
|
|
this.metrics.timers['a'] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
|
|
this.metrics.timers['abc'] = [0.1234, 2.89, 4, 6, 8];
|
|
|
|
this.metrics.timers['foo'] = [0, 2, 4, 6, 8];
|
|
|
|
this.metrics.timers['barbazfoobar'] = [0, 2, 4, 6, 8];
|
|
|
|
this.metrics.timers['bar.bazfoobar.abc'] = [0, 2, 4, 6, 8];
|
|
|
|
this.metrics.timers['xyz'] = [0, 2, 4, 6, 8];
|
|
|
|
this.metrics.histogram = [ { metric: 'foo', bins: [] },
|
|
|
|
{ metric: 'abcd', bins: [ 1, 5, 'inf'] },
|
|
|
|
{ metric: 'abc', bins: [ 1, 2.21, 'inf'] },
|
|
|
|
{ metric: 'a', bins: [ 1, 2] } ];
|
|
|
|
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
|
|
|
|
timer_data = this.metrics.timer_data;
|
|
|
|
// nothing matches the 'abcd' config, so nothing has bin_5
|
2012-12-10 01:59:00 +04:00
|
|
|
test.equal(undefined, timer_data['a']['histogram']['bin_5']);
|
|
|
|
test.equal(undefined, timer_data['abc']['histogram']['bin_5']);
|
2012-12-10 00:24:57 +04:00
|
|
|
|
|
|
|
// check that 'a' got the right config and numbers
|
2012-12-10 01:59:00 +04:00
|
|
|
test.equal(0, timer_data['a']['histogram']['bin_1']);
|
|
|
|
test.equal(1, timer_data['a']['histogram']['bin_2']);
|
|
|
|
test.equal(undefined, timer_data['a']['histogram']['bin_inf']);
|
2012-12-10 00:24:57 +04:00
|
|
|
|
|
|
|
// only 'abc' should have a bin_inf; also check all its counts,
|
|
|
|
// and make sure it has no other bins
|
2012-12-10 01:59:00 +04:00
|
|
|
test.equal(1, timer_data['abc']['histogram']['bin_1']);
|
2014-04-17 21:43:32 +04:00
|
|
|
test.equal(0, timer_data['abc']['histogram']['bin_2_21']);
|
2012-12-10 01:59:00 +04:00
|
|
|
test.equal(4, timer_data['abc']['histogram']['bin_inf']);
|
|
|
|
test.equal(3, _.size(timer_data['abc']['histogram']));
|
2012-12-10 00:24:57 +04:00
|
|
|
|
2012-12-10 01:59:00 +04:00
|
|
|
// these all have histograms disabled ('foo' explicitly, rest implicitly)
|
|
|
|
test.equal(undefined, timer_data['foo']['histogram']);
|
|
|
|
test.equal(undefined, timer_data['barbazfoobar']['histogram']);
|
|
|
|
test.equal(undefined, timer_data['bar.bazfoobar.abc']['histogram']);
|
|
|
|
test.equal(undefined, timer_data['xyz']['histogram']);
|
2012-12-10 00:24:57 +04:00
|
|
|
|
2012-12-05 07:53:21 +04:00
|
|
|
test.done();
|
|
|
|
},
|
|
|
|
timers_single_time_single_top_percentile: function(test) {
|
|
|
|
test.expect(3);
|
|
|
|
this.metrics.timers['a'] = [100];
|
|
|
|
this.metrics.pctThreshold = [-10];
|
|
|
|
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
|
|
|
|
timer_data = this.metrics.timer_data['a'];
|
|
|
|
test.equal(100, timer_data.mean_top10);
|
|
|
|
test.equal(100, timer_data.lower_top10);
|
|
|
|
test.equal(100, timer_data.sum_top10);
|
|
|
|
test.done();
|
|
|
|
},
|
|
|
|
timers_multiple_times_single_top_percentile: function(test) {
|
|
|
|
test.expect(3);
|
|
|
|
this.metrics.timers['a'] = [10, 10, 10, 10, 10, 10, 10, 10, 100, 200];
|
|
|
|
this.metrics.pctThreshold = [-20];
|
|
|
|
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
|
|
|
|
timer_data = this.metrics.timer_data['a'];
|
|
|
|
test.equal(150, timer_data.mean_top20);
|
|
|
|
test.equal(100, timer_data.lower_top20);
|
|
|
|
test.equal(300, timer_data.sum_top20);
|
2012-10-13 08:33:05 +04:00
|
|
|
test.done();
|
2012-11-12 02:51:24 +04:00
|
|
|
},
|
|
|
|
statsd_metrics_exist: function(test) {
|
|
|
|
test.expect(1);
|
|
|
|
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
|
|
|
|
statsd_metrics = this.metrics.statsd_metrics;
|
|
|
|
test.notEqual(undefined, statsd_metrics["processing_time"]);
|
|
|
|
test.done();
|
2013-03-22 09:10:26 +04:00
|
|
|
},
|
|
|
|
timers_multiple_times_even: function(test) {
|
|
|
|
test.expect(1);
|
2013-03-22 09:28:32 +04:00
|
|
|
this.metrics.timers['a'] = [300, 200, 400, 100];
|
2013-03-22 09:10:26 +04:00
|
|
|
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
|
|
|
|
timer_data = this.metrics.timer_data['a'];
|
|
|
|
test.equal(250, timer_data.median);
|
|
|
|
test.done();
|
2012-10-13 08:33:05 +04:00
|
|
|
}
|
|
|
|
}
|