metrics: instrument request with histograms by default (#33921)

Signed-off-by: bergquist <carl.bergquist@gmail.com>
This commit is contained in:
Carl Bergquist 2021-05-14 12:53:50 +02:00 committed by GitHub
parent 8ec87250c1
commit 8254efc027
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View File

@ -60,7 +60,11 @@ func RequestMetrics(cfg *setting.Cfg) func(handler string) macaron.Handler {
method := sanitizeMethod(req.Method) method := sanitizeMethod(req.Method)
// enable histogram and disable summaries + counters for http requests. // 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 // avoiding the sanitize functions for in the new instrumentation
// since they dont make much sense. We should remove them later. // since they dont make much sense. We should remove them later.
histogram := httpRequestDurationHistogram. histogram := httpRequestDurationHistogram.
@ -75,10 +79,6 @@ func RequestMetrics(cfg *setting.Cfg) func(handler string) macaron.Handler {
return return
} }
histogram.Observe(time.Since(now).Seconds()) 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 { switch {

View File

@ -399,9 +399,11 @@ func (cfg Cfg) IsDatabaseMetricsEnabled() bool {
return cfg.FeatureToggles["database_metrics"] return cfg.FeatureToggles["database_metrics"]
} }
// IsHTTPRequestHistogramEnabled returns whether the http_request_histogram feature is enabled. // IsHTTPRequestHistogramDisabled returns whether the request historgrams is disabled.
func (cfg Cfg) IsHTTPRequestHistogramEnabled() bool { // This feature toggle will be removed in Grafana 8.x but gives the operator
return cfg.FeatureToggles["http_request_histogram"] // some graceperiod to update all the monitoring tools.
func (cfg Cfg) IsHTTPRequestHistogramDisabled() bool {
return cfg.FeatureToggles["disable_http_request_histogram"]
} }
type CommandLineArgs struct { type CommandLineArgs struct {