Skip to content

Commit 1e78981

Browse files
committed
fix(metrics): discard undefined responseTimes
1 parent 3504294 commit 1e78981

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/agent/metrics/externalEdge/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var debug = require('debug')('risingstack/trace')
12
var flatMap = require('lodash.flatmap')
23
var consts = require('../../../consts')
34

@@ -36,6 +37,12 @@ ExternalEdgeMetrics.prototype.initProtocol = function (data) {
3637
}
3738

3839
ExternalEdgeMetrics.prototype.report = function (data) {
40+
// protect against bad use of the report function: responseTime is required
41+
// TODO: check all instrumentations to be sure they send a responseTime
42+
if (!data.responseTime) {
43+
debug('ExternalEdgeMetrics.report responseTime is undefined, discarding')
44+
return
45+
}
3946
this.initProtocol(data)
4047
var edge = this.initHost(data)
4148

lib/agent/metrics/externalEdge/index.spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,32 @@ var expect = require('chai').expect
33
var ExternalEdgeMetrics = require('./')
44

55
describe('The ExternalEdgeMetrics module', function () {
6+
it('discards undefined responseTime values', function () {
7+
var ISOString = 'date-string'
8+
var collectorApi = {
9+
sendExternalEdgeMetrics: this.sandbox.spy()
10+
}
11+
12+
var edgeMetrics = ExternalEdgeMetrics.create({
13+
collectorApi: collectorApi,
14+
config: {
15+
collectInterval: 1
16+
}
17+
})
18+
19+
this.sandbox.stub(Date.prototype, 'toISOString', function () {
20+
return ISOString
21+
})
22+
23+
edgeMetrics.report({
24+
targetHost: 'rstckapp.com',
25+
protocol: 'psql',
26+
status: 0
27+
})
28+
29+
expect(edgeMetrics.metrics).to.eql({})
30+
})
31+
632
it('sends metrics', function () {
733
var ISOString = 'date-string'
834
var collectorApi = {

0 commit comments

Comments
 (0)