[FIX] StatsD entry format (#2107)
* [dataGenerator] Test individual lines instead of bulk * [dataGenerator] Add EOL to pattern test (should fail) * [dataGenerator] only push timestamp to Graphite (not StatsD)
This commit is contained in:
parent
9cc886690e
commit
da1f64ac9d
|
|
@ -7,6 +7,9 @@ const flatten = require('../../support/flattenMessage'),
|
|||
formatEntry = require('./helpers/format-entry'),
|
||||
isStatsd = require('./helpers/is-statsd');
|
||||
|
||||
const STATSD = 'statsd';
|
||||
const GRAPHITE = 'graphite';
|
||||
|
||||
function keyPathFromMessage(message, options, includeQueryParams) {
|
||||
let typeParts = message.type.split('.');
|
||||
typeParts.push(typeParts.shift());
|
||||
|
|
@ -55,7 +58,7 @@ class GraphiteDataGenerator {
|
|||
this.namespace = namespace;
|
||||
this.includeQueryParams = !!includeQueryParams;
|
||||
this.options = options;
|
||||
this.entryFormat = isStatsd(options.graphite) ? 'statsd' : 'graphite';
|
||||
this.entryFormat = isStatsd(options.graphite) ? STATSD : GRAPHITE;
|
||||
}
|
||||
|
||||
dataFromMessage(message, time) {
|
||||
|
|
@ -71,9 +74,10 @@ class GraphiteDataGenerator {
|
|||
flatten.flattenMessageData(message),
|
||||
(entries, value, key) => {
|
||||
const fullKey = util.format('%s.%s.%s', this.namespace, keypath, key);
|
||||
entries.push(
|
||||
util.format(formatEntry(this.entryFormat), fullKey, value, timestamp)
|
||||
);
|
||||
const args = [formatEntry(this.entryFormat), fullKey, value];
|
||||
this.entryFormat === GRAPHITE && args.push(timestamp);
|
||||
|
||||
entries.push(util.format.apply(util, args));
|
||||
return entries;
|
||||
},
|
||||
[]
|
||||
|
|
|
|||
|
|
@ -99,9 +99,11 @@ describe('graphite', function() {
|
|||
});
|
||||
var data = generator.dataFromMessage(message, moment());
|
||||
|
||||
expect(data).to.match(
|
||||
/ns.summary.sub_domain_com.chrome.cable.domains.www.sitespeed.io.dns.median:[\d]{1,}\|ms/
|
||||
);
|
||||
data.forEach(function(line) {
|
||||
expect(line).to.match(
|
||||
/ns.summary.sub_domain_com.chrome.cable.domains.www.sitespeed.io.dns.(median|mean|min|p10|p90|p99|max):[\d]{1,}\|ms$/
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue