diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/lib/opentelemetry/metric-helpers/playback-metrics.ts | 12 | ||||
-rw-r--r-- | server/middlewares/validators/metrics.ts | 9 | ||||
-rw-r--r-- | server/tests/api/check-params/metrics.ts | 27 | ||||
-rw-r--r-- | server/tests/api/server/open-telemetry.ts | 2 |
4 files changed, 45 insertions, 5 deletions
diff --git a/server/lib/opentelemetry/metric-helpers/playback-metrics.ts b/server/lib/opentelemetry/metric-helpers/playback-metrics.ts index 406789618..41a5dd640 100644 --- a/server/lib/opentelemetry/metric-helpers/playback-metrics.ts +++ b/server/lib/opentelemetry/metric-helpers/playback-metrics.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { Counter, Meter } from '@opentelemetry/api' | 1 | import { Counter, Histogram, Meter } from '@opentelemetry/api' |
2 | import { MVideoImmutable } from '@server/types/models' | 2 | import { MVideoImmutable } from '@server/types/models' |
3 | import { PlaybackMetricCreate } from '@shared/models' | 3 | import { PlaybackMetricCreate } from '@shared/models' |
4 | 4 | ||
@@ -11,6 +11,8 @@ export class PlaybackMetrics { | |||
11 | 11 | ||
12 | private downloadedBytesHTTPCounter: Counter | 12 | private downloadedBytesHTTPCounter: Counter |
13 | 13 | ||
14 | private peersP2PPeers: Histogram | ||
15 | |||
14 | constructor (private readonly meter: Meter) { | 16 | constructor (private readonly meter: Meter) { |
15 | 17 | ||
16 | } | 18 | } |
@@ -34,6 +36,10 @@ export class PlaybackMetrics { | |||
34 | this.uploadedBytesP2PCounter = this.meter.createCounter('peertube_playback_p2p_uploaded_bytes', { | 36 | this.uploadedBytesP2PCounter = this.meter.createCounter('peertube_playback_p2p_uploaded_bytes', { |
35 | description: 'Uploaded bytes with P2P by PeerTube player.' | 37 | description: 'Uploaded bytes with P2P by PeerTube player.' |
36 | }) | 38 | }) |
39 | |||
40 | this.peersP2PPeers = this.meter.createHistogram('peertube_playback_p2p_peers', { | ||
41 | description: 'Total P2P peers connected to the PeerTube player.' | ||
42 | }) | ||
37 | } | 43 | } |
38 | 44 | ||
39 | observe (video: MVideoImmutable, metrics: PlaybackMetricCreate) { | 45 | observe (video: MVideoImmutable, metrics: PlaybackMetricCreate) { |
@@ -47,6 +53,8 @@ export class PlaybackMetrics { | |||
47 | resolution: metrics.resolution + '', | 53 | resolution: metrics.resolution + '', |
48 | fps: metrics.fps + '', | 54 | fps: metrics.fps + '', |
49 | 55 | ||
56 | p2pEnabled: metrics.p2pEnabled, | ||
57 | |||
50 | videoUUID: video.uuid | 58 | videoUUID: video.uuid |
51 | } | 59 | } |
52 | 60 | ||
@@ -57,5 +65,7 @@ export class PlaybackMetrics { | |||
57 | this.downloadedBytesP2PCounter.add(metrics.downloadedBytesP2P, attributes) | 65 | this.downloadedBytesP2PCounter.add(metrics.downloadedBytesP2P, attributes) |
58 | 66 | ||
59 | this.uploadedBytesP2PCounter.add(metrics.uploadedBytesP2P, attributes) | 67 | this.uploadedBytesP2PCounter.add(metrics.uploadedBytesP2P, attributes) |
68 | |||
69 | if (metrics.totalPeers) this.peersP2PPeers.record(metrics.totalPeers, attributes) | ||
60 | } | 70 | } |
61 | } | 71 | } |
diff --git a/server/middlewares/validators/metrics.ts b/server/middlewares/validators/metrics.ts index 8ee5ac0d0..ced9afc69 100644 --- a/server/middlewares/validators/metrics.ts +++ b/server/middlewares/validators/metrics.ts | |||
@@ -12,6 +12,15 @@ const addPlaybackMetricValidator = [ | |||
12 | body('fps') | 12 | body('fps') |
13 | .optional() | 13 | .optional() |
14 | .isInt({ min: 0 }), | 14 | .isInt({ min: 0 }), |
15 | |||
16 | body('totalPeers') | ||
17 | .optional() | ||
18 | .isInt({ min: 0 }), | ||
19 | |||
20 | body('p2pEnabled') | ||
21 | .optional() | ||
22 | .isBoolean(), | ||
23 | |||
15 | body('playerMode') | 24 | body('playerMode') |
16 | .custom(isValidPlayerMode), | 25 | .custom(isValidPlayerMode), |
17 | 26 | ||
diff --git a/server/tests/api/check-params/metrics.ts b/server/tests/api/check-params/metrics.ts index be8253217..25443401d 100644 --- a/server/tests/api/check-params/metrics.ts +++ b/server/tests/api/check-params/metrics.ts | |||
@@ -89,10 +89,6 @@ describe('Test metrics API validators', function () { | |||
89 | }) | 89 | }) |
90 | }) | 90 | }) |
91 | 91 | ||
92 | it('Should fail with a missing errors', async function () { | ||
93 | |||
94 | }) | ||
95 | |||
96 | it('Should fail with an missing/invalid errors', async function () { | 92 | it('Should fail with an missing/invalid errors', async function () { |
97 | await makePostBodyRequest({ | 93 | await makePostBodyRequest({ |
98 | url: server.url, | 94 | url: server.url, |
@@ -149,6 +145,22 @@ describe('Test metrics API validators', function () { | |||
149 | }) | 145 | }) |
150 | }) | 146 | }) |
151 | 147 | ||
148 | it('Should fail with an invalid p2pEnabled', async function () { | ||
149 | await makePostBodyRequest({ | ||
150 | url: server.url, | ||
151 | path, | ||
152 | fields: { ...baseParams, p2pEnabled: 'toto' } | ||
153 | }) | ||
154 | }) | ||
155 | |||
156 | it('Should fail with an invalid totalPeers', async function () { | ||
157 | await makePostBodyRequest({ | ||
158 | url: server.url, | ||
159 | path, | ||
160 | fields: { ...baseParams, totalPeers: 'toto' } | ||
161 | }) | ||
162 | }) | ||
163 | |||
152 | it('Should fail with a bad video id', async function () { | 164 | it('Should fail with a bad video id', async function () { |
153 | await makePostBodyRequest({ | 165 | await makePostBodyRequest({ |
154 | url: server.url, | 166 | url: server.url, |
@@ -173,6 +185,13 @@ describe('Test metrics API validators', function () { | |||
173 | fields: baseParams, | 185 | fields: baseParams, |
174 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | 186 | expectedStatus: HttpStatusCode.NO_CONTENT_204 |
175 | }) | 187 | }) |
188 | |||
189 | await makePostBodyRequest({ | ||
190 | url: server.url, | ||
191 | path, | ||
192 | fields: { ...baseParams, p2pEnabled: false, totalPeers: 32 }, | ||
193 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
194 | }) | ||
176 | }) | 195 | }) |
177 | }) | 196 | }) |
178 | 197 | ||
diff --git a/server/tests/api/server/open-telemetry.ts b/server/tests/api/server/open-telemetry.ts index fd85fc514..0bd0b5e86 100644 --- a/server/tests/api/server/open-telemetry.ts +++ b/server/tests/api/server/open-telemetry.ts | |||
@@ -62,6 +62,8 @@ describe('Open Telemetry', function () { | |||
62 | downloadedBytesP2P: 0, | 62 | downloadedBytesP2P: 0, |
63 | downloadedBytesHTTP: 0, | 63 | downloadedBytesHTTP: 0, |
64 | uploadedBytesP2P: 5, | 64 | uploadedBytesP2P: 5, |
65 | totalPeers: 1, | ||
66 | p2pEnabled: false, | ||
65 | videoId: video.uuid | 67 | videoId: video.uuid |
66 | } | 68 | } |
67 | }) | 69 | }) |