diff options
author | Chocobozzz <me@florianbigard.com> | 2022-08-12 16:41:29 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-08-16 10:33:27 +0200 |
commit | fd3c2e87051f5029cdec39d877b576a62f48e219 (patch) | |
tree | a3c657f178702a3363af680ed8ffb7cd038243b8 /server/controllers/api/metrics.ts | |
parent | 0e6cd1c00f71554fe7375a96db693a6983951ba6 (diff) | |
download | PeerTube-fd3c2e87051f5029cdec39d877b576a62f48e219.tar.gz PeerTube-fd3c2e87051f5029cdec39d877b576a62f48e219.tar.zst PeerTube-fd3c2e87051f5029cdec39d877b576a62f48e219.zip |
Add playback metric endpoint sent to OTEL
Diffstat (limited to 'server/controllers/api/metrics.ts')
-rw-r--r-- | server/controllers/api/metrics.ts | 27 |
1 files changed, 27 insertions, 0 deletions
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 @@ | |||
1 | import express from 'express' | ||
2 | import { OpenTelemetryMetrics } from '@server/lib/opentelemetry/metrics' | ||
3 | import { HttpStatusCode, PlaybackMetricCreate } from '@shared/models' | ||
4 | import { addPlaybackMetricValidator, asyncMiddleware } from '../../middlewares' | ||
5 | |||
6 | const metricsRouter = express.Router() | ||
7 | |||
8 | metricsRouter.post('/playback', | ||
9 | asyncMiddleware(addPlaybackMetricValidator), | ||
10 | addPlaybackMetric | ||
11 | ) | ||
12 | |||
13 | // --------------------------------------------------------------------------- | ||
14 | |||
15 | export { | ||
16 | metricsRouter | ||
17 | } | ||
18 | |||
19 | // --------------------------------------------------------------------------- | ||
20 | |||
21 | function 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 | } | ||