mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-08 00:22:14 +01:00
feat(otel): flag to disable telemetry for system routes
This commit is contained in:
@@ -41,6 +41,9 @@ type Api struct {
|
||||
basicAuthPassword string
|
||||
downloadFromCfg downloadFromConfig
|
||||
disableHealthCheckRouteTelemetry bool
|
||||
disableRootRouteTelemetry bool
|
||||
disableDebugRouteTelemetry bool
|
||||
disableVersionRouteTelemetry bool
|
||||
enableDebugRoute bool
|
||||
|
||||
routes []Route
|
||||
@@ -197,6 +200,9 @@ func (a *Api) Descriptor() gotenberg.ModuleDescriptor {
|
||||
fs.Int("api-download-from-max-retry", 4, "Set the maximum number of retries for the download from feature")
|
||||
fs.Bool("api-disable-download-from", false, "Disable the download from feature")
|
||||
fs.Bool("api-disable-health-check-route-telemetry", false, "Disable telemetry for health check route")
|
||||
fs.Bool("api-disable-root-route-telemetry", false, "Disable telemetry for the root route")
|
||||
fs.Bool("api-disable-debug-route-telemetry", false, "Disable telemetry for the debug route")
|
||||
fs.Bool("api-disable-version-route-telemetry", false, "Disable telemetry for the version route")
|
||||
fs.Bool("api-enable-debug-route", false, "Enable the debug route")
|
||||
|
||||
// Deprecated flags.
|
||||
@@ -235,6 +241,9 @@ func (a *Api) Provision(ctx *gotenberg.Context) error {
|
||||
disable: flags.MustBool("api-disable-download-from"),
|
||||
}
|
||||
a.disableHealthCheckRouteTelemetry = flags.MustDeprecatedBool("api-disable-health-check-logging", "api-disable-health-check-route-telemetry")
|
||||
a.disableRootRouteTelemetry = flags.MustBool("api-disable-root-route-telemetry")
|
||||
a.disableDebugRouteTelemetry = flags.MustBool("api-disable-debug-route-telemetry")
|
||||
a.disableVersionRouteTelemetry = flags.MustBool("api-disable-version-route-telemetry")
|
||||
a.enableDebugRoute = flags.MustBool("api-enable-debug-route")
|
||||
|
||||
// Port from env?
|
||||
@@ -453,10 +462,19 @@ func (a *Api) Start() error {
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the user wishes to disable telemetry for the health check route.
|
||||
// Check if the user wishes to disable telemetry for specific routes.
|
||||
if a.disableHealthCheckRouteTelemetry {
|
||||
disableTelemetryForPaths = append(disableTelemetryForPaths, "health")
|
||||
}
|
||||
if a.disableRootRouteTelemetry {
|
||||
disableTelemetryForPaths = append(disableTelemetryForPaths, "")
|
||||
}
|
||||
if a.disableDebugRouteTelemetry {
|
||||
disableTelemetryForPaths = append(disableTelemetryForPaths, "debug")
|
||||
}
|
||||
if a.disableVersionRouteTelemetry {
|
||||
disableTelemetryForPaths = append(disableTelemetryForPaths, "version")
|
||||
}
|
||||
|
||||
serverName := fmt.Sprintf("%s:%d", a.bindIp, a.port)
|
||||
|
||||
|
||||
@@ -23,11 +23,11 @@ func init() {
|
||||
// Prometheus is a module that collects metrics and exposes them via an HTTP
|
||||
// route.
|
||||
type Prometheus struct {
|
||||
namespace string
|
||||
interval time.Duration
|
||||
disableRouteLogging bool
|
||||
disableCollect bool
|
||||
metricsPath string
|
||||
namespace string
|
||||
interval time.Duration
|
||||
disableRouteTelemetry bool
|
||||
disableCollect bool
|
||||
metricsPath string
|
||||
|
||||
metrics []gotenberg.Metric
|
||||
registry *prometheus.Registry
|
||||
@@ -41,10 +41,18 @@ func (mod *Prometheus) Descriptor() gotenberg.ModuleDescriptor {
|
||||
fs := flag.NewFlagSet("prometheus", flag.ExitOnError)
|
||||
fs.String("prometheus-namespace", "gotenberg", "Set the namespace of 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-telemetry", false, "Disable telemetry for the Prometheus metrics route")
|
||||
fs.Bool("prometheus-disable-collect", false, "Disable the collect of metrics")
|
||||
fs.String("prometheus-metrics-path", "/prometheus/metrics", "Path for Prometheus metrics endpoint")
|
||||
|
||||
// Deprecated flags.
|
||||
fs.Bool("prometheus-disable-route-logging", false, "Disable the route logging")
|
||||
|
||||
err := fs.MarkDeprecated("prometheus-disable-route-logging", "use --prometheus-disable-route-telemetry instead")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return fs
|
||||
}(),
|
||||
New: func() gotenberg.Module { return new(Prometheus) },
|
||||
@@ -56,7 +64,7 @@ func (mod *Prometheus) Provision(ctx *gotenberg.Context) error {
|
||||
flags := ctx.ParsedFlags()
|
||||
mod.namespace = flags.MustString("prometheus-namespace")
|
||||
mod.interval = flags.MustDuration("prometheus-collect-interval")
|
||||
mod.disableRouteLogging = flags.MustBool("prometheus-disable-route-logging")
|
||||
mod.disableRouteTelemetry = flags.MustDeprecatedBool("prometheus-disable-route-logging", "prometheus-disable-route-telemetry")
|
||||
mod.disableCollect = flags.MustBool("prometheus-disable-collect")
|
||||
mod.metricsPath = flags.MustString("prometheus-metrics-path")
|
||||
|
||||
@@ -179,7 +187,7 @@ func (mod *Prometheus) Routes() ([]api.Route, error) {
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: mod.metricsPath,
|
||||
DisableTelemetry: mod.disableRouteLogging,
|
||||
DisableTelemetry: mod.disableRouteTelemetry,
|
||||
Handler: echo.WrapHandler(
|
||||
promhttp.HandlerFor(mod.registry, promhttp.HandlerOpts{}),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user