diff options
author | Chocobozzz <me@florianbigard.com> | 2022-07-05 15:43:21 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-07-06 15:13:55 +0200 |
commit | 630d0a1bf5897fff203cb07e426223f55dcc882d (patch) | |
tree | 5e6fa9d26f3f21178a538bd1ac38fa0a3f4f228c /server/tests | |
parent | 15b43b214eb37b05aa65aa8ef61fd0e6aa0b62d2 (diff) | |
download | PeerTube-630d0a1bf5897fff203cb07e426223f55dcc882d.tar.gz PeerTube-630d0a1bf5897fff203cb07e426223f55dcc882d.tar.zst PeerTube-630d0a1bf5897fff203cb07e426223f55dcc882d.zip |
Introduce experimental telemetry
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/server/index.ts | 1 | ||||
-rw-r--r-- | server/tests/api/server/no-client.ts | 3 | ||||
-rw-r--r-- | server/tests/api/server/open-telemetry.ts | 95 | ||||
-rw-r--r-- | server/tests/shared/checks.ts | 9 | ||||
-rw-r--r-- | server/tests/shared/mock-servers/index.ts | 1 | ||||
-rw-r--r-- | server/tests/shared/mock-servers/mock-http.ts | 23 |
6 files changed, 129 insertions, 3 deletions
diff --git a/server/tests/api/server/index.ts b/server/tests/api/server/index.ts index 45be107ce..78522c246 100644 --- a/server/tests/api/server/index.ts +++ b/server/tests/api/server/index.ts | |||
@@ -17,5 +17,6 @@ import './slow-follows' | |||
17 | import './stats' | 17 | import './stats' |
18 | import './tracker' | 18 | import './tracker' |
19 | import './no-client' | 19 | import './no-client' |
20 | import './open-telemetry' | ||
20 | import './plugins' | 21 | import './plugins' |
21 | import './proxy' | 22 | import './proxy' |
diff --git a/server/tests/api/server/no-client.ts b/server/tests/api/server/no-client.ts index 913907788..193f6c987 100644 --- a/server/tests/api/server/no-client.ts +++ b/server/tests/api/server/no-client.ts | |||
@@ -1,7 +1,6 @@ | |||
1 | import 'mocha' | ||
2 | import request from 'supertest' | 1 | import request from 'supertest' |
3 | import { cleanupTests, createSingleServer, PeerTubeServer } from '@shared/server-commands' | ||
4 | import { HttpStatusCode } from '@shared/models' | 2 | import { HttpStatusCode } from '@shared/models' |
3 | import { cleanupTests, createSingleServer, PeerTubeServer } from '@shared/server-commands' | ||
5 | 4 | ||
6 | describe('Start and stop server without web client routes', function () { | 5 | describe('Start and stop server without web client routes', function () { |
7 | let server: PeerTubeServer | 6 | let server: PeerTubeServer |
diff --git a/server/tests/api/server/open-telemetry.ts b/server/tests/api/server/open-telemetry.ts new file mode 100644 index 000000000..20909429f --- /dev/null +++ b/server/tests/api/server/open-telemetry.ts | |||
@@ -0,0 +1,95 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { expectLogContain, expectLogDoesNotContain, MockHTTP } from '@server/tests/shared' | ||
5 | import { HttpStatusCode, VideoPrivacy } from '@shared/models' | ||
6 | import { cleanupTests, createSingleServer, makeRawRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' | ||
7 | |||
8 | describe('Open Telemetry', function () { | ||
9 | let server: PeerTubeServer | ||
10 | |||
11 | describe('Metrics', function () { | ||
12 | const metricsUrl = 'http://localhost:9091/metrics' | ||
13 | |||
14 | it('Should not enable open telemetry metrics', async function () { | ||
15 | server = await createSingleServer(1) | ||
16 | |||
17 | let hasError = false | ||
18 | try { | ||
19 | await makeRawRequest(metricsUrl, HttpStatusCode.NOT_FOUND_404) | ||
20 | } catch (err) { | ||
21 | hasError = err.message.includes('ECONNREFUSED') | ||
22 | } | ||
23 | |||
24 | expect(hasError).to.be.true | ||
25 | |||
26 | await server.kill() | ||
27 | }) | ||
28 | |||
29 | it('Should enable open telemetry metrics', async function () { | ||
30 | server = await createSingleServer(1, { | ||
31 | open_telemetry: { | ||
32 | metrics: { | ||
33 | enabled: true | ||
34 | } | ||
35 | } | ||
36 | }) | ||
37 | |||
38 | const res = await makeRawRequest(metricsUrl, HttpStatusCode.OK_200) | ||
39 | expect(res.text).to.contain('peertube_job_queue_total') | ||
40 | |||
41 | await server.kill() | ||
42 | }) | ||
43 | }) | ||
44 | |||
45 | describe('Tracing', function () { | ||
46 | let mockHTTP: MockHTTP | ||
47 | let mockPort: number | ||
48 | |||
49 | before(async function () { | ||
50 | mockHTTP = new MockHTTP() | ||
51 | mockPort = await mockHTTP.initialize() | ||
52 | }) | ||
53 | |||
54 | it('Should enable open telemetry tracing', async function () { | ||
55 | server = await createSingleServer(1) | ||
56 | |||
57 | await expectLogDoesNotContain(server, 'Registering Open Telemetry tracing') | ||
58 | |||
59 | await server.kill() | ||
60 | }) | ||
61 | |||
62 | it('Should enable open telemetry metrics', async function () { | ||
63 | server = await createSingleServer(1, { | ||
64 | open_telemetry: { | ||
65 | tracing: { | ||
66 | enabled: true, | ||
67 | jaeger_exporter: { | ||
68 | endpoint: 'http://localhost:' + mockPort | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | }) | ||
73 | |||
74 | await expectLogContain(server, 'Registering Open Telemetry tracing') | ||
75 | }) | ||
76 | |||
77 | it('Should upload a video and correctly works', async function () { | ||
78 | await setAccessTokensToServers([ server ]) | ||
79 | |||
80 | const { uuid } = await server.videos.quickUpload({ name: 'video', privacy: VideoPrivacy.PUBLIC }) | ||
81 | |||
82 | const video = await server.videos.get({ id: uuid }) | ||
83 | |||
84 | expect(video.name).to.equal('video') | ||
85 | }) | ||
86 | |||
87 | after(async function () { | ||
88 | await mockHTTP.terminate() | ||
89 | }) | ||
90 | }) | ||
91 | |||
92 | after(async function () { | ||
93 | await cleanupTests([ server ]) | ||
94 | }) | ||
95 | }) | ||
diff --git a/server/tests/shared/checks.ts b/server/tests/shared/checks.ts index 33b917f31..55ebc6c3e 100644 --- a/server/tests/shared/checks.ts +++ b/server/tests/shared/checks.ts | |||
@@ -29,6 +29,12 @@ async function expectLogDoesNotContain (server: PeerTubeServer, str: string) { | |||
29 | expect(content.toString()).to.not.contain(str) | 29 | expect(content.toString()).to.not.contain(str) |
30 | } | 30 | } |
31 | 31 | ||
32 | async function expectLogContain (server: PeerTubeServer, str: string) { | ||
33 | const content = await server.servers.getLogContent() | ||
34 | |||
35 | expect(content.toString()).to.contain(str) | ||
36 | } | ||
37 | |||
32 | async function testImage (url: string, imageName: string, imageHTTPPath: string, extension = '.jpg') { | 38 | async function testImage (url: string, imageName: string, imageHTTPPath: string, extension = '.jpg') { |
33 | const res = await makeGetRequest({ | 39 | const res = await makeGetRequest({ |
34 | url, | 40 | url, |
@@ -99,5 +105,6 @@ export { | |||
99 | expectNotStartWith, | 105 | expectNotStartWith, |
100 | checkBadStartPagination, | 106 | checkBadStartPagination, |
101 | checkBadCountPagination, | 107 | checkBadCountPagination, |
102 | checkBadSortPagination | 108 | checkBadSortPagination, |
109 | expectLogContain | ||
103 | } | 110 | } |
diff --git a/server/tests/shared/mock-servers/index.ts b/server/tests/shared/mock-servers/index.ts index abf4a8203..1fa983116 100644 --- a/server/tests/shared/mock-servers/index.ts +++ b/server/tests/shared/mock-servers/index.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | export * from './mock-429' | 1 | export * from './mock-429' |
2 | export * from './mock-email' | 2 | export * from './mock-email' |
3 | export * from './mock-http' | ||
3 | export * from './mock-instances-index' | 4 | export * from './mock-instances-index' |
4 | export * from './mock-joinpeertube-versions' | 5 | export * from './mock-joinpeertube-versions' |
5 | export * from './mock-object-storage' | 6 | export * from './mock-object-storage' |
diff --git a/server/tests/shared/mock-servers/mock-http.ts b/server/tests/shared/mock-servers/mock-http.ts new file mode 100644 index 000000000..b7a019e07 --- /dev/null +++ b/server/tests/shared/mock-servers/mock-http.ts | |||
@@ -0,0 +1,23 @@ | |||
1 | import express from 'express' | ||
2 | import { Server } from 'http' | ||
3 | import { getPort, randomListen, terminateServer } from './shared' | ||
4 | |||
5 | export class MockHTTP { | ||
6 | private server: Server | ||
7 | |||
8 | async initialize () { | ||
9 | const app = express() | ||
10 | |||
11 | app.get('/*', (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
12 | return res.sendStatus(200) | ||
13 | }) | ||
14 | |||
15 | this.server = await randomListen(app) | ||
16 | |||
17 | return getPort(this.server) | ||
18 | } | ||
19 | |||
20 | terminate () { | ||
21 | return terminateServer(this.server) | ||
22 | } | ||
23 | } | ||