1
0
Fork 0
peertube/server/controllers/api/metrics.ts
kontrollanten e72ace5a50
Handle redis disconnection gracefully (#5599)
* feat(server/api/contact): handle redis disconnection

* feat(server/api/metrics): handle metrics disabled
2023-03-14 08:50:44 +01:00

32 lines
1,017 B
TypeScript

import express from 'express'
import { OpenTelemetryMetrics } from '@server/lib/opentelemetry/metrics'
import { HttpStatusCode, PlaybackMetricCreate } from '@shared/models'
import { addPlaybackMetricValidator, asyncMiddleware } from '../../middlewares'
import { CONFIG } from '@server/initializers/config'
const metricsRouter = express.Router()
metricsRouter.post('/playback',
asyncMiddleware(addPlaybackMetricValidator),
addPlaybackMetric
)
// ---------------------------------------------------------------------------
export {
metricsRouter
}
// ---------------------------------------------------------------------------
function addPlaybackMetric (req: express.Request, res: express.Response) {
if (!CONFIG.OPEN_TELEMETRY.METRICS.ENABLED) {
return res.sendStatus(HttpStatusCode.FORBIDDEN_403)
}
const body: PlaybackMetricCreate = req.body
OpenTelemetryMetrics.Instance.observePlaybackMetric(res.locals.onlyImmutableVideo, body)
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
}