diff options
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/check-params/metrics.ts | 11 | ||||
-rw-r--r-- | server/tests/api/server/open-telemetry.ts | 39 |
2 files changed, 46 insertions, 4 deletions
diff --git a/server/tests/api/check-params/metrics.ts b/server/tests/api/check-params/metrics.ts index 25443401d..302bef4f5 100644 --- a/server/tests/api/check-params/metrics.ts +++ b/server/tests/api/check-params/metrics.ts | |||
@@ -38,6 +38,7 @@ describe('Test metrics API validators', function () { | |||
38 | fps: 30, | 38 | fps: 30, |
39 | resolutionChanges: 1, | 39 | resolutionChanges: 1, |
40 | errors: 2, | 40 | errors: 2, |
41 | p2pEnabled: true, | ||
41 | downloadedBytesP2P: 0, | 42 | downloadedBytesP2P: 0, |
42 | downloadedBytesHTTP: 0, | 43 | downloadedBytesHTTP: 0, |
43 | uploadedBytesP2P: 0, | 44 | uploadedBytesP2P: 0, |
@@ -145,7 +146,13 @@ describe('Test metrics API validators', function () { | |||
145 | }) | 146 | }) |
146 | }) | 147 | }) |
147 | 148 | ||
148 | it('Should fail with an invalid p2pEnabled', async function () { | 149 | it('Should fail with a missing/invalid p2pEnabled', async function () { |
150 | await makePostBodyRequest({ | ||
151 | url: server.url, | ||
152 | path, | ||
153 | fields: omit(baseParams, [ 'p2pEnabled' ]) | ||
154 | }) | ||
155 | |||
149 | await makePostBodyRequest({ | 156 | await makePostBodyRequest({ |
150 | url: server.url, | 157 | url: server.url, |
151 | path, | 158 | path, |
@@ -157,7 +164,7 @@ describe('Test metrics API validators', function () { | |||
157 | await makePostBodyRequest({ | 164 | await makePostBodyRequest({ |
158 | url: server.url, | 165 | url: server.url, |
159 | path, | 166 | path, |
160 | fields: { ...baseParams, totalPeers: 'toto' } | 167 | fields: { ...baseParams, p2pPeers: 'toto' } |
161 | }) | 168 | }) |
162 | }) | 169 | }) |
163 | 170 | ||
diff --git a/server/tests/api/server/open-telemetry.ts b/server/tests/api/server/open-telemetry.ts index 0bd0b5e86..508e9d649 100644 --- a/server/tests/api/server/open-telemetry.ts +++ b/server/tests/api/server/open-telemetry.ts | |||
@@ -2,7 +2,7 @@ | |||
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, VideoResolution } from '@shared/models' | 5 | import { HttpStatusCode, PlaybackMetricCreate, 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 () { |
@@ -62,14 +62,49 @@ 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, | 65 | p2pPeers: 1, |
66 | p2pEnabled: false, | 66 | p2pEnabled: false, |
67 | videoId: video.uuid | 67 | videoId: video.uuid |
68 | } | 68 | } |
69 | }) | 69 | }) |
70 | 70 | ||
71 | const res = await makeRawRequest({ url: metricsUrl, expectedStatus: HttpStatusCode.OK_200 }) | 71 | const res = await makeRawRequest({ url: metricsUrl, expectedStatus: HttpStatusCode.OK_200 }) |
72 | |||
72 | expect(res.text).to.contain('peertube_playback_http_downloaded_bytes_total{') | 73 | expect(res.text).to.contain('peertube_playback_http_downloaded_bytes_total{') |
74 | expect(res.text).to.contain('peertube_playback_p2p_peers{') | ||
75 | expect(res.text).to.contain('p2pEnabled="false"') | ||
76 | }) | ||
77 | |||
78 | it('Should take the last playback metric', async function () { | ||
79 | await setAccessTokensToServers([ server ]) | ||
80 | |||
81 | const video = await server.videos.quickUpload({ name: 'video' }) | ||
82 | |||
83 | const metrics = { | ||
84 | playerMode: 'p2p-media-loader', | ||
85 | resolution: VideoResolution.H_1080P, | ||
86 | fps: 30, | ||
87 | resolutionChanges: 1, | ||
88 | errors: 2, | ||
89 | downloadedBytesP2P: 0, | ||
90 | downloadedBytesHTTP: 0, | ||
91 | uploadedBytesP2P: 5, | ||
92 | p2pPeers: 7, | ||
93 | p2pEnabled: false, | ||
94 | videoId: video.uuid | ||
95 | } as PlaybackMetricCreate | ||
96 | |||
97 | await server.metrics.addPlaybackMetric({ metrics }) | ||
98 | |||
99 | metrics.p2pPeers = 42 | ||
100 | await server.metrics.addPlaybackMetric({ metrics }) | ||
101 | |||
102 | const res = await makeRawRequest({ url: metricsUrl, expectedStatus: HttpStatusCode.OK_200 }) | ||
103 | |||
104 | // eslint-disable-next-line max-len | ||
105 | const label = `{videoOrigin="local",playerMode="p2p-media-loader",resolution="1080",fps="30",p2pEnabled="false",videoUUID="${video.uuid}"}` | ||
106 | expect(res.text).to.contain(`peertube_playback_p2p_peers${label} 42`) | ||
107 | expect(res.text).to.not.contain(`peertube_playback_p2p_peers${label} 7`) | ||
73 | }) | 108 | }) |
74 | 109 | ||
75 | it('Should disable http request duration metrics', async function () { | 110 | it('Should disable http request duration metrics', async function () { |