diff options
author | kontrollanten <6680299+kontrollanten@users.noreply.github.com> | 2023-03-14 08:50:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-14 08:50:44 +0100 |
commit | e72ace5a506904a67290e347e962ddf930d2b9f9 (patch) | |
tree | 08af8cb7b20e9911c4962910024ba2ba70645d92 /server/controllers/api/metrics.ts | |
parent | 2b02a9b98cfc93a01b52ad6cb893e3d089fec472 (diff) | |
download | PeerTube-e72ace5a506904a67290e347e962ddf930d2b9f9.tar.gz PeerTube-e72ace5a506904a67290e347e962ddf930d2b9f9.tar.zst PeerTube-e72ace5a506904a67290e347e962ddf930d2b9f9.zip |
Handle redis disconnection gracefully (#5599)
* feat(server/api/contact): handle redis disconnection
* feat(server/api/metrics): handle metrics disabled
Diffstat (limited to 'server/controllers/api/metrics.ts')
-rw-r--r-- | server/controllers/api/metrics.ts | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/server/controllers/api/metrics.ts b/server/controllers/api/metrics.ts index 578b023a1..f66173875 100644 --- a/server/controllers/api/metrics.ts +++ b/server/controllers/api/metrics.ts | |||
@@ -2,6 +2,7 @@ import express from 'express' | |||
2 | import { OpenTelemetryMetrics } from '@server/lib/opentelemetry/metrics' | 2 | import { OpenTelemetryMetrics } from '@server/lib/opentelemetry/metrics' |
3 | import { HttpStatusCode, PlaybackMetricCreate } from '@shared/models' | 3 | import { HttpStatusCode, PlaybackMetricCreate } from '@shared/models' |
4 | import { addPlaybackMetricValidator, asyncMiddleware } from '../../middlewares' | 4 | import { addPlaybackMetricValidator, asyncMiddleware } from '../../middlewares' |
5 | import { CONFIG } from '@server/initializers/config' | ||
5 | 6 | ||
6 | const metricsRouter = express.Router() | 7 | const metricsRouter = express.Router() |
7 | 8 | ||
@@ -19,6 +20,10 @@ export { | |||
19 | // --------------------------------------------------------------------------- | 20 | // --------------------------------------------------------------------------- |
20 | 21 | ||
21 | function addPlaybackMetric (req: express.Request, res: express.Response) { | 22 | function addPlaybackMetric (req: express.Request, res: express.Response) { |
23 | if (!CONFIG.OPEN_TELEMETRY.METRICS.ENABLED) { | ||
24 | return res.sendStatus(HttpStatusCode.FORBIDDEN_403) | ||
25 | } | ||
26 | |||
22 | const body: PlaybackMetricCreate = req.body | 27 | const body: PlaybackMetricCreate = req.body |
23 | 28 | ||
24 | OpenTelemetryMetrics.Instance.observePlaybackMetric(res.locals.onlyImmutableVideo, body) | 29 | OpenTelemetryMetrics.Instance.observePlaybackMetric(res.locals.onlyImmutableVideo, body) |