Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 134
CON-181 Add prometheus metrics to CN#3166
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
a20877fc16d74dbde9f32f74288b5925bc24a42a011e2c073c5612b0ca32678eae75565287be57cffbcbe424700a7f5b67c00fe481a9570f147ae52608b26d40bbc50e707ca533921741d3e7683bb00a25516909551548fFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| /** | ||
| * Exposes Prometheus metrics at `GET /prometheus_metrics` | ||
| */ | ||
| module.exports = function (app) { | ||
| app.get('/prometheus_metrics', async (req, res) => { | ||
| const prometheusRegistry = req.app.get('serviceRegistry').prometheusRegistry | ||
| const metricData = await prometheusRegistry.getAllMetricData() | ||
| res.setHeader('Content-Type', prometheusRegistry.registry.contentType) | ||
| return res.end(metricData) | ||
| }) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -304,8 +304,17 @@ module.exports = function (app) { | ||
| transcodedTrackUUID | ||
| } = req.body | ||
| const prometheusRegistry = | ||
| req.app.get('serviceRegistry').prometheusRegistry | ||
| const routePostTracksDurationSecondsMetric = prometheusRegistry.getMetric( | ||
| prometheusRegistry.metricNames | ||
| .ROUTE_POST_TRACKS_DURATION_SECONDS_HISTOGRAM | ||
| ) | ||
| const metricEndTimerFn = routePostTracksDurationSecondsMetric.startTimer() | ||
| // Input validation | ||
| if (!blockchainTrackId || !blockNumber || !metadataFileUUID) { | ||
| metricEndTimerFn({ code: 400 }) | ||
SidSethi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| return errorResponseBadRequest( | ||
| 'Must include blockchainTrackId, blockNumber, and metadataFileUUID.' | ||
| ) | ||
| @@ -314,6 +323,7 @@ module.exports = function (app) { | ||
| // Error on outdated blocknumber | ||
| const cnodeUser = req.session.cnodeUser | ||
| if (blockNumber < cnodeUser.latestBlockNumber) { | ||
| metricEndTimerFn({ code: 400 }) | ||
| return errorResponseBadRequest( | ||
| `Invalid blockNumber param ${blockNumber}. Must be greater or equal to previously processed blocknumber ${cnodeUser.latestBlockNumber}.` | ||
| ) | ||
| @@ -325,6 +335,7 @@ module.exports = function (app) { | ||
| where: { fileUUID: metadataFileUUID, cnodeUserUUID } | ||
| }) | ||
| if (!file) { | ||
| metricEndTimerFn({ code: 400 }) | ||
| return errorResponseBadRequest( | ||
| `No file db record found for provided metadataFileUUID ${metadataFileUUID}.` | ||
| ) | ||
| @@ -339,11 +350,13 @@ module.exports = function (app) { | ||
| !Array.isArray(metadataJSON.track_segments) || | ||
| !metadataJSON.track_segments.length | ||
| ) { | ||
| metricEndTimerFn({ code: 500 }) | ||
| return errorResponseServerError( | ||
| `Malformatted metadataJSON stored for metadataFileUUID ${metadataFileUUID}.` | ||
| ) | ||
| } | ||
| } catch (e) { | ||
| metricEndTimerFn({ code: 500 }) | ||
| return errorResponseServerError( | ||
| `No file stored on disk for metadataFileUUID ${metadataFileUUID} at storagePath ${file.storagePath}.` | ||
| ) | ||
| @@ -357,6 +370,7 @@ module.exports = function (app) { | ||
| metadataJSON.cover_art_sizes | ||
| ) | ||
| } catch (e) { | ||
| metricEndTimerFn({ code: 500 }) | ||
| return errorResponseServerError(e.message) | ||
| } | ||
| @@ -543,10 +557,12 @@ module.exports = function (app) { | ||
| await issueAndWaitForSecondarySyncRequests(req) | ||
| metricEndTimerFn({ code: 200 }) | ||
| return successResponse() | ||
| } catch (e) { | ||
| req.logger.error(e.message) | ||
| await transaction.rollback() | ||
| metricEndTimerFn({ code: 500 }) | ||
SidSethi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| return errorResponseServerError(e.message) | ||
| } | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| const { createBullBoard } = require('@bull-board/api') | ||
| const { BullAdapter } = require('@bull-board/api/bullAdapter') | ||
| const { ExpressAdapter } = require('@bull-board/express') | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just moved lines from below | ||
| const { libs: AudiusLibs } = require('@audius/sdk') | ||
| const redisClient = require('./redis') | ||
| const BlacklistManager = require('./blacklistManager') | ||
| @@ -6,10 +10,6 @@ const config = require('./config') | ||
| const URSMRegistrationManager = require('./services/URSMRegistrationManager') | ||
| const { logger } = require('./logging') | ||
| const utils = require('./utils') | ||
| const { createBullBoard } = require('@bull-board/api') | ||
| const { BullAdapter } = require('@bull-board/api/bullAdapter') | ||
| const { ExpressAdapter } = require('@bull-board/express') | ||
| const MonitoringQueue = require('./monitors/MonitoringQueue') | ||
| const SyncQueue = require('./services/sync/syncQueue') | ||
| const SkippedCIDsRetryQueue = require('./services/sync/skippedCIDsRetryService') | ||
| @@ -19,6 +19,7 @@ const TrustedNotifierManager = require('./services/TrustedNotifierManager') | ||
| const ImageProcessingQueue = require('./ImageProcessingQueue') | ||
| const TranscodingQueue = require('./TranscodingQueue') | ||
| const StateMachineManager = require('./services/stateMachineManager') | ||
| const PrometheusRegistry = require('./services/prometheusMonitoring/prometheusRegistry') | ||
| /** | ||
| * `ServiceRegistry` is a container responsible for exposing various | ||
| @@ -45,6 +46,7 @@ class ServiceRegistry { | ||
| this.blacklistManager = BlacklistManager | ||
| this.monitoringQueue = new MonitoringQueue() | ||
| this.sessionExpirationQueue = new SessionExpirationQueue() | ||
| this.prometheusRegistry = new PrometheusRegistry() | ||
| // below services are initialized separately in below functions `initServices()` and `initServicesThatRequireServer()` | ||
| this.libs = null | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i just used this as an example of a Gauge metric - the previous example in Monitors was actually broken