mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-17 20:52:14 +01:00
feat(prometheus): add new flag --prometheus-metrics-path
This commit is contained in:
2
Makefile
2
Makefile
@@ -68,6 +68,7 @@ PROMETHEUS_NAMESPACE=gotenberg
|
|||||||
PROMETHEUS_COLLECT_INTERVAL=1s
|
PROMETHEUS_COLLECT_INTERVAL=1s
|
||||||
PROMETHEUS_DISABLE_ROUTE_LOGGING=false
|
PROMETHEUS_DISABLE_ROUTE_LOGGING=false
|
||||||
PROMETHEUS_DISABLE_COLLECT=false
|
PROMETHEUS_DISABLE_COLLECT=false
|
||||||
|
PROMETHEUS_METRICS_PATH=/prometheus/metrics
|
||||||
WEBHOOK_ENABLE_SYNC_MODE=false
|
WEBHOOK_ENABLE_SYNC_MODE=false
|
||||||
WEBHOOK_ALLOW_LIST=
|
WEBHOOK_ALLOW_LIST=
|
||||||
WEBHOOK_DENY_LIST=
|
WEBHOOK_DENY_LIST=
|
||||||
@@ -143,6 +144,7 @@ run: ## Start a Gotenberg container
|
|||||||
--prometheus-collect-interval=$(PROMETHEUS_COLLECT_INTERVAL) \
|
--prometheus-collect-interval=$(PROMETHEUS_COLLECT_INTERVAL) \
|
||||||
--prometheus-disable-route-logging=$(PROMETHEUS_DISABLE_ROUTE_LOGGING) \
|
--prometheus-disable-route-logging=$(PROMETHEUS_DISABLE_ROUTE_LOGGING) \
|
||||||
--prometheus-disable-collect=$(PROMETHEUS_DISABLE_COLLECT) \
|
--prometheus-disable-collect=$(PROMETHEUS_DISABLE_COLLECT) \
|
||||||
|
--prometheus-metrics-path=$(PROMETHEUS_METRICS_PATH) \
|
||||||
--webhook-enable-sync-mode="$(WEBHOOK_ENABLE_SYNC_MODE)" \
|
--webhook-enable-sync-mode="$(WEBHOOK_ENABLE_SYNC_MODE)" \
|
||||||
--webhook-allow-list="$(WEBHOOK_ALLOW_LIST)" \
|
--webhook-allow-list="$(WEBHOOK_ALLOW_LIST)" \
|
||||||
--webhook-deny-list="$(WEBHOOK_DENY_LIST)" \
|
--webhook-deny-list="$(WEBHOOK_DENY_LIST)" \
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ type Prometheus struct {
|
|||||||
interval time.Duration
|
interval time.Duration
|
||||||
disableRouteLogging bool
|
disableRouteLogging bool
|
||||||
disableCollect bool
|
disableCollect bool
|
||||||
|
metricsPath string
|
||||||
|
|
||||||
metrics []gotenberg.Metric
|
metrics []gotenberg.Metric
|
||||||
registry *prometheus.Registry
|
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.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-route-logging", false, "Disable the route logging")
|
||||||
fs.Bool("prometheus-disable-collect", false, "Disable the collect of metrics")
|
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
|
return fs
|
||||||
}(),
|
}(),
|
||||||
@@ -56,6 +58,7 @@ func (mod *Prometheus) Provision(ctx *gotenberg.Context) error {
|
|||||||
mod.interval = flags.MustDuration("prometheus-collect-interval")
|
mod.interval = flags.MustDuration("prometheus-collect-interval")
|
||||||
mod.disableRouteLogging = flags.MustBool("prometheus-disable-route-logging")
|
mod.disableRouteLogging = flags.MustBool("prometheus-disable-route-logging")
|
||||||
mod.disableCollect = flags.MustBool("prometheus-disable-collect")
|
mod.disableCollect = flags.MustBool("prometheus-disable-collect")
|
||||||
|
mod.metricsPath = flags.MustString("prometheus-metrics-path")
|
||||||
|
|
||||||
if mod.disableCollect {
|
if mod.disableCollect {
|
||||||
// Exit early.
|
// Exit early.
|
||||||
@@ -98,6 +101,10 @@ func (mod *Prometheus) Validate() error {
|
|||||||
return errors.New("namespace must not be empty")
|
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))
|
metricsMap := make(map[string]string, len(mod.metrics))
|
||||||
|
|
||||||
for _, metric := range mod.metrics {
|
for _, metric := range mod.metrics {
|
||||||
@@ -171,7 +178,7 @@ func (mod *Prometheus) Routes() ([]api.Route, error) {
|
|||||||
return []api.Route{
|
return []api.Route{
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/prometheus/metrics",
|
Path: mod.metricsPath,
|
||||||
DisableLogging: mod.disableRouteLogging,
|
DisableLogging: mod.disableRouteLogging,
|
||||||
Handler: echo.WrapHandler(
|
Handler: echo.WrapHandler(
|
||||||
promhttp.HandlerFor(mod.registry, promhttp.HandlerOpts{}),
|
promhttp.HandlerFor(mod.registry, promhttp.HandlerOpts{}),
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ Feature: /debug
|
|||||||
"prometheus-disable-collect": "false",
|
"prometheus-disable-collect": "false",
|
||||||
"prometheus-disable-route-logging": "false",
|
"prometheus-disable-route-logging": "false",
|
||||||
"prometheus-namespace": "gotenberg",
|
"prometheus-namespace": "gotenberg",
|
||||||
|
"prometheus-metrics-path": "/prometheus/metrics",
|
||||||
"webhook-allow-list": "",
|
"webhook-allow-list": "",
|
||||||
"webhook-client-timeout": "30s",
|
"webhook-client-timeout": "30s",
|
||||||
"webhook-deny-list": "",
|
"webhook-deny-list": "",
|
||||||
|
|||||||
@@ -29,6 +29,31 @@ Feature: /prometheus/metrics
|
|||||||
Then the Gotenberg container should log the following entries:
|
Then the Gotenberg container should log the following entries:
|
||||||
| "path":"/prometheus/metrics" |
|
| "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)
|
Scenario: GET /prometheus/metrics (Custom Namespace)
|
||||||
Given I have a Gotenberg container with the following environment variable(s):
|
Given I have a Gotenberg container with the following environment variable(s):
|
||||||
| PROMETHEUS_NAMESPACE | foo |
|
| PROMETHEUS_NAMESPACE | foo |
|
||||||
|
|||||||
Reference in New Issue
Block a user