From 630d0a1bf5897fff203cb07e426223f55dcc882d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 5 Jul 2022 15:43:21 +0200 Subject: Introduce experimental telemetry --- server/tests/api/server/index.ts | 1 + server/tests/api/server/no-client.ts | 3 +- server/tests/api/server/open-telemetry.ts | 95 +++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 server/tests/api/server/open-telemetry.ts (limited to 'server/tests/api') 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' import './stats' import './tracker' import './no-client' +import './open-telemetry' import './plugins' 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 @@ -import 'mocha' import request from 'supertest' -import { cleanupTests, createSingleServer, PeerTubeServer } from '@shared/server-commands' import { HttpStatusCode } from '@shared/models' +import { cleanupTests, createSingleServer, PeerTubeServer } from '@shared/server-commands' describe('Start and stop server without web client routes', function () { 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 @@ +/* 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 } 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://localhost:9091/metrics' + + it('Should not enable open telemetry metrics', async function () { + server = await createSingleServer(1) + + let hasError = false + try { + await makeRawRequest(metricsUrl, 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(metricsUrl, HttpStatusCode.OK_200) + expect(res.text).to.contain('peertube_job_queue_total') + + 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://localhost:' + 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 ]) + }) +}) -- cgit v1.2.3