aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-02-27 13:53:54 +0100
committerChocobozzz <me@florianbigard.com>2023-02-27 13:53:54 +0100
commit8d1f78044ca6eb9995001d3ab83be62460e043a6 (patch)
tree5b0cf63de96fdc67ef7aaa10af4969d9578406f0
parent5b94394a1a6d471f897d14ac62fe7bec5f9a74c2 (diff)
downloadPeerTube-8d1f78044ca6eb9995001d3ab83be62460e043a6.tar.gz
PeerTube-8d1f78044ca6eb9995001d3ab83be62460e043a6.tar.zst
PeerTube-8d1f78044ca6eb9995001d3ab83be62460e043a6.zip
Add ability to disable http duration OTEL metrics
-rw-r--r--config/default.yaml4
-rw-r--r--config/production.yaml.example4
-rw-r--r--server/initializers/checker-before-init.ts1
-rw-r--r--server/initializers/config.ts4
-rw-r--r--server/lib/opentelemetry/metrics.ts4
-rw-r--r--server/tests/api/check-params/users-emails.ts3
-rw-r--r--server/tests/api/server/open-telemetry.ts27
-rw-r--r--server/tests/shared/mock-servers/mock-email.ts2
8 files changed, 44 insertions, 5 deletions
diff --git a/config/default.yaml b/config/default.yaml
index 7ce345e2d..db014cc87 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -222,6 +222,10 @@ open_telemetry:
222 metrics: 222 metrics:
223 enabled: false 223 enabled: false
224 224
225 http_request_duration:
226 # You can disable HTTP request duration metric that can have a high tag cardinality
227 enabled: true
228
225 # Create a prometheus exporter server on this port so prometheus server can scrape PeerTube metrics 229 # Create a prometheus exporter server on this port so prometheus server can scrape PeerTube metrics
226 prometheus_exporter: 230 prometheus_exporter:
227 hostname: '127.0.0.1' 231 hostname: '127.0.0.1'
diff --git a/config/production.yaml.example b/config/production.yaml.example
index 877d77e01..a169c6c0e 100644
--- a/config/production.yaml.example
+++ b/config/production.yaml.example
@@ -220,6 +220,10 @@ open_telemetry:
220 metrics: 220 metrics:
221 enabled: false 221 enabled: false
222 222
223 http_request_duration:
224 # You can disable HTTP request duration metric that can have a high tag cardinality
225 enabled: true
226
223 # Create a prometheus exporter server on this port so prometheus server can scrape PeerTube metrics 227 # Create a prometheus exporter server on this port so prometheus server can scrape PeerTube metrics
224 prometheus_exporter: 228 prometheus_exporter:
225 hostname: '127.0.0.1' 229 hostname: '127.0.0.1'
diff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.ts
index 74fed251c..1351749a6 100644
--- a/server/initializers/checker-before-init.ts
+++ b/server/initializers/checker-before-init.ts
@@ -23,6 +23,7 @@ function checkMissedConfig () {
23 'log.log_ping_requests', 'log.log_tracker_unknown_infohash', 'log.prettify_sql', 'log.accept_client_log', 23 'log.log_ping_requests', 'log.log_tracker_unknown_infohash', 'log.prettify_sql', 'log.accept_client_log',
24 'open_telemetry.metrics.enabled', 'open_telemetry.metrics.prometheus_exporter.hostname', 24 'open_telemetry.metrics.enabled', 'open_telemetry.metrics.prometheus_exporter.hostname',
25 'open_telemetry.metrics.prometheus_exporter.port', 'open_telemetry.tracing.enabled', 'open_telemetry.tracing.jaeger_exporter.endpoint', 25 'open_telemetry.metrics.prometheus_exporter.port', 'open_telemetry.tracing.enabled', 'open_telemetry.tracing.jaeger_exporter.endpoint',
26 'open_telemetry.metrics.http_request_duration.enabled',
26 'user.video_quota', 'user.video_quota_daily', 27 'user.video_quota', 'user.video_quota_daily',
27 'video_channels.max_per_user', 28 'video_channels.max_per_user',
28 'csp.enabled', 'csp.report_only', 'csp.report_uri', 29 'csp.enabled', 'csp.report_only', 'csp.report_uri',
diff --git a/server/initializers/config.ts b/server/initializers/config.ts
index 7ad258f7a..eb9d0079c 100644
--- a/server/initializers/config.ts
+++ b/server/initializers/config.ts
@@ -195,6 +195,10 @@ const CONFIG = {
195 METRICS: { 195 METRICS: {
196 ENABLED: config.get<boolean>('open_telemetry.metrics.enabled'), 196 ENABLED: config.get<boolean>('open_telemetry.metrics.enabled'),
197 197
198 HTTP_REQUEST_DURATION: {
199 ENABLED: config.get<boolean>('open_telemetry.metrics.http_request_duration.enabled')
200 },
201
198 PROMETHEUS_EXPORTER: { 202 PROMETHEUS_EXPORTER: {
199 HOSTNAME: config.get<string>('open_telemetry.metrics.prometheus_exporter.hostname'), 203 HOSTNAME: config.get<string>('open_telemetry.metrics.prometheus_exporter.hostname'),
200 PORT: config.get<number>('open_telemetry.metrics.prometheus_exporter.port') 204 PORT: config.get<number>('open_telemetry.metrics.prometheus_exporter.port')
diff --git a/server/lib/opentelemetry/metrics.ts b/server/lib/opentelemetry/metrics.ts
index 9cc067e4a..bffe00840 100644
--- a/server/lib/opentelemetry/metrics.ts
+++ b/server/lib/opentelemetry/metrics.ts
@@ -62,7 +62,9 @@ class OpenTelemetryMetrics {
62 62
63 this.meter = metrics.getMeter('default') 63 this.meter = metrics.getMeter('default')
64 64
65 this.buildRequestObserver() 65 if (CONFIG.OPEN_TELEMETRY.METRICS.HTTP_REQUEST_DURATION.ENABLED === true) {
66 this.buildRequestObserver()
67 }
66 68
67 this.playbackMetrics = new PlaybackMetrics(this.meter) 69 this.playbackMetrics = new PlaybackMetrics(this.meter)
68 this.playbackMetrics.buildCounters() 70 this.playbackMetrics.buildCounters()
diff --git a/server/tests/api/check-params/users-emails.ts b/server/tests/api/check-params/users-emails.ts
index 8cfb1d15f..6ebcc8ffe 100644
--- a/server/tests/api/check-params/users-emails.ts
+++ b/server/tests/api/check-params/users-emails.ts
@@ -1,5 +1,4 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2import { MockSmtpServer } from '@server/tests/shared'
3import { HttpStatusCode, UserRole } from '@shared/models' 2import { HttpStatusCode, UserRole } from '@shared/models'
4import { cleanupTests, createSingleServer, makePostBodyRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' 3import { cleanupTests, createSingleServer, makePostBodyRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
5 4
@@ -112,8 +111,6 @@ describe('Test users API validators', function () {
112 }) 111 })
113 112
114 after(async function () { 113 after(async function () {
115 MockSmtpServer.Instance.kill()
116
117 await cleanupTests([ server ]) 114 await cleanupTests([ server ])
118 }) 115 })
119}) 116})
diff --git a/server/tests/api/server/open-telemetry.ts b/server/tests/api/server/open-telemetry.ts
index db76a3d7f..49f3b520b 100644
--- a/server/tests/api/server/open-telemetry.ts
+++ b/server/tests/api/server/open-telemetry.ts
@@ -29,6 +29,8 @@ describe('Open Telemetry', function () {
29 }) 29 })
30 30
31 it('Should enable open telemetry metrics', async function () { 31 it('Should enable open telemetry metrics', async function () {
32 this.timeout(120000)
33
32 server = await createSingleServer(1, { 34 server = await createSingleServer(1, {
33 open_telemetry: { 35 open_telemetry: {
34 metrics: { 36 metrics: {
@@ -37,8 +39,12 @@ describe('Open Telemetry', function () {
37 } 39 }
38 }) 40 })
39 41
42 // Simulate a HTTP request
43 await server.videos.list()
44
40 const res = await makeRawRequest({ url: metricsUrl, expectedStatus: HttpStatusCode.OK_200 }) 45 const res = await makeRawRequest({ url: metricsUrl, expectedStatus: HttpStatusCode.OK_200 })
41 expect(res.text).to.contain('peertube_job_queue_total{') 46 expect(res.text).to.contain('peertube_job_queue_total{')
47 expect(res.text).to.contain('http_request_duration_ms_bucket{')
42 }) 48 })
43 49
44 it('Should have playback metrics', async function () { 50 it('Should have playback metrics', async function () {
@@ -64,6 +70,27 @@ describe('Open Telemetry', function () {
64 expect(res.text).to.contain('peertube_playback_http_downloaded_bytes_total{') 70 expect(res.text).to.contain('peertube_playback_http_downloaded_bytes_total{')
65 }) 71 })
66 72
73 it('Should disable http request duration metrics', async function () {
74 await server.kill()
75
76 server = await createSingleServer(1, {
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
67 after(async function () { 94 after(async function () {
68 await server.kill() 95 await server.kill()
69 }) 96 })
diff --git a/server/tests/shared/mock-servers/mock-email.ts b/server/tests/shared/mock-servers/mock-email.ts
index 79bc22d58..5f37f6ae0 100644
--- a/server/tests/shared/mock-servers/mock-email.ts
+++ b/server/tests/shared/mock-servers/mock-email.ts
@@ -43,7 +43,7 @@ class MockSmtpServer {
43 kill () { 43 kill () {
44 if (!this.maildev) return 44 if (!this.maildev) return
45 45
46 this.maildev.shutdown() 46 this.maildev.close()
47 47
48 this.maildev = null 48 this.maildev = null
49 MockSmtpServer.instance = null 49 MockSmtpServer.instance = null