mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
Metrics: Remove support for using summaries instead of histogram for HTTP instrumentation (#49985)
Signed-off-by: bergquist <carl.bergquist@gmail.com>
This commit is contained in:
parent
f566958555
commit
9562fb389f
@ -36,7 +36,6 @@ export interface FeatureToggles {
|
||||
influxdbBackendMigration?: boolean;
|
||||
newNavigation?: boolean;
|
||||
showFeatureFlagsInUI?: boolean;
|
||||
disable_http_request_histogram?: boolean;
|
||||
publicDashboards?: boolean;
|
||||
lokiLive?: boolean;
|
||||
swaggerUi?: boolean;
|
||||
|
@ -24,12 +24,6 @@ var (
|
||||
// MProxyStatus is a metric proxy http response status
|
||||
MProxyStatus *prometheus.CounterVec
|
||||
|
||||
// MHttpRequestTotal is a metric http request counter
|
||||
MHttpRequestTotal *prometheus.CounterVec
|
||||
|
||||
// MHttpRequestSummary is a metric http request summary
|
||||
MHttpRequestSummary *prometheus.SummaryVec
|
||||
|
||||
// MApiUserSignUpStarted is a metric amount of users who started the signup flow
|
||||
MApiUserSignUpStarted prometheus.Counter
|
||||
|
||||
@ -226,23 +220,6 @@ func init() {
|
||||
Namespace: ExporterName,
|
||||
}, []string{"code"}, httpStatusCodes...)
|
||||
|
||||
MHttpRequestTotal = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "http_request_total",
|
||||
Help: "http request counter",
|
||||
},
|
||||
[]string{"handler", "statuscode", "method"},
|
||||
)
|
||||
|
||||
MHttpRequestSummary = prometheus.NewSummaryVec(
|
||||
prometheus.SummaryOpts{
|
||||
Name: "http_request_duration_milliseconds",
|
||||
Help: "http request summary",
|
||||
Objectives: objectiveMap,
|
||||
},
|
||||
[]string{"handler", "statuscode", "method"},
|
||||
)
|
||||
|
||||
MApiUserSignUpStarted = newCounterStartingAtZero(prometheus.CounterOpts{
|
||||
Name: "api_user_signup_started_total",
|
||||
Help: "amount of users who started the signup flow",
|
||||
@ -615,8 +592,6 @@ func initMetricVars() {
|
||||
MPageStatus,
|
||||
MApiStatus,
|
||||
MProxyStatus,
|
||||
MHttpRequestTotal,
|
||||
MHttpRequestSummary,
|
||||
MApiUserSignUpStarted,
|
||||
MApiUserSignUpCompleted,
|
||||
MApiUserSignUpInvite,
|
||||
|
@ -65,31 +65,22 @@ func RequestMetrics(features featuremgmt.FeatureToggles) web.Handler {
|
||||
}
|
||||
|
||||
status := rw.Status()
|
||||
|
||||
code := sanitizeCode(status)
|
||||
method := sanitizeMethod(req.Method)
|
||||
|
||||
// enable histogram and disable summaries + counters for http requests.
|
||||
if features.IsEnabled(featuremgmt.FlagDisableHttpRequestHistogram) {
|
||||
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.
|
||||
WithLabelValues(handler, code, req.Method)
|
||||
if traceID := tracing.TraceIDFromContext(c.Req.Context(), true); traceID != "" {
|
||||
// Need to type-convert the Observer to an
|
||||
// ExemplarObserver. This will always work for a
|
||||
// HistogramVec.
|
||||
histogram.(prometheus.ExemplarObserver).ObserveWithExemplar(
|
||||
time.Since(now).Seconds(), prometheus.Labels{"traceID": traceID},
|
||||
)
|
||||
return
|
||||
}
|
||||
histogram.Observe(time.Since(now).Seconds())
|
||||
// avoiding the sanitize functions for in the new instrumentation
|
||||
// since they dont make much sense. We should remove them later.
|
||||
histogram := httpRequestDurationHistogram.
|
||||
WithLabelValues(handler, code, req.Method)
|
||||
if traceID := tracing.TraceIDFromContext(c.Req.Context(), true); traceID != "" {
|
||||
// Need to type-convert the Observer to an
|
||||
// ExemplarObserver. This will always work for a
|
||||
// HistogramVec.
|
||||
histogram.(prometheus.ExemplarObserver).ObserveWithExemplar(
|
||||
time.Since(now).Seconds(), prometheus.Labels{"traceID": traceID},
|
||||
)
|
||||
return
|
||||
}
|
||||
histogram.Observe(time.Since(now).Seconds())
|
||||
|
||||
switch {
|
||||
case strings.HasPrefix(req.RequestURI, "/api/datasources/proxy"):
|
||||
@ -141,10 +132,6 @@ func countProxyRequests(status int) {
|
||||
}
|
||||
}
|
||||
|
||||
func sanitizeMethod(m string) string {
|
||||
return strings.ToLower(m)
|
||||
}
|
||||
|
||||
// If the wrapped http.Handler has not set a status code, i.e. the value is
|
||||
// currently 0, sanitizeCode will return 200, for consistency with behavior in
|
||||
// the stdlib.
|
||||
|
@ -117,11 +117,6 @@ var (
|
||||
State: FeatureStateAlpha,
|
||||
RequiresDevMode: true,
|
||||
},
|
||||
{
|
||||
Name: "disable_http_request_histogram",
|
||||
Description: "Do not create histograms for http requests",
|
||||
State: FeatureStateAlpha,
|
||||
},
|
||||
{
|
||||
Name: "publicDashboards",
|
||||
Description: "enables public access to dashboards",
|
||||
|
@ -87,10 +87,6 @@ const (
|
||||
// Show feature flags in the settings UI
|
||||
FlagShowFeatureFlagsInUI = "showFeatureFlagsInUI"
|
||||
|
||||
// FlagDisableHttpRequestHistogram
|
||||
// Do not create histograms for http requests
|
||||
FlagDisableHttpRequestHistogram = "disable_http_request_histogram"
|
||||
|
||||
// FlagPublicDashboards
|
||||
// enables public access to dashboards
|
||||
FlagPublicDashboards = "publicDashboards"
|
||||
|
@ -18,14 +18,13 @@ import (
|
||||
|
||||
func TestFeatureToggleFiles(t *testing.T) {
|
||||
legacyNames := map[string]bool{
|
||||
"httpclientprovider_azure_auth": true,
|
||||
"service-accounts": true,
|
||||
"database_metrics": true,
|
||||
"live-config": true,
|
||||
"live-pipeline": true,
|
||||
"live-service-web-worker": true,
|
||||
"prometheus_azure_auth": true,
|
||||
"disable_http_request_histogram": true,
|
||||
"httpclientprovider_azure_auth": true,
|
||||
"service-accounts": true,
|
||||
"database_metrics": true,
|
||||
"live-config": true,
|
||||
"live-pipeline": true,
|
||||
"live-service-web-worker": true,
|
||||
"prometheus_azure_auth": true,
|
||||
}
|
||||
|
||||
t.Run("verify files", func(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user