Skip to content

Commit

Permalink
Refine metrics on user social interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
bkimminich committed Feb 19, 2020
1 parent b765a39 commit 5cc625f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
20 changes: 15 additions & 5 deletions routes/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

const Prometheus = require('prom-client')
const orders = require('../data/mongodb').orders
const reviews = require('../data/mongodb').reviews
const challenges = require('../data/datacache').challenges
const utils = require('../lib/utils')
const config = require('config')
Expand Down Expand Up @@ -58,9 +59,10 @@ exports.observeMetrics = function observeMetrics () {
help: 'Total balance of all users\' digital wallets.'
})

const complaintMetrics = new Prometheus.Gauge({
name: `${app}_user_complaints_total`,
help: 'Unwarranted occurrences of customer lamentation.'
const interactionsMetrics = new Prometheus.Gauge({
name: `${app}_user_social_interactions`,
help: 'Number of social interactions with users grouped by type.',
labelNames: ['type']
})

register.registerMetric(challengeSolvedMetrics)
Expand All @@ -69,7 +71,7 @@ exports.observeMetrics = function observeMetrics () {
register.registerMetric(userMetrics)
register.registerMetric(userTotalMetrics)
register.registerMetric(walletMetrics)
register.registerMetric(complaintMetrics)
register.registerMetric(interactionsMetrics)

const updateLoop = setInterval(() => {
const challengeKeys = Object.keys(challenges)
Expand All @@ -82,6 +84,10 @@ exports.observeMetrics = function observeMetrics () {
orderMetrics.set(orders)
})

reviews.count({}).then(reviews => {
interactionsMetrics.set({ type: 'review' }, reviews)
})

models.User.count({ where: { role: { [Op.eq]: ['customer'] } } }).then(count => {
userMetrics.set({ type: 'standard' }, count)
})
Expand All @@ -96,8 +102,12 @@ exports.observeMetrics = function observeMetrics () {
walletMetrics.set(totalBalance)
})

models.Feedback.count().then(count => {
interactionsMetrics.set({ type: 'feedback' }, count)
})

models.Complaint.count().then(count => {
complaintMetrics.set(count)
interactionsMetrics.set({ type: 'complaint' }, count)
})
}, 5000)

Expand Down
4 changes: 3 additions & 1 deletion test/api/metricsApiSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ describe('/metrics', () => {
.expect('bodyContains', /^.*_users_registered{type="deluxe",app=".*"} [0-9]*$/gm)
.expect('bodyContains', /^.*_users_registered_total{app=".*"} [0-9]*$/gm)
.expect('bodyContains', /^.*_wallet_balance_total{app=".*"} [0-9]*$/gm)
.expect('bodyContains', /^.*_user_complaints_total{app=".*"} [0-9]*$/gm)
.expect('bodyContains', /^.*__user_social_interactions{type="review",app=".*"} [0-9]*$/gm)
.expect('bodyContains', /^.*__user_social_interactions{type="feedback",app=".*"} [0-9]*$/gm)
.expect('bodyContains', /^.*__user_social_interactions{type="complaint",app=".*"} [0-9]*$/gm)
})
})

0 comments on commit 5cc625f

Please sign in to comment.