Skip to content

Commit 3504294

Browse files
committed
fix(metrics): discard negative transport delay values
1 parent 0fad0ad commit 3504294

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/agent/metrics/incomingEdge/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ IncomingEdgeMetrics.prototype._getEdge = function (protocol, serviceKey) {
3030
}
3131

3232
IncomingEdgeMetrics.prototype.report = function (data) {
33+
// the transportDelay can be negative in some edge-cases:
34+
// * system clocks are out of sync
35+
// * ran locally with clock issues
36+
if (data.transportDelay < 0) {
37+
return
38+
}
3339
var serviceKey = data.serviceKey === undefined
3440
? 'root' : data.serviceKey
3541
var edge = this._getEdge(data.protocol, serviceKey)

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

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

55
describe('The IncomingEdgeMetrics module', function () {
6+
it('discards negative transportDelays', function () {
7+
var ISOString = 'date-string'
8+
var collectorApi = {
9+
sendIncomingEdgeMetrics: this.sandbox.spy()
10+
}
11+
12+
var edgeMetrics = EdgeMetrics.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+
serviceKey: 3,
25+
protocol: 'http',
26+
transportDelay: -10
27+
})
28+
expect(edgeMetrics.metrics).to.eql({})
29+
})
30+
631
it('sends metrics', function () {
732
var ISOString = 'date-string'
833
var collectorApi = {

0 commit comments

Comments
 (0)