-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metrics: merge on failed transmission.
There's been a regression lurking for a while now that only got exercised when the agent switched to Object.keys from an old-style for...in enumeration of the properties on the object. This exposed that the object being passed to Agent.prototype.mergeMetrics was not, in fact, a metrics object, but the pre-serialization JSON array expected by the collector. Also added nock because Sinon doesn't have a way to easily mock HTTP requests from Node. Nock's nice! Thanks, Pedro!
- Loading branch information
Forrest L Norvell
committed
Aug 7, 2013
1 parent
6de4a73
commit b13179b
Showing
3 changed files
with
89 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
'use strict'; | ||
|
||
var path = require('path') | ||
, test = require('tap').test | ||
, nock = require('nock') | ||
, dns = require ('dns') | ||
, Agent = require(path.join(__dirname, '..', '..', 'lib', 'agent.js')) | ||
, Transaction = require(path.join(__dirname, '..', '..', 'lib', 'transaction.js')) | ||
; | ||
|
||
test("harvesting with a mocked collector that returns 503", function (t) { | ||
nock.disableNetConnect(); | ||
|
||
dns.lookup('collector.newrelic.com', function (error, collector) { | ||
if (error) { | ||
t.fail(error); | ||
t.end(); | ||
} | ||
|
||
var RUN_ID = 1337 | ||
, url = 'http://' + collector | ||
, agent = new Agent() | ||
, transaction = new Transaction(agent) | ||
; | ||
|
||
function path(method, runID) { | ||
var fragment = '/agent_listener/invoke_raw_method?' + | ||
'marshal_format=json&protocol_version=9&' + | ||
'license_key=license%20key%20here&method=' + method; | ||
|
||
if (runID) fragment += '&run_id=' + runID; | ||
|
||
return fragment; | ||
} | ||
|
||
var redirect = nock(url).post(path('get_redirect_host')) | ||
.reply(200, {return_value : "collector.newrelic.com"}); | ||
|
||
var handshake = nock(url).post(path('connect')) | ||
.reply(200, {return_value : {agent_run_id : 1337}}); | ||
|
||
var sendMetrics = nock(url).post(path('metric_data', RUN_ID)).reply(503) | ||
, sendErrors = nock(url).post(path('error_data', RUN_ID)).reply(503) | ||
, sendTrace = nock(url).post(path('transaction_sample_data', RUN_ID)).reply(503) | ||
, shutdown = nock(url).post(path('shutdown', RUN_ID)).reply(503) | ||
; | ||
|
||
// needs to be created to create the connection attribute | ||
agent.start(); | ||
|
||
agent.connection.on('connect', function () { | ||
// disable the default harvester | ||
clearInterval(agent.harvesterHandle); | ||
|
||
agent.connection.on('transactionSampleDataError', function () { | ||
t.ok(redirect.isDone(), "requested redirect"); | ||
t.ok(handshake.isDone(), "got handshake"); | ||
t.ok(sendMetrics.isDone(), "tried to send metrics"); | ||
t.ok(sendErrors.isDone(), "tried to send errors"); | ||
t.ok(sendTrace.isDone(), "tried to send transaction trace"); | ||
|
||
agent.connection.on('shutdownError', function () { | ||
t.ok(shutdown.isDone(), "tried to send shutdown"); | ||
|
||
t.end(); | ||
}); | ||
|
||
agent.stop(); | ||
}); | ||
|
||
// need sample data to give the harvest cycle something to send | ||
agent.errors.add(transaction, new Error('test error')); | ||
agent.traces.trace = transaction.getTrace(); | ||
|
||
agent.harvest(); | ||
}); | ||
}); | ||
}); |