Skip to content

Commit

Permalink
Merge pull request newrelic#953 from NodeJS-agent/bclement/omit-insta…
Browse files Browse the repository at this point in the history
…nce-metrics

NODE-1204 metrics: don't send up db instance metrics
  • Loading branch information
Martin Kuba committed Sep 26, 2016
2 parents f3a5911 + c5afca9 commit b931360
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 82 deletions.
9 changes: 5 additions & 4 deletions lib/db/parsed-statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ ParsedStatement.prototype.recordMetrics = function recordMetrics(segment, scope)
segment.name = model || operation

// Datastore instance metrics.
if (segment.parameters.instance) {
var instanceName = DB.INSTANCE + '/' + thisTypeSlash + segment.parameters.instance
transaction.measure(instanceName, null, duration, exclusive)
}
// This is commented out due to future possible metric name changes.
// if (segment.parameters.instance) {
// var instanceName = DB.INSTANCE + '/' + thisTypeSlash + segment.parameters.instance
// transaction.measure(instanceName, null, duration, exclusive)
// }

if (this.raw) {
transaction.agent.queries.addQuery(
Expand Down
15 changes: 8 additions & 7 deletions lib/db/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,19 @@ QuerySample.prototype.prepareJSON = function prepareJSON(done) {
}

QuerySample.prototype.getParams = function getParams() {
var segmentParams = this.trace.segment.parameters
// var segmentParams = this.trace.segment.parameters
var params = {
backtrace: this.trace.trace,
}

if (segmentParams.instance) {
params.instance = segmentParams.instance
}
// XXX: Uncomment this once metric names have been decided on
// if (segmentParams.instance) {
// params.instance = segmentParams.instance
// }

if (segmentParams.database_name) {
params.database_name = segmentParams.database_name
}
// if (segmentParams.database_name) {
// params.database_name = segmentParams.database_name
// }

return params
}
Expand Down
7 changes: 4 additions & 3 deletions lib/db/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var INSTANCE_UNKNOWN = 'unknown'


exports.captureInstanceAttributes = captureInstanceAttributes
function captureInstanceAttributes(segment, host, port, database) {
function captureInstanceAttributes(segment, host, port/* , database */) {
port = port || INSTANCE_UNKNOWN
if (host && urltils.isLocalhost(host)) {
host = segment.transaction.agent.config.getHostnameSafe(host)
Expand All @@ -15,6 +15,7 @@ function captureInstanceAttributes(segment, host, port, database) {
host = INSTANCE_UNKNOWN
}

segment.parameters.database_name = database || INSTANCE_UNKNOWN
segment.parameters.instance = host + ':{' + port + '}'
// XXX: Uncomment this when metric names have been decided on
// segment.parameters.database_name = database || INSTANCE_UNKNOWN
// segment.parameters.instance = host + ':{' + port + '}'
}
37 changes: 20 additions & 17 deletions test/versioned/pg-1/pg.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,25 @@ module.exports = function runTests(agent, pg, name) {
expected['Datastore/statement/Postgres/' + selectTable + '/select'] = 1

var hostId = METRIC_HOST_NAME + ':{' + params.postgres_port + '}'
expected['Datastore/instance/Postgres/' + hostId] = 2
// this should be uncommented out when instance metrics are sent up
// expected['Datastore/instance/Postgres/' + hostId] = 2

var slowQuerySamples = agent.queries.samples
for (var key in slowQuerySamples) {
var queryParams = slowQuerySamples[key].getParams()

t.equal(
queryParams.instance,
hostId,
'instance data should show up in slow query params'
)
// XXX: Uncomment once metric names have been decided on
// t.equal(
// queryParams.instance,
// hostId,
// 'instance data should show up in slow query params'
// )

t.equal(
queryParams.database_name,
params.postgres_db,
'database name should show up in slow query params'
)
// t.equal(
// queryParams.database_name,
// params.postgres_db,
// 'database name should show up in slow query params'
// )

t.ok(queryParams.backtrace, 'params should contain a backtrace')
}
Expand Down Expand Up @@ -134,12 +136,13 @@ module.exports = function runTests(agent, pg, name) {
t.ok(setSegment, 'trace segment for insert should exist')
t.ok(getSegment, 'trace segment for select should exist')

t.equals(setSegment.parameters.instance, hostId, 'should add the instance parameter')
t.equals(
setSegment.parameters.database_name,
params.postgres_db,
'should add the database name parameter'
)
// XXX: Uncomment once metric names have been decided on
// t.equals(setSegment.parameters.instance, hostId, 'should add the instance parameter')
// t.equals(
// setSegment.parameters.database_name,
// params.postgres_db,
// 'should add the database name parameter'
// )

if (!getSegment) return t.end()

Expand Down
37 changes: 20 additions & 17 deletions test/versioned/pg-2/pg.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,25 @@ module.exports = function runTests(agent, pg, name) {
expected['Datastore/statement/Postgres/' + selectTable + '/select'] = 1

var hostId = METRIC_HOST_NAME + ':{' + params.postgres_port + '}'
expected['Datastore/instance/Postgres/' + hostId] = 2
// this should be uncommented out when instance metrics are sent up
// expected['Datastore/instance/Postgres/' + hostId] = 2

var slowQuerySamples = agent.queries.samples
for (var key in slowQuerySamples) {
var queryParams = slowQuerySamples[key].getParams()

t.equal(
queryParams.instance,
hostId,
'instance data should show up in slow query params'
)
// XXX: Uncomment once metric names have been decided on
// t.equal(
// queryParams.instance,
// hostId,
// 'instance data should show up in slow query params'
// )

t.equal(
queryParams.database_name,
params.postgres_db,
'database name should show up in slow query params'
)
// t.equal(
// queryParams.database_name,
// params.postgres_db,
// 'database name should show up in slow query params'
// )

t.ok(queryParams.backtrace, 'params should contain a backtrace')
}
Expand Down Expand Up @@ -134,12 +136,13 @@ module.exports = function runTests(agent, pg, name) {
t.ok(setSegment, 'trace segment for insert should exist')
t.ok(getSegment, 'trace segment for select should exist')

t.equals(setSegment.parameters.instance, hostId, 'should add the instance parameter')
t.equals(
setSegment.parameters.database_name,
params.postgres_db,
'should add the database name parameter'
)
// XXX: Uncomment once metric names have been decided on
// t.equals(setSegment.parameters.instance, hostId, 'should add the instance parameter')
// t.equals(
// setSegment.parameters.database_name,
// params.postgres_db,
// 'should add the database name parameter'
// )

if (!getSegment) return t.end()

Expand Down
37 changes: 20 additions & 17 deletions test/versioned/pg-3/pg.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,25 @@ module.exports = function runTests(agent, pg, name) {
expected['Datastore/statement/Postgres/' + selectTable + '/select'] = 1

var hostId = METRIC_HOST_NAME + ':{' + params.postgres_port + '}'
expected['Datastore/instance/Postgres/' + hostId] = 2
// this should be uncommented out when instance metrics are sent up
// expected['Datastore/instance/Postgres/' + hostId] = 2

var slowQuerySamples = agent.queries.samples
for (var key in slowQuerySamples) {
var queryParams = slowQuerySamples[key].getParams()

t.equal(
queryParams.instance,
hostId,
'instance data should show up in slow query params'
)
// XXX: Uncomment once metric names have been decided on
// t.equal(
// queryParams.instance,
// hostId,
// 'instance data should show up in slow query params'
// )

t.equal(
queryParams.database_name,
params.postgres_db,
'database name should show up in slow query params'
)
// t.equal(
// queryParams.database_name,
// params.postgres_db,
// 'database name should show up in slow query params'
// )

t.ok(queryParams.backtrace, 'params should contain a backtrace')
}
Expand Down Expand Up @@ -134,12 +136,13 @@ module.exports = function runTests(agent, pg, name) {
t.ok(setSegment, 'trace segment for insert should exist')
t.ok(getSegment, 'trace segment for select should exist')

t.equals(setSegment.parameters.instance, hostId, 'should add the instance parameter')
t.equals(
setSegment.parameters.database_name,
params.postgres_db,
'should add the database name parameter'
)
// XXX: Uncomment once metric names have been decided on
// t.equals(setSegment.parameters.instance, hostId, 'should add the instance parameter')
// t.equals(
// setSegment.parameters.database_name,
// params.postgres_db,
// 'should add the database name parameter'
// )

if (!getSegment) return t.end()

Expand Down
37 changes: 20 additions & 17 deletions test/versioned/pg-4/pg.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,25 @@ module.exports = function runTests(agent, pg, name) {
expected['Datastore/statement/Postgres/' + selectTable + '/select'] = 1

var hostId = METRIC_HOST_NAME + ':{' + params.postgres_port + '}'
expected['Datastore/instance/Postgres/' + hostId] = 2
// this should be uncommented out when instance metrics are sent up
// expected['Datastore/instance/Postgres/' + hostId] = 2

var slowQuerySamples = agent.queries.samples
for (var key in slowQuerySamples) {
var queryParams = slowQuerySamples[key].getParams()

t.equal(
queryParams.instance,
hostId,
'instance data should show up in slow query params'
)
// XXX: Uncomment once metric names have been decided on
// t.equal(
// queryParams.instance,
// hostId,
// 'instance data should show up in slow query params'
// )

t.equal(
queryParams.database_name,
params.postgres_db,
'database name should show up in slow query params'
)
// t.equal(
// queryParams.database_name,
// params.postgres_db,
// 'database name should show up in slow query params'
// )

t.ok(queryParams.backtrace, 'params should contain a backtrace')
}
Expand Down Expand Up @@ -134,12 +136,13 @@ module.exports = function runTests(agent, pg, name) {
t.ok(setSegment, 'trace segment for insert should exist')
t.ok(getSegment, 'trace segment for select should exist')

t.equals(setSegment.parameters.instance, hostId, 'should add the instance parameter')
t.equals(
setSegment.parameters.database_name,
params.postgres_db,
'should add the database name parameter'
)
// XXX: Uncomment once metric names have been decided on
// t.equals(setSegment.parameters.instance, hostId, 'should add the instance parameter')
// t.equals(
// setSegment.parameters.database_name,
// params.postgres_db,
// 'should add the database name parameter'
// )

if (!getSegment) return t.end()

Expand Down

0 comments on commit b931360

Please sign in to comment.