Skip to content

Commit

Permalink
wrap up test for rate counter, add recordCounterRates to example conf…
Browse files Browse the repository at this point in the history
…iguration, do not record counter rates if config says to not do that thing
  • Loading branch information
mediocretes committed Mar 28, 2016
1 parent af2985d commit 0980b63
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 58 deletions.
1 change: 1 addition & 0 deletions exampleConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ exports.config = {
secure: true, // OPTIONAL (boolean), whether or not to use secure protocol to connect to Instrumental, default true
verify_cert: true, // OPTIONAL (boolean), should we attempt to verify the server certificate before allowing communication, default true
timeout: 10000, // OPTIONAL (integer), number of milliseconds to wait for establishing a connection to Instrumental before giving up, default 10s
recordCounterRates: true, // OPTIONAL (boolean) whether or not to send ".rate" metrics with counters, default true
}
}
10 changes: 5 additions & 5 deletions lib/instrumental.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ exports.build_payload = function build_payload(metrics, time_stamp) {
if(v !== 0) {
payload.push(p.inc(k, v, time_stamp));
}
console.log("config recordCounterRates: " + recordCounterRates)
// if(recordCounterRates) {

if(recordCounterRates) {
var vps = metrics.counter_rates[k];
payload.push(p.gauge_abs([k, "rate"].join("."), vps, time_stamp));
// }
}
}

// gauge item.time 7292 121820381
Expand Down Expand Up @@ -221,10 +221,10 @@ exports.init = function instrumental_init(startup_time, config, events) {
timeout = Number(config.instrumental.timeout || 10000);

// Record counter_rates by default
if(typeof(config.instrumental.record_counter_rates) == 'undefined'){
if(typeof(config.instrumental.recordCounterRates) == 'undefined'){
recordCounterRates = true;
} else {
recordCounterRates = config.instrumental.record_counter_rates;
recordCounterRates = config.instrumental.recordCounterRates;
}

if(typeof(config.instrumental.secure) == 'undefined'){
Expand Down
60 changes: 7 additions & 53 deletions test/instrumental_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,20 @@ test('counter_rate should not report if disabled in configuration', function (t)
counter_rates: { 'my.test.1': 280.5 }
};

// console.log("CONFIG: " + JSON.stringify(config));
// console.log("INSTRUMENTAL: " + JSON.stringify(config.instrumental));
var now = Math.round(new Date().getTime() / 1000);
var dummy_events = { on: function(e){ } };
instrumental.init(now, config, dummy_events)

// Enable rate counters and ensure they are recorded
config.instrumental.recordCounterRates = true;
var payload = instrumental.build_payload(metrics);

//var expected_payload = ["increment my.test.1 2805 ","gauge_absolute my.test.1.rate 280.5 "]
// t.equal(expected_payload, payload)
// t.fail("record_counter_rates should have a default")
var payload = instrumental.build_payload(metrics)

// TODO: What's with the fucking space on the end of this string?
t.assert(payload.indexOf("gauge_absolute my.test.1.rate 280.5 ") > -1, "Expected a rate metric, got: " + JSON.stringify(payload))

// Disable rate counters and ensure they are NOT recorded
config.instrumental.record_counter_rates = false;
config.instrumental.recordCounterRates = false;
instrumental.init(now, config, dummy_events);

var payload = instrumental.build_payload(metrics);
payload.forEach(function(instrumental_metric) {
if (instrumental_metric.indexOf("rate") > -1) {
Expand All @@ -35,49 +33,5 @@ test('counter_rate should not report if disabled in configuration', function (t)
}
})


// [ 'gauge_absolute statsd.bad_lines_seen.rate 0 ', 'increment statsd.packets_received 581 ', 'gauge_absolute statsd.packets_received.rate 58.1 ', 'increment my.test.1 2805 ', 'gauge_absolute my.test.1.rate 280.5 ', 'gauge_absolute my.test.1.count_90 9 ', 'gauge_absolute my.test.1.mean_90 0.3333333333333333 ', 'gauge_absolute my.test.1.upper_90 1 ', 'gauge_absolute my.test.1.sum_90 3 ', 'gauge_absolute my.test.1.sum_squares_90 3 ', 'gauge_absolute my.test.1.std 0.4898979485566356 ', 'gauge_absolute my.test.1.upper 1 ', 'gauge_absolute my.test.1.lower 0 ', 'gauge_absolute my.test.1.count 10 ', 'gauge_absolute my.test.1.count_ps 1 ', 'gauge_absolute my.test.1.sum 4 ', 'gauge_absolute my.test.1.sum_squares 4 ', 'gauge_absolute my.test.1.mean 0.4 ', 'gauge_absolute my.test.1.median 0 ', 'gauge my.test.1 4 ', 'gauge statsd.timestamp_lag 0 ' ]


// assert payload is an array
// assert array does not contain any counter_rate metrics

t.end();
});



/*
var metrics = {
counters:
{ 'statsd.bad_lines_seen': 0,
'statsd.packets_received': 581,
'my.test.1': 2805 },
gauges: { 'my.test.1': 4, 'statsd.timestamp_lag': 0 },
timers: { 'my.test.1': [ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 ] },
timer_counters: { 'my.test.1': 10 },
sets: {},
counter_rates:
{ 'statsd.bad_lines_seen': 0,
'statsd.packets_received': 58.1,
'my.test.1': 280.5 },
timer_data:
{ 'my.test.1':
{ count_90: 9,
mean_90: 0.3333333333333333,
upper_90: 1,
sum_90: 3,
sum_squares_90: 3,
std: 0.4898979485566356,
upper: 1,
lower: 0,
count: 10,
count_ps: 1,
sum: 4,
sum_squares: 4,
mean: 0.4,
median: 0 } },
pctThreshold: [ 90 ],
histogram: undefined,
statsd_metrics: { processing_time: 0 } };
*/

0 comments on commit 0980b63

Please sign in to comment.