cerebro-cli
Advanced tools
Comparing version 0.3.0 to 0.3.1
{ | ||
"name": "cerebro-cli", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "", | ||
"bin": { | ||
"cerebro-cli": "./src/index.js" | ||
}, | ||
"main": "./src/index.js", | ||
@@ -22,5 +25,7 @@ "scripts": { | ||
"@octokit/rest": "^18.5.6", | ||
"prom-client": "^13.1.0" | ||
"prom-client": "^13.1.0", | ||
"ws": "^7.4.6" | ||
}, | ||
"devDependencies": { | ||
"live-server": "^1.2.1", | ||
"markdownlint": "^0.23.1", | ||
@@ -31,5 +36,4 @@ "markdownlint-cli": "^0.27.1", | ||
"nyc": "^15.1.0", | ||
"standard": "^16.0.3", | ||
"ws": "^7.4.6" | ||
"standard": "^16.0.3" | ||
} | ||
} |
@@ -0,1 +1,3 @@ | ||
#!/usr/bin/env node | ||
const metrics = require('./metrics') | ||
@@ -11,2 +13,4 @@ const { | ||
const seeker = require('./seeker') | ||
const ui = require('live-server') | ||
const websocket = require('./output/websocket') | ||
@@ -37,18 +41,31 @@ // Initialization | ||
seeker.events.on('miss-included-langs', count => missIncludedLangs.inc(count)) | ||
seeker.events.on('miss-non-hireable', count => missNonHireable.inc(count)) | ||
seeker.events.on('metrics', async (metrics) => { | ||
uniqueEvents.set(metrics.uniqueEvents) | ||
pullRequests.set(metrics.prEvents) | ||
suitablePRs.set(metrics.suitablePRs) | ||
missIncludedLangs.set(metrics.missIncludedLangs) | ||
missNonHireable.set(metrics.missNonHireable) | ||
// TODO: Fix lang labels | ||
candidatesFound.set(metrics.candidatesFound) | ||
seeker.events.on('stats-unique-events', count => uniqueEvents.inc(count)) | ||
seeker.events.on('stats-pull-requests', count => pullRequests.inc(count)) | ||
seeker.events.on('stats-suitable-prs', count => suitablePRs.inc(count)) | ||
websocket.broadcast({ metrics }) | ||
}) | ||
function outputCandidate (candidate) { | ||
console.log(candidate) | ||
candidatesFound.labels({ lang: candidate.includedLangs[0] }).inc(1) | ||
} | ||
seeker.events.on('candidate-found', outputCandidate) | ||
seeker.events.on('candidate-found', (candidate) => { | ||
websocket.broadcast({ candidate }) | ||
}) | ||
// Start Prometheus metrics server on the specified port | ||
metrics.start({ port: 9100 }) | ||
// Start Prometheus metrics server on the default port 8080 | ||
websocket.start() | ||
// Start Prometheus metrics server on the default port 9100 | ||
metrics.start() | ||
// Start examples UI for now | ||
ui.start({ | ||
port: 3000, | ||
root: './examples', | ||
open: false | ||
}) | ||
// Exit cleanly on SIGINT | ||
@@ -63,3 +80,6 @@ // TODO: Maybe emit stats? | ||
seeker.stop() | ||
console.log('stopping examples ui...') | ||
ui.shutdown() | ||
process.exit() | ||
}) |
@@ -10,3 +10,4 @@ const client = require('prom-client') | ||
const uniqueEvents = new client.Counter({ | ||
// TODO: Maybe we need to change these back to Counters, maybe not. | ||
const uniqueEvents = new client.Gauge({ | ||
name: 'unique_events_processed', | ||
@@ -17,3 +18,3 @@ help: 'Number of unique events processed by Cerebro' | ||
const pullRequests = new client.Counter({ | ||
const pullRequests = new client.Gauge({ | ||
name: 'pull_requests_processed', | ||
@@ -24,3 +25,3 @@ help: 'Count of total pull request events processed.' | ||
const suitablePRs = new client.Counter({ | ||
const suitablePRs = new client.Gauge({ | ||
name: 'suitable_pull_requests_found', | ||
@@ -31,3 +32,3 @@ help: 'Number of suitable pull requests by Cerebro' | ||
const missIncludedLangs = new client.Counter({ | ||
const missIncludedLangs = new client.Gauge({ | ||
name: 'miss_included_langs', | ||
@@ -38,3 +39,3 @@ help: 'Pull request -> candidate miss based on target programming language' | ||
const missNonHireable = new client.Counter({ | ||
const missNonHireable = new client.Gauge({ | ||
name: 'miss_non_hireable', | ||
@@ -45,3 +46,3 @@ help: 'Pull request -> candidate miss candidate.hirable value' | ||
const candidatesFound = new client.Counter({ | ||
const candidatesFound = new client.Gauge({ | ||
name: 'candidates_found', | ||
@@ -48,0 +49,0 @@ help: 'Count of candidates found by Cerebro so far', |
@@ -5,6 +5,15 @@ const { Octokit } = require('@octokit/rest') | ||
let seekInterval | ||
let metricsInterval, seekInterval | ||
let octokit | ||
let cursor = 0 | ||
let metrics = { | ||
uniqueEvents: 0, | ||
prEvents: 0, | ||
suitablePRs: 0, | ||
missIncludedLangs: 0, | ||
missNonHireable: 0, | ||
candidatesFound: 0 | ||
} | ||
function getNewEvents (ghEvents) { | ||
@@ -15,3 +24,3 @@ const uniqueEvents = ghEvents.filter(d => parseInt(d.id, 10) > cursor) | ||
events.emit('stats-unique-events', uniqueEvents.length) | ||
metrics.uniqueEvents += uniqueEvents.length | ||
return Promise.resolve(uniqueEvents) | ||
@@ -25,3 +34,3 @@ } | ||
events.emit('stats-pull-requests', prEvents.length) | ||
metrics.prEvents += prEvents.length | ||
return Promise.resolve(prEvents) | ||
@@ -41,3 +50,3 @@ } | ||
events.emit('stats-suitable-prs', suitablePRs.length) | ||
metrics.suitablePRs += suitablePRs.length | ||
return Promise.resolve(suitablePRs) | ||
@@ -78,7 +87,22 @@ } | ||
return seek | ||
}()), interval) // IIFE executes automatically | ||
})(), interval) // IIFE executes automatically | ||
metricsInterval = setInterval(function sendMetrics () { | ||
events.emit('metrics', metrics) | ||
return sendMetrics | ||
}, 5000) | ||
} | ||
function stop () { | ||
clearInterval(metricsInterval) | ||
clearInterval(seekInterval) | ||
events.removeAllListeners() | ||
metrics = { | ||
uniqueEvents: 0, | ||
prEvents: 0, | ||
suitablePRs: 0, | ||
missIncludedLangs: 0, | ||
missNonHireable: 0, | ||
candidatesFound: 0 | ||
} | ||
cursor = 0 | ||
@@ -102,3 +126,3 @@ } | ||
if (includedLangs.length === 0) { | ||
events.emit('miss-included-langs', 1) | ||
metrics.missIncludedLangs++ | ||
continue | ||
@@ -110,3 +134,3 @@ } | ||
if (!candidate.hireable && !showNonHireable) { | ||
events.emit('miss-non-hireable', 1) | ||
metrics.missNonHireable++ | ||
continue | ||
@@ -120,2 +144,3 @@ } | ||
}) | ||
metrics.candidatesFound++ | ||
} | ||
@@ -122,0 +147,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52786
9
294
3