1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import { expect } from 'chai'
import { expectLogContain, expectLogDoesNotContain, MockHTTP } from '@server/tests/shared'
import { HttpStatusCode, VideoPrivacy, VideoResolution } from '@shared/models'
import { cleanupTests, createSingleServer, makeRawRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
describe('Open Telemetry', function () {
let server: PeerTubeServer
describe('Metrics', function () {
const metricsUrl = 'http://127.0.0.1:9092/metrics'
it('Should not enable open telemetry metrics', async function () {
this.timeout(60000)
server = await createSingleServer(1)
let hasError = false
try {
await makeRawRequest({ url: metricsUrl, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
} catch (err) {
hasError = err.message.includes('ECONNREFUSED')
}
expect(hasError).to.be.true
await server.kill()
})
it('Should enable open telemetry metrics', async function () {
server = await createSingleServer(1, {
open_telemetry: {
metrics: {
enabled: true
}
}
})
const res = await makeRawRequest({ url: metricsUrl, expectedStatus: HttpStatusCode.OK_200 })
expect(res.text).to.contain('peertube_job_queue_total{')
})
it('Should have playback metrics', async function () {
await setAccessTokensToServers([ server ])
const video = await server.videos.quickUpload({ name: 'video' })
await server.metrics.addPlaybackMetric({
metrics: {
playerMode: 'p2p-media-loader',
resolution: VideoResolution.H_1080P,
fps: 30,
resolutionChanges: 1,
errors: 2,
downloadedBytesP2P: 0,
downloadedBytesHTTP: 0,
uploadedBytesP2P: 5,
videoId: video.uuid
}
})
const res = await makeRawRequest({ url: metricsUrl, expectedStatus: HttpStatusCode.OK_200 })
expect(res.text).to.contain('peertube_playback_http_downloaded_bytes_total{')
})
after(async function () {
await server.kill()
})
})
describe('Tracing', function () {
let mockHTTP: MockHTTP
let mockPort: number
before(async function () {
mockHTTP = new MockHTTP()
mockPort = await mockHTTP.initialize()
})
it('Should enable open telemetry tracing', async function () {
server = await createSingleServer(1)
await expectLogDoesNotContain(server, 'Registering Open Telemetry tracing')
await server.kill()
})
it('Should enable open telemetry metrics', async function () {
server = await createSingleServer(1, {
open_telemetry: {
tracing: {
enabled: true,
jaeger_exporter: {
endpoint: 'http://127.0.0.1:' + mockPort
}
}
}
})
await expectLogContain(server, 'Registering Open Telemetry tracing')
})
it('Should upload a video and correctly works', async function () {
await setAccessTokensToServers([ server ])
const { uuid } = await server.videos.quickUpload({ name: 'video', privacy: VideoPrivacy.PUBLIC })
const video = await server.videos.get({ id: uuid })
expect(video.name).to.equal('video')
})
after(async function () {
await mockHTTP.terminate()
})
})
after(async function () {
await cleanupTests([ server ])
})
})
|