Skip to content

Commit

Permalink
prom: Add option to enable a "bazel_remote" HTTP metrics prefix
Browse files Browse the repository at this point in the history
This makes it possible to differentiate bazel-remote from other
applications that are using the same metrics.
  • Loading branch information
kellyma2 authored and mostynb committed Oct 17, 2024
1 parent f5c5612 commit 99f5d76
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
Expand Down
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
})
Expand Down
6 changes: 6 additions & 0 deletions utils/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down

0 comments on commit 99f5d76

Please sign in to comment.