Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Prometheus Metric Names for Bull Queue Durations #3649

Merged
merged 5 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ export class PrometheusRegistry {

// job duration in seconds
const jobDuration = (job.finishedOn - job.processedOn!) * 1000
this.getMetric(
this.metricNames.JOBS_DURATION_MILLISECONDS_HISTOGRAM
).observe(jobLabels, jobDuration)
this.getMetric(this.metricNames.JOBS_DURATION_SECONDS_HISTOGRAM).observe(
jobLabels,
jobDuration
)

// job duration in seconds
const waitingDuration = (job.processedOn! - job.timestamp) * 1000
this.getMetric(
this.metricNames.JOBS_WAITING_DURATION_MILLISECONDS_HISTOGRAM
this.metricNames.JOBS_WAITING_DURATION_SECONDS_HISTOGRAM
).observe(jobLabels, waitingDuration)

this.getMetric(this.metricNames.JOBS_ATTEMPTS_HISTOGRAM).observe(
Expand Down
40 changes: 40 additions & 0 deletions creator-node/test/lib/genericBullQueueMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const PrometheusRegistry = require('../../src/services/prometheusMonitoring/prometheusRegistry')
const Bull = require('bull')

const config = require('../../src/config')

// Mock monitoring queue that sets monitor values on construction
class GenericBullQueue {
constructor() {
this.queue = Bull('genericBullQueue', {
redis: {
host: config.get('redisHost'),
port: config.get('redisPort')
},
defaultJobOptions: {
removeOnComplete: 0,
removeOnFail: 0
}
})
const prometheusRegistry = new PrometheusRegistry()
prometheusRegistry.startQueueMetrics(this.queue)

this.queue.process(1, async (job) => {
console.log(this.params)
jonaylor89 marked this conversation as resolved.
Show resolved Hide resolved

const { timeout } = job.data
if (timeout) {
console.log(`waiting ${timeout}`)
setTimeout(() => console.log(`done ${timeout}`), timeout)
}
})
}

async addTask(params) {
const job = await this.queue.add(params)

return job
}
}

module.exports = GenericBullQueue
14 changes: 14 additions & 0 deletions creator-node/test/prometheus.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { getLibsMock } = require('./lib/libsMock')
const {
NAMESPACE_PREFIX
} = require('../src/services/prometheusMonitoring/prometheus.constants')
const GenericBullQueue = require('./lib/genericBullQueueMock')

describe('test Prometheus metrics', async function () {
let app, server, libsMock
Expand Down Expand Up @@ -117,4 +118,17 @@ describe('test Prometheus metrics', async function () {
assert.ok(resp.text.includes(NAMESPACE_PREFIX + '_jobs_active'))
assert.ok(resp.text.includes(NAMESPACE_PREFIX + '_jobs_delayed'))
})

it('Checks the duration of a bull queue job', async function () {
const genericBullQueue = new GenericBullQueue()
const job = await genericBullQueue.addTask({ timeout: 500 })

await job.finished()

const resp = await request(app).get('/prometheus_metrics').expect(200)
assert.ok(
resp.text.includes(NAMESPACE_PREFIX + '_jobs_duration_seconds_bucket')
vicky-g marked this conversation as resolved.
Show resolved Hide resolved
jonaylor89 marked this conversation as resolved.
Show resolved Hide resolved
)
assert.ok(resp.text.includes(`queue_name="genericBullQueue"`))
})
})