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/tests/api | |
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/tests/api')
-rw-r--r-- | server/tests/api/check-params/index.ts | 1 | ||||
-rw-r--r-- | server/tests/api/check-params/metrics.ts | 183 | ||||
-rw-r--r-- | server/tests/api/server/open-telemetry.ts | 31 |
3 files changed, 212 insertions, 3 deletions
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts index 149305f49..cd7a38459 100644 --- a/server/tests/api/check-params/index.ts +++ b/server/tests/api/check-params/index.ts | |||
@@ -10,6 +10,7 @@ import './follows' | |||
10 | import './jobs' | 10 | import './jobs' |
11 | import './live' | 11 | import './live' |
12 | import './logs' | 12 | import './logs' |
13 | import './metrics' | ||
13 | import './my-user' | 14 | import './my-user' |
14 | import './plugins' | 15 | import './plugins' |
15 | import './redundancy' | 16 | import './redundancy' |
diff --git a/server/tests/api/check-params/metrics.ts b/server/tests/api/check-params/metrics.ts new file mode 100644 index 000000000..2d4509406 --- /dev/null +++ b/server/tests/api/check-params/metrics.ts | |||
@@ -0,0 +1,183 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import { omit } from 'lodash' | ||
5 | import { HttpStatusCode, PlaybackMetricCreate, VideoResolution } from '@shared/models' | ||
6 | import { cleanupTests, createSingleServer, makePostBodyRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' | ||
7 | |||
8 | describe('Test metrics API validators', function () { | ||
9 | let server: PeerTubeServer | ||
10 | let videoUUID: string | ||
11 | |||
12 | // --------------------------------------------------------------- | ||
13 | |||
14 | before(async function () { | ||
15 | this.timeout(120000) | ||
16 | |||
17 | server = await createSingleServer(1, { | ||
18 | open_telemetry: { | ||
19 | metrics: { | ||
20 | enabled: true | ||
21 | } | ||
22 | } | ||
23 | }) | ||
24 | |||
25 | await setAccessTokensToServers([ server ]) | ||
26 | |||
27 | const { uuid } = await server.videos.quickUpload({ name: 'video' }) | ||
28 | videoUUID = uuid | ||
29 | }) | ||
30 | |||
31 | describe('When adding playback metrics', function () { | ||
32 | const path = '/api/v1/metrics/playback' | ||
33 | let baseParams: PlaybackMetricCreate | ||
34 | |||
35 | before(function () { | ||
36 | baseParams = { | ||
37 | playerMode: 'p2p-media-loader', | ||
38 | resolution: VideoResolution.H_1080P, | ||
39 | fps: 30, | ||
40 | resolutionChanges: 1, | ||
41 | errors: 2, | ||
42 | downloadedBytesP2P: 0, | ||
43 | downloadedBytesHTTP: 0, | ||
44 | uploadedBytesP2P: 0, | ||
45 | videoId: videoUUID | ||
46 | } | ||
47 | }) | ||
48 | |||
49 | it('Should fail with an invalid resolution', async function () { | ||
50 | await makePostBodyRequest({ | ||
51 | url: server.url, | ||
52 | path, | ||
53 | fields: { ...baseParams, resolution: 'toto' } | ||
54 | }) | ||
55 | }) | ||
56 | |||
57 | it('Should fail with an invalid fps', async function () { | ||
58 | await makePostBodyRequest({ | ||
59 | url: server.url, | ||
60 | path, | ||
61 | fields: { ...baseParams, fps: 'toto' } | ||
62 | }) | ||
63 | }) | ||
64 | |||
65 | it('Should fail with a missing/invalid player mode', async function () { | ||
66 | await makePostBodyRequest({ | ||
67 | url: server.url, | ||
68 | path, | ||
69 | fields: omit(baseParams, 'playerMode') | ||
70 | }) | ||
71 | |||
72 | await makePostBodyRequest({ | ||
73 | url: server.url, | ||
74 | path, | ||
75 | fields: { ...baseParams, playerMode: 'toto' } | ||
76 | }) | ||
77 | }) | ||
78 | |||
79 | it('Should fail with an missing/invalid resolution changes', async function () { | ||
80 | await makePostBodyRequest({ | ||
81 | url: server.url, | ||
82 | path, | ||
83 | fields: omit(baseParams, 'resolutionChanges') | ||
84 | }) | ||
85 | |||
86 | await makePostBodyRequest({ | ||
87 | url: server.url, | ||
88 | path, | ||
89 | fields: { ...baseParams, resolutionChanges: 'toto' } | ||
90 | }) | ||
91 | }) | ||
92 | |||
93 | it('Should fail with a missing errors', async function () { | ||
94 | |||
95 | }) | ||
96 | |||
97 | it('Should fail with an missing/invalid errors', async function () { | ||
98 | await makePostBodyRequest({ | ||
99 | url: server.url, | ||
100 | path, | ||
101 | fields: omit(baseParams, 'errors') | ||
102 | }) | ||
103 | |||
104 | await makePostBodyRequest({ | ||
105 | url: server.url, | ||
106 | path, | ||
107 | fields: { ...baseParams, errors: 'toto' } | ||
108 | }) | ||
109 | }) | ||
110 | |||
111 | it('Should fail with an missing/invalid downloadedBytesP2P', async function () { | ||
112 | await makePostBodyRequest({ | ||
113 | url: server.url, | ||
114 | path, | ||
115 | fields: omit(baseParams, 'downloadedBytesP2P') | ||
116 | }) | ||
117 | |||
118 | await makePostBodyRequest({ | ||
119 | url: server.url, | ||
120 | path, | ||
121 | fields: { ...baseParams, downloadedBytesP2P: 'toto' } | ||
122 | }) | ||
123 | }) | ||
124 | |||
125 | it('Should fail with an missing/invalid downloadedBytesHTTP', async function () { | ||
126 | await makePostBodyRequest({ | ||
127 | url: server.url, | ||
128 | path, | ||
129 | fields: omit(baseParams, 'downloadedBytesHTTP') | ||
130 | }) | ||
131 | |||
132 | await makePostBodyRequest({ | ||
133 | url: server.url, | ||
134 | path, | ||
135 | fields: { ...baseParams, downloadedBytesHTTP: 'toto' } | ||
136 | }) | ||
137 | }) | ||
138 | |||
139 | it('Should fail with an missing/invalid uploadedBytesP2P', async function () { | ||
140 | await makePostBodyRequest({ | ||
141 | url: server.url, | ||
142 | path, | ||
143 | fields: omit(baseParams, 'uploadedBytesP2P') | ||
144 | }) | ||
145 | |||
146 | await makePostBodyRequest({ | ||
147 | url: server.url, | ||
148 | path, | ||
149 | fields: { ...baseParams, uploadedBytesP2P: 'toto' } | ||
150 | }) | ||
151 | }) | ||
152 | |||
153 | it('Should fail with a bad video id', async function () { | ||
154 | await makePostBodyRequest({ | ||
155 | url: server.url, | ||
156 | path, | ||
157 | fields: { ...baseParams, videoId: 'toto' } | ||
158 | }) | ||
159 | }) | ||
160 | |||
161 | it('Should fail with an unknown video', async function () { | ||
162 | await makePostBodyRequest({ | ||
163 | url: server.url, | ||
164 | path, | ||
165 | fields: { ...baseParams, videoId: 42 }, | ||
166 | expectedStatus: HttpStatusCode.NOT_FOUND_404 | ||
167 | }) | ||
168 | }) | ||
169 | |||
170 | it('Should succeed with the correct params', async function () { | ||
171 | await makePostBodyRequest({ | ||
172 | url: server.url, | ||
173 | path, | ||
174 | fields: baseParams, | ||
175 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
176 | }) | ||
177 | }) | ||
178 | }) | ||
179 | |||
180 | after(async function () { | ||
181 | await cleanupTests([ server ]) | ||
182 | }) | ||
183 | }) | ||
diff --git a/server/tests/api/server/open-telemetry.ts b/server/tests/api/server/open-telemetry.ts index 20909429f..3137a9eb6 100644 --- a/server/tests/api/server/open-telemetry.ts +++ b/server/tests/api/server/open-telemetry.ts | |||
@@ -2,14 +2,14 @@ | |||
2 | 2 | ||
3 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
4 | import { expectLogContain, expectLogDoesNotContain, MockHTTP } from '@server/tests/shared' | 4 | import { expectLogContain, expectLogDoesNotContain, MockHTTP } from '@server/tests/shared' |
5 | import { HttpStatusCode, VideoPrivacy } from '@shared/models' | 5 | import { HttpStatusCode, VideoPrivacy, VideoResolution } from '@shared/models' |
6 | import { cleanupTests, createSingleServer, makeRawRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' | 6 | import { cleanupTests, createSingleServer, makeRawRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' |
7 | 7 | ||
8 | describe('Open Telemetry', function () { | 8 | describe('Open Telemetry', function () { |
9 | let server: PeerTubeServer | 9 | let server: PeerTubeServer |
10 | 10 | ||
11 | describe('Metrics', function () { | 11 | describe('Metrics', function () { |
12 | const metricsUrl = 'http://localhost:9091/metrics' | 12 | const metricsUrl = 'http://localhost:9092/metrics' |
13 | 13 | ||
14 | it('Should not enable open telemetry metrics', async function () { | 14 | it('Should not enable open telemetry metrics', async function () { |
15 | server = await createSingleServer(1) | 15 | server = await createSingleServer(1) |
@@ -36,8 +36,33 @@ describe('Open Telemetry', function () { | |||
36 | }) | 36 | }) |
37 | 37 | ||
38 | const res = await makeRawRequest(metricsUrl, HttpStatusCode.OK_200) | 38 | const res = await makeRawRequest(metricsUrl, HttpStatusCode.OK_200) |
39 | expect(res.text).to.contain('peertube_job_queue_total') | 39 | expect(res.text).to.contain('peertube_job_queue_total{') |
40 | }) | ||
41 | |||
42 | it('Should have playback metrics', async function () { | ||
43 | await setAccessTokensToServers([ server ]) | ||
44 | |||
45 | const video = await server.videos.quickUpload({ name: 'video' }) | ||
46 | |||
47 | await server.metrics.addPlaybackMetric({ | ||
48 | metrics: { | ||
49 | playerMode: 'p2p-media-loader', | ||
50 | resolution: VideoResolution.H_1080P, | ||
51 | fps: 30, | ||
52 | resolutionChanges: 1, | ||
53 | errors: 2, | ||
54 | downloadedBytesP2P: 0, | ||
55 | downloadedBytesHTTP: 0, | ||
56 | uploadedBytesP2P: 5, | ||
57 | videoId: video.uuid | ||
58 | } | ||
59 | }) | ||
40 | 60 | ||
61 | const res = await makeRawRequest(metricsUrl, HttpStatusCode.OK_200) | ||
62 | expect(res.text).to.contain('peertube_playback_http_uploaded_bytes_total{') | ||
63 | }) | ||
64 | |||
65 | after(async function () { | ||
41 | await server.kill() | 66 | await server.kill() |
42 | }) | 67 | }) |
43 | }) | 68 | }) |