diff options
-rw-r--r-- | server/tests/api/redundancy/redundancy.ts | 15 | ||||
-rw-r--r-- | server/tests/api/server/stats.ts | 63 | ||||
-rw-r--r-- | shared/extra-utils/index.ts | 4 | ||||
-rw-r--r-- | shared/extra-utils/server/index.ts | 3 | ||||
-rw-r--r-- | shared/extra-utils/server/servers.ts | 3 | ||||
-rw-r--r-- | shared/extra-utils/server/stats-command.ts | 25 | ||||
-rw-r--r-- | shared/extra-utils/server/stats.ts | 23 |
7 files changed, 58 insertions, 78 deletions
diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 5b970473c..e4ea99de6 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts | |||
@@ -5,7 +5,6 @@ import * as chai from 'chai' | |||
5 | import { readdir } from 'fs-extra' | 5 | import { readdir } from 'fs-extra' |
6 | import * as magnetUtil from 'magnet-uri' | 6 | import * as magnetUtil from 'magnet-uri' |
7 | import { join } from 'path' | 7 | import { join } from 'path' |
8 | import { removeVideoRedundancy } from '@server/lib/redundancy' | ||
9 | import { HttpStatusCode } from '@shared/core-utils' | 8 | import { HttpStatusCode } from '@shared/core-utils' |
10 | import { | 9 | import { |
11 | checkSegmentHash, | 10 | checkSegmentHash, |
@@ -30,15 +29,7 @@ import { | |||
30 | waitJobs, | 29 | waitJobs, |
31 | waitUntilLog | 30 | waitUntilLog |
32 | } from '@shared/extra-utils' | 31 | } from '@shared/extra-utils' |
33 | import { getStats } from '@shared/extra-utils/server/stats' | 32 | import { VideoDetails, VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models' |
34 | import { | ||
35 | ServerStats, | ||
36 | VideoDetails, | ||
37 | VideoPrivacy, | ||
38 | VideoRedundancy, | ||
39 | VideoRedundancyStrategy, | ||
40 | VideoRedundancyStrategyWithManual | ||
41 | } from '@shared/models' | ||
42 | 33 | ||
43 | const expect = chai.expect | 34 | const expect = chai.expect |
44 | 35 | ||
@@ -241,9 +232,7 @@ async function checkStatsGlobal (strategy: VideoRedundancyStrategyWithManual) { | |||
241 | statsLength = 2 | 232 | statsLength = 2 |
242 | } | 233 | } |
243 | 234 | ||
244 | const res = await getStats(servers[0].url) | 235 | const data = await servers[0].statsCommand.get() |
245 | const data: ServerStats = res.body | ||
246 | |||
247 | expect(data.videosRedundancy).to.have.lengthOf(statsLength) | 236 | expect(data.videosRedundancy).to.have.lengthOf(statsLength) |
248 | 237 | ||
249 | const stat = data.videosRedundancy[0] | 238 | const stat = data.videosRedundancy[0] |
diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts index f609ea725..36114a297 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts | |||
@@ -19,8 +19,7 @@ import { | |||
19 | wait, | 19 | wait, |
20 | waitJobs | 20 | waitJobs |
21 | } from '@shared/extra-utils' | 21 | } from '@shared/extra-utils' |
22 | import { getStats } from '@shared/extra-utils/server/stats' | 22 | import { ActivityType, VideoPlaylistPrivacy } from '@shared/models' |
23 | import { ActivityType, ServerStats, VideoPlaylistPrivacy } from '@shared/models' | ||
24 | 23 | ||
25 | const expect = chai.expect | 24 | const expect = chai.expect |
26 | 25 | ||
@@ -58,8 +57,7 @@ describe('Test stats (excluding redundancy)', function () { | |||
58 | }) | 57 | }) |
59 | 58 | ||
60 | it('Should have the correct stats on instance 1', async function () { | 59 | it('Should have the correct stats on instance 1', async function () { |
61 | const res = await getStats(servers[0].url) | 60 | const data = await servers[0].statsCommand.get() |
62 | const data: ServerStats = res.body | ||
63 | 61 | ||
64 | expect(data.totalLocalVideoComments).to.equal(1) | 62 | expect(data.totalLocalVideoComments).to.equal(1) |
65 | expect(data.totalLocalVideos).to.equal(1) | 63 | expect(data.totalLocalVideos).to.equal(1) |
@@ -74,8 +72,7 @@ describe('Test stats (excluding redundancy)', function () { | |||
74 | }) | 72 | }) |
75 | 73 | ||
76 | it('Should have the correct stats on instance 2', async function () { | 74 | it('Should have the correct stats on instance 2', async function () { |
77 | const res = await getStats(servers[1].url) | 75 | const data = await servers[1].statsCommand.get() |
78 | const data: ServerStats = res.body | ||
79 | 76 | ||
80 | expect(data.totalLocalVideoComments).to.equal(0) | 77 | expect(data.totalLocalVideoComments).to.equal(0) |
81 | expect(data.totalLocalVideos).to.equal(0) | 78 | expect(data.totalLocalVideos).to.equal(0) |
@@ -90,8 +87,7 @@ describe('Test stats (excluding redundancy)', function () { | |||
90 | }) | 87 | }) |
91 | 88 | ||
92 | it('Should have the correct stats on instance 3', async function () { | 89 | it('Should have the correct stats on instance 3', async function () { |
93 | const res = await getStats(servers[2].url) | 90 | const data = await servers[2].statsCommand.get() |
94 | const data: ServerStats = res.body | ||
95 | 91 | ||
96 | expect(data.totalLocalVideoComments).to.equal(0) | 92 | expect(data.totalLocalVideoComments).to.equal(0) |
97 | expect(data.totalLocalVideos).to.equal(0) | 93 | expect(data.totalLocalVideos).to.equal(0) |
@@ -110,8 +106,7 @@ describe('Test stats (excluding redundancy)', function () { | |||
110 | await servers[2].followsCommand.unfollow({ target: servers[0] }) | 106 | await servers[2].followsCommand.unfollow({ target: servers[0] }) |
111 | await waitJobs(servers) | 107 | await waitJobs(servers) |
112 | 108 | ||
113 | const res = await getStats(servers[2].url) | 109 | const data = await servers[2].statsCommand.get() |
114 | const data: ServerStats = res.body | ||
115 | 110 | ||
116 | expect(data.totalVideos).to.equal(0) | 111 | expect(data.totalVideos).to.equal(0) |
117 | }) | 112 | }) |
@@ -120,8 +115,8 @@ describe('Test stats (excluding redundancy)', function () { | |||
120 | const server = servers[0] | 115 | const server = servers[0] |
121 | 116 | ||
122 | { | 117 | { |
123 | const res = await getStats(server.url) | 118 | const data = await server.statsCommand.get() |
124 | const data: ServerStats = res.body | 119 | |
125 | expect(data.totalDailyActiveUsers).to.equal(1) | 120 | expect(data.totalDailyActiveUsers).to.equal(1) |
126 | expect(data.totalWeeklyActiveUsers).to.equal(1) | 121 | expect(data.totalWeeklyActiveUsers).to.equal(1) |
127 | expect(data.totalMonthlyActiveUsers).to.equal(1) | 122 | expect(data.totalMonthlyActiveUsers).to.equal(1) |
@@ -130,8 +125,8 @@ describe('Test stats (excluding redundancy)', function () { | |||
130 | { | 125 | { |
131 | await userLogin(server, user) | 126 | await userLogin(server, user) |
132 | 127 | ||
133 | const res = await getStats(server.url) | 128 | const data = await server.statsCommand.get() |
134 | const data: ServerStats = res.body | 129 | |
135 | expect(data.totalDailyActiveUsers).to.equal(2) | 130 | expect(data.totalDailyActiveUsers).to.equal(2) |
136 | expect(data.totalWeeklyActiveUsers).to.equal(2) | 131 | expect(data.totalWeeklyActiveUsers).to.equal(2) |
137 | expect(data.totalMonthlyActiveUsers).to.equal(2) | 132 | expect(data.totalMonthlyActiveUsers).to.equal(2) |
@@ -142,8 +137,8 @@ describe('Test stats (excluding redundancy)', function () { | |||
142 | const server = servers[0] | 137 | const server = servers[0] |
143 | 138 | ||
144 | { | 139 | { |
145 | const res = await getStats(server.url) | 140 | const data = await server.statsCommand.get() |
146 | const data: ServerStats = res.body | 141 | |
147 | expect(data.totalLocalDailyActiveVideoChannels).to.equal(1) | 142 | expect(data.totalLocalDailyActiveVideoChannels).to.equal(1) |
148 | expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1) | 143 | expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1) |
149 | expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(1) | 144 | expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(1) |
@@ -157,8 +152,8 @@ describe('Test stats (excluding redundancy)', function () { | |||
157 | const resChannel = await addVideoChannel(server.url, server.accessToken, channelAttributes) | 152 | const resChannel = await addVideoChannel(server.url, server.accessToken, channelAttributes) |
158 | channelId = resChannel.body.videoChannel.id | 153 | channelId = resChannel.body.videoChannel.id |
159 | 154 | ||
160 | const res = await getStats(server.url) | 155 | const data = await server.statsCommand.get() |
161 | const data: ServerStats = res.body | 156 | |
162 | expect(data.totalLocalDailyActiveVideoChannels).to.equal(1) | 157 | expect(data.totalLocalDailyActiveVideoChannels).to.equal(1) |
163 | expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1) | 158 | expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1) |
164 | expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(1) | 159 | expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(1) |
@@ -167,8 +162,8 @@ describe('Test stats (excluding redundancy)', function () { | |||
167 | { | 162 | { |
168 | await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.webm', channelId }) | 163 | await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.webm', channelId }) |
169 | 164 | ||
170 | const res = await getStats(server.url) | 165 | const data = await server.statsCommand.get() |
171 | const data: ServerStats = res.body | 166 | |
172 | expect(data.totalLocalDailyActiveVideoChannels).to.equal(2) | 167 | expect(data.totalLocalDailyActiveVideoChannels).to.equal(2) |
173 | expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(2) | 168 | expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(2) |
174 | expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(2) | 169 | expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(2) |
@@ -179,9 +174,8 @@ describe('Test stats (excluding redundancy)', function () { | |||
179 | const server = servers[0] | 174 | const server = servers[0] |
180 | 175 | ||
181 | { | 176 | { |
182 | const resStats = await getStats(server.url) | 177 | const data = await server.statsCommand.get() |
183 | const dataStats: ServerStats = resStats.body | 178 | expect(data.totalLocalPlaylists).to.equal(0) |
184 | expect(dataStats.totalLocalPlaylists).to.equal(0) | ||
185 | } | 179 | } |
186 | 180 | ||
187 | { | 181 | { |
@@ -195,9 +189,8 @@ describe('Test stats (excluding redundancy)', function () { | |||
195 | } | 189 | } |
196 | }) | 190 | }) |
197 | 191 | ||
198 | const resStats = await getStats(server.url) | 192 | const data = await server.statsCommand.get() |
199 | const dataStats: ServerStats = resStats.body | 193 | expect(data.totalLocalPlaylists).to.equal(1) |
200 | expect(dataStats.totalLocalPlaylists).to.equal(1) | ||
201 | } | 194 | } |
202 | }) | 195 | }) |
203 | 196 | ||
@@ -231,14 +224,12 @@ describe('Test stats (excluding redundancy)', function () { | |||
231 | await waitJobs(servers) | 224 | await waitJobs(servers) |
232 | 225 | ||
233 | { | 226 | { |
234 | const res = await getStats(servers[1].url) | 227 | const data = await servers[1].statsCommand.get() |
235 | const data: ServerStats = res.body | ||
236 | expect(data.totalLocalVideoFilesSize).to.equal(0) | 228 | expect(data.totalLocalVideoFilesSize).to.equal(0) |
237 | } | 229 | } |
238 | 230 | ||
239 | { | 231 | { |
240 | const res = await getStats(servers[0].url) | 232 | const data = await servers[0].statsCommand.get() |
241 | const data: ServerStats = res.body | ||
242 | expect(data.totalLocalVideoFilesSize).to.be.greaterThan(500000) | 233 | expect(data.totalLocalVideoFilesSize).to.be.greaterThan(500000) |
243 | expect(data.totalLocalVideoFilesSize).to.be.lessThan(600000) | 234 | expect(data.totalLocalVideoFilesSize).to.be.lessThan(600000) |
244 | } | 235 | } |
@@ -253,8 +244,7 @@ describe('Test stats (excluding redundancy)', function () { | |||
253 | } | 244 | } |
254 | }) | 245 | }) |
255 | 246 | ||
256 | const res1 = await getStats(servers[1].url) | 247 | const first = await servers[1].statsCommand.get() |
257 | const first = res1.body as ServerStats | ||
258 | 248 | ||
259 | for (let i = 0; i < 10; i++) { | 249 | for (let i = 0; i < 10; i++) { |
260 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) | 250 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) |
@@ -264,10 +254,9 @@ describe('Test stats (excluding redundancy)', function () { | |||
264 | 254 | ||
265 | await wait(6000) | 255 | await wait(6000) |
266 | 256 | ||
267 | const res2 = await getStats(servers[1].url) | 257 | const second = await servers[1].statsCommand.get() |
268 | const second: ServerStats = res2.body | ||
269 | |||
270 | expect(second.totalActivityPubMessagesProcessed).to.be.greaterThan(first.totalActivityPubMessagesProcessed) | 258 | expect(second.totalActivityPubMessagesProcessed).to.be.greaterThan(first.totalActivityPubMessagesProcessed) |
259 | |||
271 | const apTypes: ActivityType[] = [ | 260 | const apTypes: ActivityType[] = [ |
272 | 'Create', 'Update', 'Delete', 'Follow', 'Accept', 'Announce', 'Undo', 'Like', 'Reject', 'View', 'Dislike', 'Flag' | 261 | 'Create', 'Update', 'Delete', 'Follow', 'Accept', 'Announce', 'Undo', 'Like', 'Reject', 'View', 'Dislike', 'Flag' |
273 | ] | 262 | ] |
@@ -287,9 +276,7 @@ describe('Test stats (excluding redundancy)', function () { | |||
287 | 276 | ||
288 | await wait(6000) | 277 | await wait(6000) |
289 | 278 | ||
290 | const res3 = await getStats(servers[1].url) | 279 | const third = await servers[1].statsCommand.get() |
291 | const third: ServerStats = res3.body | ||
292 | |||
293 | expect(third.totalActivityPubMessagesWaiting).to.equal(0) | 280 | expect(third.totalActivityPubMessagesWaiting).to.equal(0) |
294 | expect(third.activityPubMessagesProcessedPerSecond).to.be.lessThan(second.activityPubMessagesProcessedPerSecond) | 281 | expect(third.activityPubMessagesProcessedPerSecond).to.be.lessThan(second.activityPubMessagesProcessedPerSecond) |
295 | }) | 282 | }) |
diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index cf6418249..f69d7241e 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts | |||
@@ -13,10 +13,6 @@ export * from './server' | |||
13 | export * from './requests/check-api-params' | 13 | export * from './requests/check-api-params' |
14 | export * from './requests/requests' | 14 | export * from './requests/requests' |
15 | 15 | ||
16 | export * from './server/clients' | ||
17 | export * from './server/config' | ||
18 | export * from './server/servers' | ||
19 | |||
20 | export * from './users/accounts' | 16 | export * from './users/accounts' |
21 | export * from './users/blocklist' | 17 | export * from './users/blocklist' |
22 | export * from './users/login' | 18 | export * from './users/login' |
diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts index 3ee70f0cf..d37f46321 100644 --- a/shared/extra-utils/server/index.ts +++ b/shared/extra-utils/server/index.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | export * from './config' | ||
1 | export * from './contact-form-command' | 2 | export * from './contact-form-command' |
2 | export * from './debug-command' | 3 | export * from './debug-command' |
3 | export * from './follows-command' | 4 | export * from './follows-command' |
@@ -7,3 +8,5 @@ export * from './jobs-command' | |||
7 | export * from './plugins-command' | 8 | export * from './plugins-command' |
8 | export * from './plugins' | 9 | export * from './plugins' |
9 | export * from './redundancy-command' | 10 | export * from './redundancy-command' |
11 | export * from './servers' | ||
12 | export * from './stats-command' | ||
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index eaf39ecea..4603cf62e 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts | |||
@@ -22,6 +22,7 @@ import { FollowsCommand } from './follows-command' | |||
22 | import { JobsCommand } from './jobs-command' | 22 | import { JobsCommand } from './jobs-command' |
23 | import { PluginsCommand } from './plugins-command' | 23 | import { PluginsCommand } from './plugins-command' |
24 | import { RedundancyCommand } from './redundancy-command' | 24 | import { RedundancyCommand } from './redundancy-command' |
25 | import { StatsCommand } from './stats-command' | ||
25 | 26 | ||
26 | interface ServerInfo { | 27 | interface ServerInfo { |
27 | app: ChildProcess | 28 | app: ChildProcess |
@@ -89,6 +90,7 @@ interface ServerInfo { | |||
89 | jobsCommand?: JobsCommand | 90 | jobsCommand?: JobsCommand |
90 | pluginsCommand?: PluginsCommand | 91 | pluginsCommand?: PluginsCommand |
91 | redundancyCommand?: RedundancyCommand | 92 | redundancyCommand?: RedundancyCommand |
93 | statsCommand?: StatsCommand | ||
92 | } | 94 | } |
93 | 95 | ||
94 | function parallelTests () { | 96 | function parallelTests () { |
@@ -308,6 +310,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] | |||
308 | server.jobsCommand = new JobsCommand(server) | 310 | server.jobsCommand = new JobsCommand(server) |
309 | server.pluginsCommand = new PluginsCommand(server) | 311 | server.pluginsCommand = new PluginsCommand(server) |
310 | server.redundancyCommand = new RedundancyCommand(server) | 312 | server.redundancyCommand = new RedundancyCommand(server) |
313 | server.statsCommand = new StatsCommand(server) | ||
311 | 314 | ||
312 | res(server) | 315 | res(server) |
313 | }) | 316 | }) |
diff --git a/shared/extra-utils/server/stats-command.ts b/shared/extra-utils/server/stats-command.ts new file mode 100644 index 000000000..b51d9ceef --- /dev/null +++ b/shared/extra-utils/server/stats-command.ts | |||
@@ -0,0 +1,25 @@ | |||
1 | import { ServerStats } from '@shared/models' | ||
2 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | export class StatsCommand extends AbstractCommand { | ||
6 | |||
7 | get (options: OverrideCommandOptions & { | ||
8 | useCache?: boolean // default false | ||
9 | } = {}) { | ||
10 | const { useCache = false } = options | ||
11 | const path = '/api/v1/server/stats' | ||
12 | |||
13 | const query = { | ||
14 | t: useCache ? undefined : new Date().getTime() | ||
15 | } | ||
16 | |||
17 | return this.getRequestBody<ServerStats>({ | ||
18 | ...options, | ||
19 | |||
20 | path, | ||
21 | query, | ||
22 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
23 | }) | ||
24 | } | ||
25 | } | ||
diff --git a/shared/extra-utils/server/stats.ts b/shared/extra-utils/server/stats.ts deleted file mode 100644 index b9dae24e2..000000000 --- a/shared/extra-utils/server/stats.ts +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | import { makeGetRequest } from '../requests/requests' | ||
2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
3 | |||
4 | function getStats (url: string, useCache = false) { | ||
5 | const path = '/api/v1/server/stats' | ||
6 | |||
7 | const query = { | ||
8 | t: useCache ? undefined : new Date().getTime() | ||
9 | } | ||
10 | |||
11 | return makeGetRequest({ | ||
12 | url, | ||
13 | path, | ||
14 | query, | ||
15 | statusCodeExpected: HttpStatusCode.OK_200 | ||
16 | }) | ||
17 | } | ||
18 | |||
19 | // --------------------------------------------------------------------------- | ||
20 | |||
21 | export { | ||
22 | getStats | ||
23 | } | ||