]>
Commit | Line | Data |
---|---|---|
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, VideoResolution } 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://127.0.0.1:9092/metrics' | |
13 | ||
14 | it('Should not enable open telemetry metrics', async function () { | |
15 | this.timeout(60000) | |
16 | ||
17 | server = await createSingleServer(1) | |
18 | ||
19 | let hasError = false | |
20 | try { | |
21 | await makeRawRequest({ url: metricsUrl, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | |
22 | } catch (err) { | |
23 | hasError = err.message.includes('ECONNREFUSED') | |
24 | } | |
25 | ||
26 | expect(hasError).to.be.true | |
27 | ||
28 | await server.kill() | |
29 | }) | |
30 | ||
31 | it('Should enable open telemetry metrics', async function () { | |
32 | this.timeout(120000) | |
33 | ||
34 | await server.run({ | |
35 | open_telemetry: { | |
36 | metrics: { | |
37 | enabled: true | |
38 | } | |
39 | } | |
40 | }) | |
41 | ||
42 | // Simulate a HTTP request | |
43 | await server.videos.list() | |
44 | ||
45 | const res = await makeRawRequest({ url: metricsUrl, expectedStatus: HttpStatusCode.OK_200 }) | |
46 | expect(res.text).to.contain('peertube_job_queue_total{') | |
47 | expect(res.text).to.contain('http_request_duration_ms_bucket{') | |
48 | }) | |
49 | ||
50 | it('Should have playback metrics', async function () { | |
51 | await setAccessTokensToServers([ server ]) | |
52 | ||
53 | const video = await server.videos.quickUpload({ name: 'video' }) | |
54 | ||
55 | await server.metrics.addPlaybackMetric({ | |
56 | metrics: { | |
57 | playerMode: 'p2p-media-loader', | |
58 | resolution: VideoResolution.H_1080P, | |
59 | fps: 30, | |
60 | resolutionChanges: 1, | |
61 | errors: 2, | |
62 | downloadedBytesP2P: 0, | |
63 | downloadedBytesHTTP: 0, | |
64 | uploadedBytesP2P: 5, | |
65 | videoId: video.uuid | |
66 | } | |
67 | }) | |
68 | ||
69 | const res = await makeRawRequest({ url: metricsUrl, expectedStatus: HttpStatusCode.OK_200 }) | |
70 | expect(res.text).to.contain('peertube_playback_http_downloaded_bytes_total{') | |
71 | }) | |
72 | ||
73 | it('Should disable http request duration metrics', async function () { | |
74 | await server.kill() | |
75 | ||
76 | await server.run({ | |
77 | open_telemetry: { | |
78 | metrics: { | |
79 | enabled: true, | |
80 | http_request_duration: { | |
81 | enabled: false | |
82 | } | |
83 | } | |
84 | } | |
85 | }) | |
86 | ||
87 | // Simulate a HTTP request | |
88 | await server.videos.list() | |
89 | ||
90 | const res = await makeRawRequest({ url: metricsUrl, expectedStatus: HttpStatusCode.OK_200 }) | |
91 | expect(res.text).to.not.contain('http_request_duration_ms_bucket{') | |
92 | }) | |
93 | ||
94 | after(async function () { | |
95 | await server.kill() | |
96 | }) | |
97 | }) | |
98 | ||
99 | describe('Tracing', function () { | |
100 | let mockHTTP: MockHTTP | |
101 | let mockPort: number | |
102 | ||
103 | before(async function () { | |
104 | mockHTTP = new MockHTTP() | |
105 | mockPort = await mockHTTP.initialize() | |
106 | }) | |
107 | ||
108 | it('Should enable open telemetry tracing', async function () { | |
109 | server = await createSingleServer(1) | |
110 | ||
111 | await expectLogDoesNotContain(server, 'Registering Open Telemetry tracing') | |
112 | ||
113 | await server.kill() | |
114 | }) | |
115 | ||
116 | it('Should enable open telemetry metrics', async function () { | |
117 | await server.run({ | |
118 | open_telemetry: { | |
119 | tracing: { | |
120 | enabled: true, | |
121 | jaeger_exporter: { | |
122 | endpoint: 'http://127.0.0.1:' + mockPort | |
123 | } | |
124 | } | |
125 | } | |
126 | }) | |
127 | ||
128 | await expectLogContain(server, 'Registering Open Telemetry tracing') | |
129 | }) | |
130 | ||
131 | it('Should upload a video and correctly works', async function () { | |
132 | await setAccessTokensToServers([ server ]) | |
133 | ||
134 | const { uuid } = await server.videos.quickUpload({ name: 'video', privacy: VideoPrivacy.PUBLIC }) | |
135 | ||
136 | const video = await server.videos.get({ id: uuid }) | |
137 | ||
138 | expect(video.name).to.equal('video') | |
139 | }) | |
140 | ||
141 | after(async function () { | |
142 | await mockHTTP.terminate() | |
143 | }) | |
144 | }) | |
145 | ||
146 | after(async function () { | |
147 | await cleanupTests([ server ]) | |
148 | }) | |
149 | }) |