Skip to content

Commit e659ea1

Browse files
committed
cleanup modules
1 parent ab4ee15 commit e659ea1

File tree

14 files changed

+75
-126
lines changed

14 files changed

+75
-126
lines changed

app.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ if (process.env.NEW_RELIC_LICENSE_KEY) {
99
require('newrelic')
1010
}
1111

12-
var cluster = require('cluster')
13-
var createCount = require('callback-count')
14-
15-
var ApiServer = require('server')
16-
var dogstatsd = require('models/datadog')
17-
var envIs = require('101/env-is')
18-
var error = require('error')
19-
var keyGen = require('key-generator')
20-
var logger = require('middlewares/logger')(__filename)
21-
var mongooseControl = require('models/mongo/mongoose-control')
22-
var noop = require('101/noop')
23-
var redisClient = require('models/redis')
24-
var redisPubSub = require('models/redis/pubsub')
25-
26-
var log = logger.log
12+
const cluster = require('cluster')
13+
const createCount = require('callback-count')
14+
15+
const ApiServer = require('server')
16+
const envIs = require('101/env-is')
17+
const error = require('error')
18+
const keyGen = require('key-generator')
19+
const logger = require('middlewares/logger')(__filename)
20+
const mongooseControl = require('models/mongo/mongoose-control')
21+
const monitor = require('monitor-dog')
22+
const noop = require('101/noop')
23+
const redisClient = require('models/redis')
24+
const redisPubSub = require('models/redis/pubsub')
25+
26+
const log = logger.log
2727

2828
// express server, handles web HTTP requests
29-
var apiServer = new ApiServer()
29+
const apiServer = new ApiServer()
3030

3131
/**
3232
* @class
@@ -52,7 +52,7 @@ Api.prototype.start = function (cb) {
5252
// start github ssh key generator
5353
keyGen.start(count.inc().next)
5454
// start sending socket count
55-
dogstatsd.monitorStart()
55+
monitor.startSocketsMonitor()
5656
// connect to mongoose
5757
mongooseControl.start(count.inc().next)
5858
// express server start
@@ -91,7 +91,7 @@ Api.prototype.stop = function (cb) {
9191
// stop github ssh key generator
9292
keyGen.stop(count.inc().next)
9393
// stop sending socket count
94-
dogstatsd.monitorStop()
94+
monitor.stopSocketsMonitor()
9595
// express server
9696
apiServer.stop(count.inc().next)
9797

lib/express-app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var morganFreeman = require('morgan')
1111

1212
var Timer = require('models/apis/timers')
1313
var csrf = require('middlewares/csrf')
14-
var dogstatsd = require('models/datadog')
14+
var dogstatsd = require('monitor-dog')
1515
var error = require('error')
1616
var passport = require('middlewares/passport')
1717
var pkg = require('../package.json')

lib/hasher.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
'use strict'
88

99
var crypto = require('crypto')
10-
var dogstatsd = require('models/datadog')
10+
var monitorDog = require('monitor-dog')
1111
var exists = require('101/exists')
1212
var isFunction = require('101/is-function')
1313
var strim = require('strim')
@@ -18,7 +18,7 @@ var strim = require('strim')
1818
* @param {Function} cb callback
1919
*/
2020
module.exports = function hasher (data, dontReplaceWhitespace, cb) {
21-
var start = new Date()
21+
const timer = monitorDog.timer('infraCodeVersion.hashTime', true, ['length:' + data.length])
2222
if (isFunction(dontReplaceWhitespace)) {
2323
cb = dontReplaceWhitespace
2424
dontReplaceWhitespace = false
@@ -60,7 +60,7 @@ module.exports = function hasher (data, dontReplaceWhitespace, cb) {
6060
function done (err, hash) {
6161
if (calledBack) { return }
6262
calledBack = true
63-
dogstatsd.timing('api.infraCodeVersion.hashTime', new Date() - start, 1, ['length:' + data.length])
63+
timer.stop()
6464
cb(err, hash)
6565
}
6666
}

lib/key-generator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require('loadenv')()
88
var async = require('async')
99

1010
var Keypair = require('models/mongo/keypair')
11-
var dogstatsd = require('models/datadog')
11+
var monitorDog = require('monitor-dog')
1212
var logger = require('middlewares/logger')(__filename)
1313
var noop = require('101/noop')
1414
var bindAll = require('101/bind-all')
@@ -89,7 +89,7 @@ KeyGen.prototype._handleInterval = function () {
8989
log.error({err: err}, 'error getting the keypair count')
9090
return handleComplete(err)
9191
}
92-
dogstatsd.gauge('api.keypairs.count', count)
92+
monitorDog.gauge('keypairs.count', count)
9393
var numKeysToCreate = self.poolSize - count
9494
var tasks = []
9595
for (var i = 0; i < numKeysToCreate; i++) {

lib/models/apis/container-fs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var pathModule = require('path')
44
var request = require('request')
55
var url = require('url')
66
var Boom = require('dat-middleware').Boom
7-
var dogstatsd = require('models/datadog')
7+
var monitorDog = require('monitor-dog')
88

99
function formatURL (container, path) {
1010
var parsedHost = url.parse(container.host)
@@ -54,7 +54,7 @@ function logTime (err, res, method, call, start) {
5454
statusCode = res.statusCode
5555
}
5656

57-
dogstatsd.timing('api.krain.request',
57+
monitorDog.histogram('krain.request',
5858
new Date() - start,
5959
['statusCode:' + statusCode,
6060
'didErr:' + (err ? 'true' : 'false'),

lib/models/apis/timers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
var isFunction = require('101/is-function')
77

8-
var dogstatsd = require('models/datadog')
8+
var monitorDog = require('monitor-dog')
99
var logger = require('middlewares/logger')(__filename)
1010

1111
var log = logger.log
@@ -26,7 +26,7 @@ Timers.prototype.debug = function (name, message) {
2626
Timers.prototype.sendToDatadog = function (name, timer, tags) {
2727
var ms = (timer[0] * 1000) + (timer[1] / 1000000)
2828
// ms = seconds * 1000 + nanoseconds / 1000000
29-
dogstatsd.timing('api.timers.' + name, ms, tags)
29+
monitorDog.histogram('timers.' + name, ms, tags)
3030
}
3131

3232
Timers.prototype.startTimer = function (name, cb) {

lib/models/datadog/index.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

lib/models/mongo/context-version.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const pick = require('101/pick')
2121
const Promise = require('bluebird')
2222
const util = require('util')
2323

24-
const dogstatsd = require('models/datadog')
24+
const monitorDog = require('monitor-dog')
2525
const error = require('error')
2626
const Github = require('models/apis/github')
2727
const InfraCodeVersion = require('models/mongo/infra-code-version')
@@ -1155,11 +1155,11 @@ ContextVersionSchema.methods.dedupeBuild = function (callback) {
11551155
log.trace('dedupeBuild: replaceIfDupe')
11561156
if (dupe) { // dupe found
11571157
log.trace('dedupeBuild: replaceIfDupe dupe found')
1158-
dogstatsd.increment('api.contextVersion.build.deduped')
1158+
monitorDog.increment('contextVersion.build.deduped')
11591159
self.copyBuildFromContextVersion(dupe, cb)
11601160
} else {
11611161
log.trace('dedupeBuild: replaceIfDupe no dupe')
1162-
dogstatsd.increment('api.contextVersion.build.noDupe')
1162+
monitorDog.increment('contextVersion.build.noDupe')
11631163
cb(null, self)
11641164
}
11651165
}

lib/routes/actions/analyze/index.js

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var isObject = require('101/is-object')
1313
var keypath = require('keypather')()
1414
var mw = require('dat-middleware')
1515

16-
var dogstatsd = require('models/datadog')
16+
var monitorDog = require('monitor-dog')
1717
var GitHub = require('models/apis/github')
1818
var logger = require('logger')
1919
var stacks = require('routes/actions/analyze/data/stacks')
@@ -160,7 +160,10 @@ function extractJS (req, res, next) {
160160
languageFramework: req.languageFramework
161161
})
162162
log.info('extractJS called')
163-
var start = new Date()
163+
const timer = monitorDog.timitimerng('actions-analyze-index.extractJS', true, [
164+
'dependencyFile:' + req.dependencyFile.name,
165+
'languageFramework:' + req.languageFramework
166+
])
164167
var depFile
165168
try {
166169
depFile = JSON.parse(req.dependencyFileContent)
@@ -179,10 +182,7 @@ function extractJS (req, res, next) {
179182
nodejs: nodev,
180183
npm: npmv
181184
}
182-
dogstatsd.timing('api.actions-analyze-index.extractJS', new Date() - start, 1, [
183-
'dependencyFile:' + req.dependencyFile.name,
184-
'languageFramework:' + req.languageFramework
185-
])
185+
timer.stop()
186186
next()
187187
}
188188

@@ -196,7 +196,11 @@ function extractRuby (req, res, next) {
196196
logger.trace({
197197
languageFramework: req.languageFramework
198198
}, 'extractRuby')
199-
var start = new Date()
199+
const timer = monitorDog.timer('actions-analyze-index.extractRuby', true, [
200+
'dependencyFile:' + req.dependencyFile.name,
201+
'languageFramework:' + req.languageFramework,
202+
'dependencies.length:' + dependencies.length
203+
])
200204
var dependencies = []
201205
var gemfileDependenciesRegexPattern = /^(\s+)?gem\s+['"](\S+)['"]/gm
202206
var execResult = gemfileDependenciesRegexPattern.exec(req.dependencyFileContent)
@@ -209,11 +213,7 @@ function extractRuby (req, res, next) {
209213
ruby: req.supportedLanguageVersions.defaultVersion,
210214
rails: stacks.rails.defaultVersion
211215
}
212-
dogstatsd.timing('api.actions-analyze-index.extractRuby', new Date() - start, 1, [
213-
'dependencyFile:' + req.dependencyFile.name,
214-
'languageFramework:' + req.languageFramework,
215-
'dependencies.length:' + dependencies.length
216-
])
216+
timer.stop()
217217
next()
218218
}
219219

@@ -227,7 +227,11 @@ function extractPython (req, res, next) {
227227
logger.trace({
228228
languageFramework: req.languageFramework
229229
}, 'extractPython')
230-
var start = new Date()
230+
const timer = monitorDog.timer('actions-analyze-index.extractPython', true, [
231+
'dependencyFile:' + req.dependencyFile.name,
232+
'languageFramework:' + req.languageFramework,
233+
'dependencies.length:' + dependencies.length
234+
])
231235
var dependencies = []
232236
var pythonDependenciesRegexPattern
233237
var execResult
@@ -253,11 +257,7 @@ function extractPython (req, res, next) {
253257
req.inferredLanguageVersion = {
254258
python: req.supportedLanguageVersions.defaultVersion
255259
}
256-
dogstatsd.timing('api.actions-analyze-index.extractPython', new Date() - start, 1, [
257-
'dependencyFile:' + req.dependencyFile.name,
258-
'languageFramework:' + req.languageFramework,
259-
'dependencies.length:' + dependencies.length
260-
])
260+
timer.stop()
261261
next()
262262
}
263263

@@ -273,7 +273,10 @@ function extractPHP (req, res, next) {
273273
method: 'extractPHP'
274274
})
275275
log.info('extractPHP')
276-
var start = new Date()
276+
const timer = monitorDog.timer('actions-analyze-index.extractPHP', true, [
277+
'dependencyFile:' + req.dependencyFile.name,
278+
'languageFramework:' + req.languageFramework
279+
])
277280
var depFile
278281
try {
279282
depFile = JSON.parse(req.dependencyFileContent)
@@ -287,10 +290,7 @@ function extractPHP (req, res, next) {
287290
req.inferredLanguageVersion = {
288291
php: req.supportedLanguageVersions.defaultVersion
289292
}
290-
dogstatsd.timing('api.actions-analyze-index.extractPHP', new Date() - start, 1, [
291-
'dependencyFile:' + req.dependencyFile.name,
292-
'languageFramework:' + req.languageFramework
293-
])
293+
timer.stop()
294294
next()
295295
}
296296

@@ -326,7 +326,7 @@ function inferDependenciesFromDependencyList (req, res, next) {
326326
suggestableServices = suggestableServicesPHP
327327
break
328328
}
329-
var start = new Date()
329+
const timer = monitorDog.timer('actions-analyze-index.inferDependenciesFromDependencyList', true, [])
330330
var inferredServices = suggestableServicesKeys.filter(function (key) {
331331
return find(suggestableServices[key], function (moduleThatMatchesSuggestableService) {
332332
return find(req.dependencyList, function (dependencyInProject) {
@@ -335,8 +335,7 @@ function inferDependenciesFromDependencyList (req, res, next) {
335335
})
336336
})
337337
})
338-
dogstatsd.timing('api.actions-analyze-index.inferDependenciesFromDependencyList',
339-
new Date() - start, 1, [])
338+
timer.stop()
340339
req.inferredDependencies = inferredServices
341340
next()
342341
}

lib/socket/messenger.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const keypather = require('keypather')()
99
const Promise = require('bluebird')
1010
const uuid = require('uuid')
1111

12-
const dogstatsd = require('models/datadog')
12+
const monitorDog = require('monitor-dog')
1313
const error = require('dat-middleware').Boom
1414
const errorModule = require('error')
1515
const GitHub = require('models/apis/github')
@@ -19,7 +19,7 @@ const User = require('models/mongo/user')
1919

2020
module.exports = new Messenger()
2121

22-
const baseDataName = 'api.socket.messenger'
22+
const baseDataName = 'socket.messenger'
2323
function Messenger () {}
2424

2525
Messenger.prototype.setServer = function (server) {
@@ -267,11 +267,11 @@ Messenger.prototype.canJoin = function (socket, data, cb) {
267267
* @returns Promise with either a success, or a rejection if something fails
268268
*/
269269
Messenger.prototype.subscribeStreamHandler = function (socket, id, data) {
270-
dogstatsd.increment(baseDataName + '.connections')
270+
monitorDog.increment(baseDataName + '.connections')
271271
// check required args
272272
return Promise.try(function () {
273273
if (!data.name || !data.type || !data.action) {
274-
dogstatsd.increment(baseDataName + '.err.invalid_args')
274+
monitorDog.increment(baseDataName + '.err.invalid_args')
275275
const notFound = error.create(400, 'name, type and action are required', data)
276276
keypather.set(notFound, 'data.level', 'warning')
277277
throw notFound

0 commit comments

Comments
 (0)