From 92de0cf6fe51d7ac4b76d7b95252009e0c24c345 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 14 Jan 2026 17:04:57 +0800 Subject: [PATCH] feat(prometheus): add new flag --prometheus-metrics-path --- Makefile | 2 ++ pkg/modules/prometheus/prometheus.go | 9 ++++++- test/integration/features/debug.feature | 1 + .../features/prometheus_metrics.feature | 25 +++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d413b307..a89f8afb 100644 --- a/Makefile +++ b/Makefile @@ -68,6 +68,7 @@ PROMETHEUS_NAMESPACE=gotenberg PROMETHEUS_COLLECT_INTERVAL=1s PROMETHEUS_DISABLE_ROUTE_LOGGING=false PROMETHEUS_DISABLE_COLLECT=false +PROMETHEUS_METRICS_PATH=/prometheus/metrics WEBHOOK_ENABLE_SYNC_MODE=false WEBHOOK_ALLOW_LIST= WEBHOOK_DENY_LIST= @@ -143,6 +144,7 @@ run: ## Start a Gotenberg container --prometheus-collect-interval=$(PROMETHEUS_COLLECT_INTERVAL) \ --prometheus-disable-route-logging=$(PROMETHEUS_DISABLE_ROUTE_LOGGING) \ --prometheus-disable-collect=$(PROMETHEUS_DISABLE_COLLECT) \ + --prometheus-metrics-path=$(PROMETHEUS_METRICS_PATH) \ --webhook-enable-sync-mode="$(WEBHOOK_ENABLE_SYNC_MODE)" \ --webhook-allow-list="$(WEBHOOK_ALLOW_LIST)" \ --webhook-deny-list="$(WEBHOOK_DENY_LIST)" \ diff --git a/pkg/modules/prometheus/prometheus.go b/pkg/modules/prometheus/prometheus.go index d899e6b4..51a72833 100644 --- a/pkg/modules/prometheus/prometheus.go +++ b/pkg/modules/prometheus/prometheus.go @@ -27,6 +27,7 @@ type Prometheus struct { interval time.Duration disableRouteLogging bool disableCollect bool + metricsPath string metrics []gotenberg.Metric registry *prometheus.Registry @@ -42,6 +43,7 @@ func (mod *Prometheus) Descriptor() gotenberg.ModuleDescriptor { fs.Duration("prometheus-collect-interval", time.Duration(1)*time.Second, "Set the interval for collecting modules' metrics") fs.Bool("prometheus-disable-route-logging", false, "Disable the route logging") fs.Bool("prometheus-disable-collect", false, "Disable the collect of metrics") + fs.String("prometheus-metrics-path", "/prometheus/metrics", "Path for Prometheus metrics endpoint") return fs }(), @@ -56,6 +58,7 @@ func (mod *Prometheus) Provision(ctx *gotenberg.Context) error { mod.interval = flags.MustDuration("prometheus-collect-interval") mod.disableRouteLogging = flags.MustBool("prometheus-disable-route-logging") mod.disableCollect = flags.MustBool("prometheus-disable-collect") + mod.metricsPath = flags.MustString("prometheus-metrics-path") if mod.disableCollect { // Exit early. @@ -98,6 +101,10 @@ func (mod *Prometheus) Validate() error { return errors.New("namespace must not be empty") } + if mod.metricsPath == "" { + return errors.New("metrics path cannot be empty") + } + metricsMap := make(map[string]string, len(mod.metrics)) for _, metric := range mod.metrics { @@ -171,7 +178,7 @@ func (mod *Prometheus) Routes() ([]api.Route, error) { return []api.Route{ { Method: http.MethodGet, - Path: "/prometheus/metrics", + Path: mod.metricsPath, DisableLogging: mod.disableRouteLogging, Handler: echo.WrapHandler( promhttp.HandlerFor(mod.registry, promhttp.HandlerOpts{}), diff --git a/test/integration/features/debug.feature b/test/integration/features/debug.feature index b3f96604..033810a3 100644 --- a/test/integration/features/debug.feature +++ b/test/integration/features/debug.feature @@ -109,6 +109,7 @@ Feature: /debug "prometheus-disable-collect": "false", "prometheus-disable-route-logging": "false", "prometheus-namespace": "gotenberg", + "prometheus-metrics-path": "/prometheus/metrics", "webhook-allow-list": "", "webhook-client-timeout": "30s", "webhook-deny-list": "", diff --git a/test/integration/features/prometheus_metrics.feature b/test/integration/features/prometheus_metrics.feature index 5a12402f..19a1e40e 100644 --- a/test/integration/features/prometheus_metrics.feature +++ b/test/integration/features/prometheus_metrics.feature @@ -29,6 +29,31 @@ Feature: /prometheus/metrics Then the Gotenberg container should log the following entries: | "path":"/prometheus/metrics" | + Scenario: GET /custom/metrics (Custom Metrics Path) + Given I have a Gotenberg container with the following environment variable(s): + | PROMETHEUS_METRICS_PATH | /custom/metrics | + When I make a "GET" request to Gotenberg at the "/custom/metrics" endpoint + Then the response status code should be 200 + Then the response header "Content-Type" should be "text/plain; version=0.0.4; charset=utf-8; escaping=underscores" + Then the response body should match string: + """ + # HELP gotenberg_chromium_requests_queue_size Current number of Chromium conversion requests waiting to be treated. + # TYPE gotenberg_chromium_requests_queue_size gauge + gotenberg_chromium_requests_queue_size 0 + # HELP gotenberg_chromium_restarts_count Current number of Chromium restarts. + # TYPE gotenberg_chromium_restarts_count gauge + gotenberg_chromium_restarts_count 0 + # HELP gotenberg_libreoffice_requests_queue_size Current number of LibreOffice conversion requests waiting to be treated. + # TYPE gotenberg_libreoffice_requests_queue_size gauge + gotenberg_libreoffice_requests_queue_size 0 + # HELP gotenberg_libreoffice_restarts_count Current number of LibreOffice restarts. + # TYPE gotenberg_libreoffice_restarts_count gauge + gotenberg_libreoffice_restarts_count 0 + + """ + Then the Gotenberg container should log the following entries: + | "path":"/custom/metrics" | + Scenario: GET /prometheus/metrics (Custom Namespace) Given I have a Gotenberg container with the following environment variable(s): | PROMETHEUS_NAMESPACE | foo |