Skip to content

Commit

Permalink
feat(event-paths): add path based event reporting with CollectorTrans…
Browse files Browse the repository at this point in the history
…actionRaw 1.1.0 support
  • Loading branch information
dszakallas committed May 3, 2017
1 parent ef06893 commit a1cbeb4
Show file tree
Hide file tree
Showing 124 changed files with 1,998 additions and 1,511 deletions.
23 changes: 20 additions & 3 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
parserOptions:
ecmaVersion: 5
sourceType: script
env:
node: true
mocha: true
extends: standard
rules:
no-unused-expressions: off
node/no-deprecated-api: off
standard/no-callback-literal: off
no-unused-expressions:
- off
node/no-deprecated-api:
- off
standard/no-callback-literal:
- off
strict:
- error
- safe
consistent-this:
- error
- self
no-multiple-empty-lines:
- error
- max: 1
maxEOF: 0
maxBOF: 0
2 changes: 1 addition & 1 deletion example/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// index.js
'use strict'
var trace = require('@risingstack/trace')

var app = require('express')()
Expand Down
29 changes: 15 additions & 14 deletions example/config/trace.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/**
* Your Trace configuration file
*/
'use strict'

module.exports = {
serviceName: 'your-awesome-app',
apiKey: 'KEEP.ME.SECRET',
ignoreHeaders: {
'user-agent': ['007']
},
ignorePaths: [
'/healtcheck'
],
ignoreStatusCodes: [
401,
403
]
}
module.exports = {
serviceName: 'your-awesome-app',
apiKey: 'KEEP.ME.SECRET',
ignoreHeaders: {
'user-agent': ['007']
},
ignorePaths: [
'/healtcheck'
],
ignoreStatusCodes: [
401,
403
]
}
3 changes: 2 additions & 1 deletion lib/agent/agent.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
var Timer = require('./timer')

function Agent (name, interval, task) {
Expand Down Expand Up @@ -27,6 +28,6 @@ Agent.prototype.stop = function (callback) {

Agent.prototype.initialize = function () { }

Agent.prototype.destruct = function () { this.stop() }
Agent.prototype.destruct = function (callback) { this.stop(callback) }

module.exports = Agent
File renamed without changes.
1 change: 1 addition & 0 deletions lib/agent/api/bufferStream.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
var stream = require('stream')
var util = require('util')

Expand Down
31 changes: 16 additions & 15 deletions lib/agent/api/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
var https = require('https')
var url = require('url')
var util = require('util')
Expand Down Expand Up @@ -246,27 +247,27 @@ CollectorApi.prototype.sendDependencies = function (dependencies) {

CollectorApi.prototype.getService = function (cb) {
var opts = url.parse(this.COLLECTOR_API_SERVICE)
var _this = this
var self = this
cb = cb || function () {}

var payload = JSON.stringify({
name: _this.serviceName,
name: self.serviceName,
version: '2',
collector: {
language: _this.collectorLanguage,
language: self.collectorLanguage,
version: libPackage.version
},
runtime: {
name: _this.system.processName,
version: _this.system.processVersion,
pid: _this.system.processId
name: self.system.processName,
version: self.system.processVersion,
pid: self.system.processId
},
machine: {
arch: _this.system.osArch,
platform: _this.system.osPlatform,
release: _this.system.osRelease,
hostname: _this.system.hostname,
cpus: _this.system.cpus
arch: self.system.osArch,
platform: self.system.osPlatform,
release: self.system.osRelease,
hostname: self.system.hostname,
cpus: self.system.cpus
}
})
var req = https.request({
Expand All @@ -287,13 +288,13 @@ CollectorApi.prototype.getService = function (cb) {
res.pipe(bl(function (err, resBuffer) {
var response

var retryInterval = _this.baseRetryInterval
var retryInterval = self.baseRetryInterval

if (err) {
debug.error('getService', err)
return setTimeout(function () {
debug.warn('getService', format('Retrying with %d ms', retryInterval))
_this.getService()
self.getService()
}, retryInterval)
}

Expand All @@ -307,7 +308,7 @@ CollectorApi.prototype.getService = function (cb) {
debug.error('getService', 'Service responded with ' + res.statusCode)
return setTimeout(function () {
debug.warn('getService', format('Retrying with %d ms', retryInterval))
_this.getService(cb)
self.getService(cb)
}, retryInterval)
}

Expand All @@ -317,7 +318,7 @@ CollectorApi.prototype.getService = function (cb) {
return
}

_this.serviceKey = response.key
self.serviceKey = response.key
cb(null, response.key)
}))
})
Expand Down
5 changes: 3 additions & 2 deletions lib/agent/api/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict'
var util = require('util')
var url = require('url')
var https = require('https')
var FakeReadable = require('../util').FakeStream.FakeReadable
var FakeWritable = require('../util').FakeStream.FakeWritable
var FakeReadable = require('./FakeStream.mock').FakeReadable
var FakeWritable = require('./FakeStream.mock').FakeWritable
var CollectorApi = require('./')

var expect = require('chai').expect
Expand Down
9 changes: 5 additions & 4 deletions lib/agent/control/control.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
var debug = require('../../utils/debug')('agent:control')

var inherits = require('util').inherits
Expand All @@ -19,19 +20,19 @@ function Control (options) {
inherits(Control, Agent)

Control.prototype.getUpdates = function () {
var _this = this
var self = this
this.collectorApi.getUpdates({
latestCommandId: _this.latestCommandId
latestCommandId: self.latestCommandId
}, function (err, result) {
if (err) {
return debug.error('getUpdates', err)
}

_this.latestCommandId = result.latestCommandId
self.latestCommandId = result.latestCommandId

result.commands = result.commands || []
result.commands.forEach(function (command) {
_this.controlBus.emit(command.command, command)
self.controlBus.emit(command.command, command)
})
})
}
Expand Down
1 change: 1 addition & 0 deletions lib/agent/control/control.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
var expect = require('chai').expect

var Control = require('./')
Expand Down
1 change: 1 addition & 0 deletions lib/agent/control/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
'use strict'
module.exports = require('./control')
1 change: 1 addition & 0 deletions lib/agent/healthcheck/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
var inherits = require('util').inherits
var Agent = require('../agent')

Expand Down
1 change: 1 addition & 0 deletions lib/agent/healthcheck/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
var expect = require('chai').expect

var Healthcheck = require('./')
Expand Down
1 change: 1 addition & 0 deletions lib/agent/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
var EventEmitter = require('events').EventEmitter

var debug = require('../utils/debug')('agent')
Expand Down
13 changes: 7 additions & 6 deletions lib/agent/metrics/apm/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
var os = require('os')
var gc = require('../../../optionalDependencies/@risingstack/gc-stats')()
var eventLoopStats = require('../../../optionalDependencies/@risingstack/event-loop-stats')
Expand All @@ -8,7 +9,7 @@ var BYTES_TO_MEGABYTES = 1024 * 1024
var NANO_TO_MILLI = 1000 * 1000

function ApmMetrics (options) {
var _this = this
var self = this
this.cpuCount = os.cpus().length
this.pid = process.pid
this.collectorApi = options.collectorApi
Expand All @@ -24,18 +25,18 @@ function ApmMetrics (options) {

gc.on('stats', function (stats) {
// time is in nanoseconds
_this.gc.time += stats.pause
self.gc.time += stats.pause

switch (stats.gctype) {
case 1:
_this.gc.scavenge += 1
self.gc.scavenge += 1
break
case 2:
_this.gc.marksweep += 1
self.gc.marksweep += 1
break
case 3:
_this.gc.scavenge += 1
_this.gc.marksweep += 1
self.gc.scavenge += 1
self.gc.marksweep += 1
break
}
})
Expand Down
1 change: 1 addition & 0 deletions lib/agent/metrics/apm/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
var expect = require('chai').expect
var os = require('os')
var eventLoopStats = require('@risingstack/event-loop-stats')
Expand Down
1 change: 1 addition & 0 deletions lib/agent/metrics/custom/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
var inherits = require('util').inherits
var Agent = require('../../agent')
var reservoirSampler = require('../../util/samplers/reservoir')
Expand Down
1 change: 1 addition & 0 deletions lib/agent/metrics/custom/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
var expect = require('chai').expect

var CustomMetrics = require('./')
Expand Down
9 changes: 5 additions & 4 deletions lib/agent/metrics/externalEdge/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
var debug = require('../../../utils/debug')('agent:metrics:externalEdge')
var flatMap = require('lodash.flatmap')

Expand Down Expand Up @@ -71,19 +72,19 @@ ExternalEdgeMetrics.prototype.calculateTimes = function (items) {
}

ExternalEdgeMetrics.prototype.sendMetrics = function (callback) {
var _this = this
var self = this
callback = callback || function () {}

var metrics = flatMap(Object.keys(this.metrics), function (protocol) {
return Object.keys(_this.metrics[protocol]).map(function (hostName) {
var host = _this.metrics[protocol][hostName]
return Object.keys(self.metrics[protocol]).map(function (hostName) {
var host = self.metrics[protocol][hostName]
return {
protocol: protocol,
target: {
id: hostName
},
metrics: {
responseTime: _this.calculateTimes(host.responseTime),
responseTime: self.calculateTimes(host.responseTime),
status: {
ok: host.status.ok,
notOk: host.status.notOk
Expand Down
1 change: 1 addition & 0 deletions lib/agent/metrics/externalEdge/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
var expect = require('chai').expect

var ExternalEdgeMetrics = require('./')
Expand Down
9 changes: 5 additions & 4 deletions lib/agent/metrics/incomingEdge/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
var flatMap = require('lodash.flatmap')
var inherits = require('util').inherits
var Agent = require('../../agent')
Expand Down Expand Up @@ -60,12 +61,12 @@ IncomingEdgeMetrics.prototype._calculateTimes = function (items) {
}

IncomingEdgeMetrics.prototype.sendMetrics = function (callback) {
var _this = this
var self = this
callback = callback || function () {}

var metrics = flatMap(Object.keys(this.metrics), function (protocol) {
return Object.keys(_this.metrics[protocol]).map(function (serviceKey) {
var items = _this.metrics[protocol][serviceKey]
return Object.keys(self.metrics[protocol]).map(function (serviceKey) {
var items = self.metrics[protocol][serviceKey]
if (serviceKey === 'root') {
return {
protocol: protocol,
Expand All @@ -78,7 +79,7 @@ IncomingEdgeMetrics.prototype.sendMetrics = function (callback) {
protocol: protocol,
serviceKey: serviceKey,
metrics: {
transportDelay: _this._calculateTimes(items.transportDelay),
transportDelay: self._calculateTimes(items.transportDelay),
count: items.count
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/agent/metrics/incomingEdge/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
var expect = require('chai').expect

var EdgeMetrics = require('./')
Expand Down
1 change: 1 addition & 0 deletions lib/agent/metrics/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
module.exports.apm = require('./apm')
module.exports.rpm = require('./rpm')
module.exports.incomingEdge = require('./incomingEdge')
Expand Down
1 change: 1 addition & 0 deletions lib/agent/metrics/rpm/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
var inherits = require('util').inherits
var Agent = require('../../agent')

Expand Down
1 change: 1 addition & 0 deletions lib/agent/metrics/rpm/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'
var expect = require('chai').expect

var RpmMetrics = require('./')
Expand Down

0 comments on commit a1cbeb4

Please sign in to comment.