From fd3c2e87051f5029cdec39d877b576a62f48e219 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 12 Aug 2022 16:41:29 +0200 Subject: Add playback metric endpoint sent to OTEL --- server/controllers/api/index.ts | 4 +++- server/controllers/api/metrics.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 server/controllers/api/metrics.ts (limited to 'server/controllers/api') diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts index 8c8ebd061..e1d197c8a 100644 --- a/server/controllers/api/index.ts +++ b/server/controllers/api/index.ts @@ -11,6 +11,7 @@ import { bulkRouter } from './bulk' import { configRouter } from './config' import { customPageRouter } from './custom-page' import { jobsRouter } from './jobs' +import { metricsRouter } from './metrics' import { oauthClientsRouter } from './oauth-clients' import { overviewsRouter } from './overviews' import { pluginRouter } from './plugins' @@ -18,9 +19,9 @@ import { searchRouter } from './search' import { serverRouter } from './server' import { usersRouter } from './users' import { videoChannelRouter } from './video-channel' +import { videoChannelSyncRouter } from './video-channel-sync' import { videoPlaylistRouter } from './video-playlist' import { videosRouter } from './videos' -import { videoChannelSyncRouter } from './video-channel-sync' const apiRouter = express.Router() @@ -48,6 +49,7 @@ apiRouter.use('/video-channel-syncs', videoChannelSyncRouter) apiRouter.use('/video-playlists', videoPlaylistRouter) apiRouter.use('/videos', videosRouter) apiRouter.use('/jobs', jobsRouter) +apiRouter.use('/metrics', metricsRouter) apiRouter.use('/search', searchRouter) apiRouter.use('/overviews', overviewsRouter) apiRouter.use('/plugins', pluginRouter) diff --git a/server/controllers/api/metrics.ts b/server/controllers/api/metrics.ts new file mode 100644 index 000000000..578b023a1 --- /dev/null +++ b/server/controllers/api/metrics.ts @@ -0,0 +1,27 @@ +import express from 'express' +import { OpenTelemetryMetrics } from '@server/lib/opentelemetry/metrics' +import { HttpStatusCode, PlaybackMetricCreate } from '@shared/models' +import { addPlaybackMetricValidator, asyncMiddleware } from '../../middlewares' + +const metricsRouter = express.Router() + +metricsRouter.post('/playback', + asyncMiddleware(addPlaybackMetricValidator), + addPlaybackMetric +) + +// --------------------------------------------------------------------------- + +export { + metricsRouter +} + +// --------------------------------------------------------------------------- + +function addPlaybackMetric (req: express.Request, res: express.Response) { + const body: PlaybackMetricCreate = req.body + + OpenTelemetryMetrics.Instance.observePlaybackMetric(res.locals.onlyImmutableVideo, body) + + return res.sendStatus(HttpStatusCode.NO_CONTENT_204) +} -- cgit v1.2.3