diff --git a/pkg/middleware/request_metrics.go b/pkg/middleware/request_metrics.go index 69cf49ae9fc..1fc93cc1157 100644 --- a/pkg/middleware/request_metrics.go +++ b/pkg/middleware/request_metrics.go @@ -60,7 +60,11 @@ func RequestMetrics(cfg *setting.Cfg) func(handler string) macaron.Handler { method := sanitizeMethod(req.Method) // enable histogram and disable summaries + counters for http requests. - if cfg.IsHTTPRequestHistogramEnabled() { + if cfg.IsHTTPRequestHistogramDisabled() { + duration := time.Since(now).Nanoseconds() / int64(time.Millisecond) + metrics.MHttpRequestTotal.WithLabelValues(handler, code, method).Inc() + metrics.MHttpRequestSummary.WithLabelValues(handler, code, method).Observe(float64(duration)) + } else { // avoiding the sanitize functions for in the new instrumentation // since they dont make much sense. We should remove them later. histogram := httpRequestDurationHistogram. @@ -75,10 +79,6 @@ func RequestMetrics(cfg *setting.Cfg) func(handler string) macaron.Handler { return } histogram.Observe(time.Since(now).Seconds()) - } else { - duration := time.Since(now).Nanoseconds() / int64(time.Millisecond) - metrics.MHttpRequestTotal.WithLabelValues(handler, code, method).Inc() - metrics.MHttpRequestSummary.WithLabelValues(handler, code, method).Observe(float64(duration)) } switch { diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index ca7ef20801f..1b4395569fa 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -399,9 +399,11 @@ func (cfg Cfg) IsDatabaseMetricsEnabled() bool { return cfg.FeatureToggles["database_metrics"] } -// IsHTTPRequestHistogramEnabled returns whether the http_request_histogram feature is enabled. -func (cfg Cfg) IsHTTPRequestHistogramEnabled() bool { - return cfg.FeatureToggles["http_request_histogram"] +// IsHTTPRequestHistogramDisabled returns whether the request historgrams is disabled. +// This feature toggle will be removed in Grafana 8.x but gives the operator +// some graceperiod to update all the monitoring tools. +func (cfg Cfg) IsHTTPRequestHistogramDisabled() bool { + return cfg.FeatureToggles["disable_http_request_histogram"] } type CommandLineArgs struct {