Skip to content

Commit c882668

Browse files
authored
feature: disable metrics compression (#3899)
feature: disable metrics compression new config flag: `-disable-metrics-compression=true` polarsignals profiling finding Signed-off-by: Sandor Szücs <[email protected]>
1 parent 6d26119 commit c882668

4 files changed

Lines changed: 13 additions & 1 deletion

File tree

config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type Config struct {
6565
EnableRouteFIFOMetrics bool `yaml:"enable-route-fifo-metrics"`
6666
EnableRouteLIFOMetrics bool `yaml:"enable-route-lifo-metrics"`
6767
MetricsFlavour *listFlag `yaml:"metrics-flavour"`
68+
DisableMetricsCompression bool `yaml:"disable-metrics-compression"`
6869
FilterPlugins *pluginFlag `yaml:"filter-plugin"`
6970
PredicatePlugins *pluginFlag `yaml:"predicate-plugin"`
7071
DataclientPlugins *pluginFlag `yaml:"dataclient-plugin"`
@@ -429,6 +430,7 @@ func NewConfig() *Config {
429430
flag.BoolVar(&cfg.EnableRouteFIFOMetrics, "enable-route-fifo-metrics", false, "enable metrics for the individual route FIFO queues")
430431
flag.BoolVar(&cfg.EnableRouteLIFOMetrics, "enable-route-lifo-metrics", false, "enable metrics for the individual route LIFO queues")
431432
flag.Var(cfg.MetricsFlavour, "metrics-flavour", "Metrics flavour is used to change the exposed metrics format. Supported metric formats: 'codahale' and 'prometheus', you can select both of them by using one option with ',' separated values")
433+
flag.BoolVar(&cfg.DisableMetricsCompression, "disable-metrics-compression", false, "disable metrics compression on /metrics handler endpoint.")
432434
flag.Var(cfg.FilterPlugins, "filter-plugin", "set a custom filter plugins to load, a comma separated list of name and arguments")
433435
flag.Var(cfg.PredicatePlugins, "predicate-plugin", "set a custom predicate plugins to load, a comma separated list of name and arguments")
434436
flag.Var(cfg.DataclientPlugins, "dataclient-plugin", "set a custom dataclient plugins to load, a comma separated list of name and arguments")
@@ -894,6 +896,7 @@ func (c *Config) ToOptions() skipper.Options {
894896
EnableRouteFIFOMetrics: c.EnableRouteFIFOMetrics,
895897
EnableRouteLIFOMetrics: c.EnableRouteLIFOMetrics,
896898
MetricsFlavours: c.MetricsFlavour.values,
899+
DisableMetricsCompression: c.DisableMetricsCompression,
897900
FilterPlugins: c.FilterPlugins.values,
898901
PredicatePlugins: c.PredicatePlugins.values,
899902
DataClientPlugins: c.DataclientPlugins.values,

metrics/metrics.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ type Options struct {
231231
// EnablePrometheusStartLabel adds start label to each prometheus counter with the value of counter creation
232232
// timestamp as unix nanoseconds.
233233
EnablePrometheusStartLabel bool
234+
235+
// DisableCompression defaults to enable compression on the metrics endpoint, can be disabled if set to true
236+
DisableCompression bool
234237
}
235238

236239
var (

metrics/prometheus.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,9 @@ func (p *Prometheus) CreateHandler() http.Handler {
350350
if p.opts.EnablePrometheusStartLabel {
351351
gatherer = withStartLabelGatherer{p.registry}
352352
}
353-
return promhttp.HandlerFor(gatherer, promhttp.HandlerOpts{})
353+
return promhttp.HandlerFor(gatherer, promhttp.HandlerOpts{
354+
DisableCompression: p.opts.DisableCompression,
355+
})
354356
}
355357

356358
func (p *Prometheus) getHandler() http.Handler {

skipper.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,9 @@ type Options struct {
833833
// of metrics endpoints.
834834
MetricsFlavours []string
835835

836+
// DisableMetricsCompression if enabled it will disable compression on the metrics handler, defaults to false
837+
DisableMetricsCompression bool
838+
836839
// LoadBalancerHealthCheckInterval is *deprecated* and not in use anymore
837840
LoadBalancerHealthCheckInterval time.Duration
838841

@@ -1714,6 +1717,7 @@ func run(o Options, sig chan os.Signal, idleConnsCH chan struct{}) error {
17141717
DisableCompatibilityDefaults: o.DisableMetricsCompatibilityDefaults,
17151718
PrometheusRegistry: o.PrometheusRegistry,
17161719
EnablePrometheusStartLabel: o.EnablePrometheusStartLabel,
1720+
DisableCompression: o.DisableMetricsCompression,
17171721
}
17181722

17191723
mtr := o.MetricsBackend

0 commit comments

Comments
 (0)