Skip to content

Commit

Permalink
Add logs on the scrape clients (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
HDegroote authored Jul 23, 2024
1 parent 9f8980a commit 28d4cca
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class PrometheusDhtBridge extends ReadyResource {
)

this.aliases.set(alias, entry)
this.emit('set-alias', { alias, publicKey: targetPubKey })
this.emit('set-alias', { alias, publicKey: targetPubKey, scrapeClient: entry.scrapeClient })
const updated = true

if (write === true) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"dependencies": {
"b4a": "^1.6.6",
"debounceify": "^1.1.0",
"dht-prom-client": "^0.0.1-alpha.3",
"dht-prom-client": "^0.0.1-alpha.6",
"fastify": "^4.28.0",
"graceful-goodbye": "^1.3.0",
"hypercore-id-encoding": "^1.3.0",
Expand Down
17 changes: 16 additions & 1 deletion run.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,23 @@ async function main () {
}

function setupLogging (bridge, logger) {
bridge.on('set-alias', ({ alias, publicKey }) => {
bridge.on('set-alias', ({ alias, publicKey, scrapeClient }) => {
logger.info(`Registered alias: ${alias} -> ${idEnc.normalize(publicKey)}`)

scrapeClient.on('connection-open', ({ uid, targetKey, peerInfo }) => {
logger.info(`Scraper for ${alias}->${idEnc.normalize(targetKey)} opened connection from ${idEnc.normalize(peerInfo.publicKey)} (uid: ${uid})`)
})
scrapeClient.on('connection-ignore', ({ uid }) => {
logger.info(`Scraper for ${alias} ignored connection (uid: ${uid})`)
})
scrapeClient.on('connection-close', ({ uid }) => {
logger.info(`Scraper for ${alias} closed connection (uid: ${uid})`)
})

scrapeClient.on('connection-error', ({ error, uid }) => {
logger.info(`Scraper for ${alias} connection error (uid: ${uid})`)
logger.info(error)
})
})

bridge.on('aliases-updated', (loc) => {
Expand Down
3 changes: 2 additions & 1 deletion test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const BRIDGE_EXECUTABLE = path.join(path.dirname(__dirname), 'run.js')
const PROMETHEUS_EXECUTABLE = path.join(path.dirname(__dirname), 'prometheus', 'prometheus')

const DEBUG = false
const DEBUG_PROMETHEUS = false

// Note: move this inside the test if we ever have >1 integration test
promClient.collectDefaultMetrics() // So we have something to scrape
Expand Down Expand Up @@ -183,7 +184,7 @@ test('Integration test, happy path', async t => {
let confirmedBridgeOffline = false

promProc.stderr.on('data', d => {
if (DEBUG) console.log('PROMETHEUS', d.toString())
if (DEBUG_PROMETHEUS) console.log('PROMETHEUS', d.toString())

for (const line of stdoutDec.push(d)) {
if (line.includes('Server is ready to receive web requests')) {
Expand Down

0 comments on commit 28d4cca

Please sign in to comment.