forked from statsd/statsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_metrics_tests.js
166 lines (159 loc) · 6.35 KB
/
process_metrics_tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
var pm = require('../lib/process_metrics'),
_ = require('underscore');
module.exports = {
setUp: function (callback) {
this.time_stamp = Math.round(new Date().getTime() / 1000);
var counters = {};
var gauges = {};
var timers = {};
var sets = {};
var pctThreshold = null;
this.metrics = {
counters: counters,
gauges: gauges,
timers: timers,
sets: sets,
pctThreshold: pctThreshold
}
callback();
},
counters_has_stats_count: function(test) {
test.expect(1);
this.metrics.counters['a'] = 2;
pm.process_metrics(this.metrics, 1000, this.time_stamp, function(){});
test.equal(2, this.metrics.counters['a']);
test.done();
},
counters_has_correct_rate: function(test) {
test.expect(1);
this.metrics.counters['a'] = 2;
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
test.equal(20, this.metrics.counter_rates['a']);
test.done();
},
timers_handle_empty: function(test) {
test.expect(1);
this.metrics.timers['a'] = [];
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']);
test.done();
},
timers_single_time: function(test) {
test.expect(6);
this.metrics.timers['a'] = [100];
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
timer_data = this.metrics.timer_data['a'];
test.equal(0, timer_data.std);
test.equal(100, timer_data.upper);
test.equal(100, timer_data.lower);
test.equal(1, timer_data.count);
test.equal(100, timer_data.sum);
test.equal(100, timer_data.mean);
test.done();
},
timers_multiple_times: function(test) {
test.expect(6);
this.metrics.timers['a'] = [100, 200, 300];
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
timer_data = this.metrics.timer_data['a'];
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);
test.equal(600, timer_data.sum);
test.equal(200, timer_data.mean);
test.done();
},
timers_single_time_single_percentile: function(test) {
test.expect(3);
this.metrics.timers['a'] = [100];
this.metrics.pctThreshold = [90];
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
timer_data = this.metrics.timer_data['a'];
test.equal(100, timer_data.mean_90);
test.equal(100, timer_data.upper_90);
test.equal(100, timer_data.sum_90);
test.done();
},
timers_single_time_multiple_percentiles: function(test) {
test.expect(6);
this.metrics.timers['a'] = [100];
this.metrics.pctThreshold = [90, 80];
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
timer_data = this.metrics.timer_data['a'];
test.equal(100, timer_data.mean_90);
test.equal(100, timer_data.upper_90);
test.equal(100, timer_data.sum_90);
test.equal(100, timer_data.mean_80);
test.equal(100, timer_data.upper_80);
test.equal(100, timer_data.sum_80);
test.done();
},
timers_multiple_times_single_percentiles: function(test) {
test.expect(3);
this.metrics.timers['a'] = [100, 200, 300];
this.metrics.pctThreshold = [90];
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
timer_data = this.metrics.timer_data['a'];
test.equal(200, timer_data.mean_90);
test.equal(300, timer_data.upper_90);
test.equal(600, timer_data.sum_90);
test.done();
},
timers_multiple_times_multiple_percentiles: function(test) {
test.expect(6);
this.metrics.timers['a'] = [100, 200, 300];
this.metrics.pctThreshold = [90, 80];
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
timer_data = this.metrics.timer_data['a'];
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);
test.done();
}, // check if the correct settings are being applied. as well as actual counts
timers_histogram: function (test) {
test.expect(13);
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
test.equal(undefined, timer_data['a']['histogram']['bin_5']);
test.equal(undefined, timer_data['abc']['histogram']['bin_5']);
// check that 'a' got the right config and numbers
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']);
// only 'abc' should have a bin_inf; also check all its counts,
// and make sure it has no other bins
test.equal(1, timer_data['abc']['histogram']['bin_1']);
test.equal(0, timer_data['abc']['histogram']['bin_2_21']);
test.equal(4, timer_data['abc']['histogram']['bin_inf']);
test.equal(3, _.size(timer_data['abc']['histogram']));
// 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']);
test.done();
},
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();
}
}