Skip to content

Commit

Permalink
NOT WORKING - optional counter_rate recording
Browse files Browse the repository at this point in the history
This is in-progress code to optional disable the statsd counter_rate metrics (one for each counter). Salesforce doesn't want them. The test is largely finished, but still has a few things to clean up plus some documentation about how to actually run the tests is needed.
  • Loading branch information
esquivalient committed Mar 8, 2016
1 parent 419fd7b commit af2985d
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 7 deletions.
2 changes: 1 addition & 1 deletion exampleConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Example StatsD configuration for sending metrics to Instrumental.
See the offical Statsd exampleConfig.js for more StatsD options.
*/
{
exports.config = {
port: 8125
, backends: ["statsd-instrumental-backend" ]
, debug: false
Expand Down
21 changes: 15 additions & 6 deletions lib/instrumental.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ var error = false;
var hostname = os.hostname();
var caChainPath = path.join("..", "certs");
var knownCerts = ["equifax", "geotrust", "rapidssl"];
var key, host, port, timeout, flushInterval, secure, verifyCert, caChain;
var exports = module.exports = {}; // for testing
var key, host, port, timeout, flushInterval, secure, verifyCert, caChain, recordCounterRates;

var instrumentalStats = {};

function build_payload(metrics, time_stamp) {
exports.build_payload = function build_payload(metrics, time_stamp) {
var payload = [];
// Iterators: key and value.
var k, v;
Expand All @@ -52,9 +53,11 @@ function build_payload(metrics, time_stamp) {
if(v !== 0) {
payload.push(p.inc(k, v, time_stamp));
}

var vps = metrics.counter_rates[k];
payload.push(p.gauge_abs([k, "rate"].join("."), vps, time_stamp));
console.log("config recordCounterRates: " + 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 @@ -214,10 +217,16 @@ exports.init = function instrumental_init(startup_time, config, events) {
key = config.instrumental.key;
host = config.instrumental.host || "collector.instrumentalapp.com";


// Default 10s timeout
timeout = Number(config.instrumental.timeout || 10000);

// Record counter_rates by default
if(typeof(config.instrumental.record_counter_rates) == 'undefined'){

This comment has been minimized.

Copy link
@jqr

jqr Mar 30, 2016

Contributor

This is the idiomatic way to handle key detection in a non-exception way:

if ("record_counter_rates" in config.instrumental) {
}
recordCounterRates = true;
} else {
recordCounterRates = config.instrumental.record_counter_rates;
}

if(typeof(config.instrumental.secure) == 'undefined'){
secure = true;
} else {
Expand Down
2 changes: 2 additions & 0 deletions script/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
tape test/*.js | faucet

This comment has been minimized.

Copy link
@jqr

jqr Mar 30, 2016

Contributor

Probably worth prepending a few things so this does exit codes simpler and isn't reliant upon current directory.

set -e
cd "$(dirname "$0")/.."
83 changes: 83 additions & 0 deletions test/instrumental_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
var test = require('tape');
// import 'core-js'
//import { build_payload } from "../lib/instrumental.js";
var instrumental = require("../lib/instrumental.js");
var config = require("../exampleConfig.js").config;

test('counter_rate should not report if disabled in configuration', function (t) {
var metrics = {
counters: { 'my.test.1': 2805 },
counter_rates: { 'my.test.1': 280.5 }
};

// console.log("CONFIG: " + JSON.stringify(config));
// console.log("INSTRUMENTAL: " + JSON.stringify(config.instrumental));

// 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")

// 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;
var payload = instrumental.build_payload(metrics);
payload.forEach(function(instrumental_metric) {
if (instrumental_metric.indexOf("rate") > -1) {
t.fail("Should not be any rate metrics: " + instrumental_metric);
} else {
t.pass();
}
})


// [ '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 af2985d

Please sign in to comment.