Skip to content

Commit

Permalink
update dependencies, standard code format, remove deprecated modules
Browse files Browse the repository at this point in the history
  • Loading branch information
megastef committed Nov 5, 2019
1 parent e4f6393 commit daf61a9
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 30 deletions.
2 changes: 1 addition & 1 deletion example/simple-server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var spmAgent = require('../lib/index.js') // or 'spm-agent-nodejs'
var spmAgent = require('../lib/index.js') // or 'spm-agent-nodejs'
spmAgent.on('stats', function (stats) {
console.log(stats)
})
Expand Down
2 changes: 1 addition & 1 deletion lib/eventLoopStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ EventLoopStats.prototype.start = function () {
}
return prev
}, {})
var stats = {count: 0, time: 0, avg: 0, min: 1e12, max: 0}
var stats = { count: 0, time: 0, avg: 0, min: 1e12, max: 0 }
for (var key in timesInMicroSecs) {
stats.time += parseInt(key, 10) * timesInMicroSecs[key]
stats.count += timesInMicroSecs[key]
Expand Down
8 changes: 4 additions & 4 deletions lib/gcAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ function getGcStats () {
gcTimes.toJSON().sum || 0,
heapCompactionsJSON || 0,
heapDiff.toJSON().sum || 0,
heapInfo['processHeapUsed'] || 0,
heapInfo['processHeapTotal'] || 0,
heapInfo['processMemoryRss'] || 0
heapInfo.processHeapUsed || 0,
heapInfo.processHeapTotal || 0,
heapInfo.processMemoryRss || 0
]
agent.addMetrics({ts: now, name: 'gc', value: metricValues})
agent.addMetrics({ ts: now, name: 'gc', value: metricValues })
fullGc.reset(0)
incGc.reset(0)
heapCompactions.reset(0)
Expand Down
21 changes: 3 additions & 18 deletions lib/httpServerAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
var http = require('http')
var https = require('https')
var cluster = require('cluster')
var domain = require('domain')

// constants
var FINISH_EVENT_NAME = 'finish'
Expand Down Expand Up @@ -58,8 +57,8 @@ module.exports = function httpServerAgent () {
var responseTimes = histogram.toJSON()
var now = Date.now()
var metricValue = [
httpStats['requests'] ? httpStats['requests'].count : 0, // http.requestCount (int)
httpStats['errRate'] ? httpStats['errRate'].count : 0, // http.errorCount (int)
httpStats.requests ? httpStats.requests.count : 0, // http.requestCount (int)
httpStats.errRate ? httpStats.errRate.count : 0, // http.errorCount (int)
httpStats['3xxRate'] ? httpStats['3xxRate'].count : 0, // http.3xx (int)
httpStats['4xxRate'] ? httpStats['4xxRate'].count : 0, // http.4xx (int)
httpStats['5xxRate'] ? httpStats['5xxRate'].count : 0, // http.5xx (int)
Expand Down Expand Up @@ -104,20 +103,6 @@ module.exports = function httpServerAgent () {
return hAgent
}

/**
* Utils
*/
function cleanDomainNamespace () {
// remove current req/res from bound domains if it is bound
var currentDomain = domain.active
if (!currentDomain) return

// we can also remove .members, but still need some investigation
while (currentDomain === domain.active) {
currentDomain.exit()
}
}

/**
* Make sure we deoptimize small part of fn
*/
Expand Down Expand Up @@ -178,7 +163,7 @@ function monitorHttp (ctx, req, res) {
res.removeListener(ABRUPT_CLOSE_EVENT_NAME, endOfConnectionHandler)

// this is invoked to cleanup domains from possible timers bound to it
cleanDomainNamespace()
// cleanDomainNamespace()
}

res.on(FINISH_EVENT_NAME, endOfConnectionHandler)
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
"zip-zip-top": "^0.2.0"
},
"optionalDependencies": {
"gc-stats": "1.2.1"
"gc-stats": "^1.4.0"
},
"devDependencies": {
"mocha": "^5.2.0",
"standard": "^9.0.1"
"mocha": "^6.2.2",
"standard": "^14.3.1"
}
}
6 changes: 3 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Please see the full license (found in LICENSE in this distribution) for details on its license and the licenses of its dependencies.
*/
/* global describe, it */
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
var config = require('spm-agent').Config
var port = (process.env.NJS_TEST_PORT || 8095)
var receiverUrl = 'http://127.0.0.1:' + port
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('SPM for Node.js tests', function () {
njsAgent.start()
var http = require('http')
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'})
res.writeHead(200, { 'Content-Type': 'text/plain' })
res.end('{"code":"200"}\n')
}).listen(port, '127.0.0.1')
httpTest(njsAgent, done)
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('SPM for Node.js tests', function () {
config.logger.console = false
config.logger.level = 'debug'
var NjsAgent = require('../lib/index.js')
var metricTypes = {gc: 0, eventloop: 0, numWorkers: 0}
var metricTypes = { gc: 0, eventloop: 0, numWorkers: 0 }

function checkMetrics (metric) {
metricTypes[metric.name] = 1
Expand Down

0 comments on commit daf61a9

Please sign in to comment.