aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-08-12 16:41:29 +0200
committerChocobozzz <me@florianbigard.com>2022-08-16 10:33:27 +0200
commitfd3c2e87051f5029cdec39d877b576a62f48e219 (patch)
treea3c657f178702a3363af680ed8ffb7cd038243b8 /server/controllers/api
parent0e6cd1c00f71554fe7375a96db693a6983951ba6 (diff)
downloadPeerTube-fd3c2e87051f5029cdec39d877b576a62f48e219.tar.gz
PeerTube-fd3c2e87051f5029cdec39d877b576a62f48e219.tar.zst
PeerTube-fd3c2e87051f5029cdec39d877b576a62f48e219.zip
Add playback metric endpoint sent to OTEL
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/index.ts4
-rw-r--r--server/controllers/api/metrics.ts27
2 files changed, 30 insertions, 1 deletions
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'
11import { configRouter } from './config' 11import { configRouter } from './config'
12import { customPageRouter } from './custom-page' 12import { customPageRouter } from './custom-page'
13import { jobsRouter } from './jobs' 13import { jobsRouter } from './jobs'
14import { metricsRouter } from './metrics'
14import { oauthClientsRouter } from './oauth-clients' 15import { oauthClientsRouter } from './oauth-clients'
15import { overviewsRouter } from './overviews' 16import { overviewsRouter } from './overviews'
16import { pluginRouter } from './plugins' 17import { pluginRouter } from './plugins'
@@ -18,9 +19,9 @@ import { searchRouter } from './search'
18import { serverRouter } from './server' 19import { serverRouter } from './server'
19import { usersRouter } from './users' 20import { usersRouter } from './users'
20import { videoChannelRouter } from './video-channel' 21import { videoChannelRouter } from './video-channel'
22import { videoChannelSyncRouter } from './video-channel-sync'
21import { videoPlaylistRouter } from './video-playlist' 23import { videoPlaylistRouter } from './video-playlist'
22import { videosRouter } from './videos' 24import { videosRouter } from './videos'
23import { videoChannelSyncRouter } from './video-channel-sync'
24 25
25const apiRouter = express.Router() 26const apiRouter = express.Router()
26 27
@@ -48,6 +49,7 @@ apiRouter.use('/video-channel-syncs', videoChannelSyncRouter)
48apiRouter.use('/video-playlists', videoPlaylistRouter) 49apiRouter.use('/video-playlists', videoPlaylistRouter)
49apiRouter.use('/videos', videosRouter) 50apiRouter.use('/videos', videosRouter)
50apiRouter.use('/jobs', jobsRouter) 51apiRouter.use('/jobs', jobsRouter)
52apiRouter.use('/metrics', metricsRouter)
51apiRouter.use('/search', searchRouter) 53apiRouter.use('/search', searchRouter)
52apiRouter.use('/overviews', overviewsRouter) 54apiRouter.use('/overviews', overviewsRouter)
53apiRouter.use('/plugins', pluginRouter) 55apiRouter.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 @@
1import express from 'express'
2import { OpenTelemetryMetrics } from '@server/lib/opentelemetry/metrics'
3import { HttpStatusCode, PlaybackMetricCreate } from '@shared/models'
4import { addPlaybackMetricValidator, asyncMiddleware } from '../../middlewares'
5
6const metricsRouter = express.Router()
7
8metricsRouter.post('/playback',
9 asyncMiddleware(addPlaybackMetricValidator),
10 addPlaybackMetric
11)
12
13// ---------------------------------------------------------------------------
14
15export {
16 metricsRouter
17}
18
19// ---------------------------------------------------------------------------
20
21function addPlaybackMetric (req: express.Request, res: express.Response) {
22 const body: PlaybackMetricCreate = req.body
23
24 OpenTelemetryMetrics.Instance.observePlaybackMetric(res.locals.onlyImmutableVideo, body)
25
26 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
27}