Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
Don't submit tags for legacy payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanmikaelian committed Mar 13, 2017
1 parent 1609dfe commit 24577c0
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lib/librato.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ var post_metrics = function(ts, gauges, counters, measurements)

payload = JSON.stringify(payload);
options.path = "/v1/metrics";
options.headers["Content-Length"] = payload.length
post_payload(options, proto, payload, true);
}
};
Expand Down Expand Up @@ -294,7 +295,8 @@ var flush_stats = function librato_flush(ts, metrics)
measure.tags = {};
measureName = parse_and_set_tags(measureName, measure);

// Use first capturing group as source name
// Use first capturing group as source name.
// NOTE: Only legacy users will a) have a source and b) have a source set by regex
if (sourceRegex && (match = measureName.match(sourceRegex)) && match[1]) {
measure.source = sanitize_name(match[1]);
// Remove entire matching string from the measure name & add global prefix.
Expand All @@ -315,16 +317,27 @@ var flush_stats = function librato_flush(ts, metrics)
return;
}

measurements.push(measure);

if (writeToLegacy) {
// Remove the tags
var legacyMeasure = {};
extend(legacyMeasure, measure);
delete legacyMeasure.tags;

// Set the source if there isn't one pulled from the regex
if (!legacyMeasure.source) {
legacyMeasure.source = sourceName
}

if (mType == 'counter') {
counters.push(measure);
counters.push(legacyMeasure);
} else {
gauges.push(measure);
gauges.push(legacyMeasure);
}
}

// Add the payload
measurements.push(measure);

// Post measurements and clear arrays if past batch size
if (measurements >= maxBatchSize || (writeToLegacy && (counters.length + gauges.length >= maxBatchSize)) ) {
post_metrics(measureTime, gauges, counters, measurements);
Expand Down

0 comments on commit 24577c0

Please sign in to comment.