From 99f5d76b8ca8fabbcba8da0a64526372a62f5ed3 Mon Sep 17 00:00:00 2001 From: Michael Kelly Date: Wed, 9 Oct 2024 22:47:55 -0700 Subject: [PATCH] prom: Add option to enable a "bazel_remote" HTTP metrics prefix This makes it possible to differentiate bazel-remote from other applications that are using the same metrics. --- README.md | 4 ++++ config/config.go | 4 ++++ main.go | 6 ++++++ utils/flags/flags.go | 6 ++++++ 4 files changed, 20 insertions(+) diff --git a/README.md b/README.md index 65990cd6d..d9a44eff5 100644 --- a/README.md +++ b/README.md @@ -432,6 +432,10 @@ OPTIONS: endpoint. (default: false, ie disable metrics) [$BAZEL_REMOTE_ENABLE_ENDPOINT_METRICS] + --http_metrics_prefix Prefix HTTP metrics names with `bazel_remote` + (default: false, ie no prefix) + [$BAZEL_REMOTE_HTTP_METRICS_PREFIX] + --experimental_remote_asset_api Whether to enable the experimental remote asset API implementation. (default: false, ie disable remote asset API) [$BAZEL_REMOTE_EXPERIMENTAL_REMOTE_ASSET_API] diff --git a/config/config.go b/config/config.go index 832ce6780..b239df050 100644 --- a/config/config.go +++ b/config/config.go @@ -118,6 +118,7 @@ type Config struct { EnableACKeyInstanceMangling bool `yaml:"enable_ac_key_instance_mangling"` EnableEndpointMetrics bool `yaml:"enable_endpoint_metrics"` MetricsDurationBuckets []float64 `yaml:"endpoint_metrics_duration_buckets"` + HttpMetricsPrefix bool `yaml:"http_metrics_prefix"` ExperimentalRemoteAssetAPI bool `yaml:"experimental_remote_asset_api"` HTTPReadTimeout time.Duration `yaml:"http_read_timeout"` HTTPWriteTimeout time.Duration `yaml:"http_write_timeout"` @@ -175,6 +176,7 @@ func newFromArgs(dir string, maxSize int, storageMode string, zstdImplementation disableGRPCACDepsCheck bool, enableACKeyInstanceMangling bool, enableEndpointMetrics bool, + httpMetricsPrefix bool, experimentalRemoteAssetAPI bool, httpReadTimeout time.Duration, httpWriteTimeout time.Duration, @@ -211,6 +213,7 @@ func newFromArgs(dir string, maxSize int, storageMode string, zstdImplementation EnableACKeyInstanceMangling: enableACKeyInstanceMangling, EnableEndpointMetrics: enableEndpointMetrics, MetricsDurationBuckets: defaultDurationBuckets, + HttpMetricsPrefix: httpMetricsPrefix, ExperimentalRemoteAssetAPI: experimentalRemoteAssetAPI, HTTPReadTimeout: httpReadTimeout, HTTPWriteTimeout: httpWriteTimeout, @@ -662,6 +665,7 @@ func get(ctx *cli.Context) (*Config, error) { ctx.Bool("disable_grpc_ac_deps_check"), ctx.Bool("enable_ac_key_instance_mangling"), ctx.Bool("enable_endpoint_metrics"), + ctx.Bool("http_metrics_prefix"), ctx.Bool("experimental_remote_asset_api"), ctx.Duration("http_read_timeout"), ctx.Duration("http_write_timeout"), diff --git a/main.go b/main.go index 6ecd4fb07..95c9946e5 100644 --- a/main.go +++ b/main.go @@ -287,8 +287,14 @@ func startHttpServer(c *config.Config, httpServer **http.Server, if c.EnableEndpointMetrics { log.Println("Endpoint metrics: enabled") + prefix := "" + if c.HttpMetricsPrefix { + prefix = "bazel_remote" + } + metricsMdlw := middleware.New(middleware.Config{ Recorder: httpmetrics.NewRecorder(httpmetrics.Config{ + Prefix: prefix, DurationBuckets: c.MetricsDurationBuckets, }), }) diff --git a/utils/flags/flags.go b/utils/flags/flags.go index a385bd549..342dfa573 100644 --- a/utils/flags/flags.go +++ b/utils/flags/flags.go @@ -471,6 +471,12 @@ func GetCliFlags() []cli.Flag { DefaultText: "false, ie disable metrics", EnvVars: []string{"BAZEL_REMOTE_ENABLE_ENDPOINT_METRICS"}, }, + &cli.BoolFlag{ + Name: "http_metrics_prefix", + Usage: "Whether to prefix http metrics with `bazel_remote` or not", + DefaultText: "false, ie no prefix", + EnvVars: []string{"BAZEL_REMOTE_HTTP_METRICS_PREFIX"}, + }, &cli.BoolFlag{ Name: "experimental_remote_asset_api", Usage: "Whether to enable the experimental remote asset API implementation.",