Metrics: Remove support for using summaries instead of histogram for HTTP instrumentation (#49985) (#50003)
Signed-off-by: bergquist <carl.bergquist@gmail.com>
(cherry picked from commit 9562fb389f)
Co-authored-by: Carl Bergquist <carl.bergquist@gmail.com>
This commit is contained in:
co-authored by
Carl Bergquist
parent
b2e73b866f
commit
39f461ea78
@@ -36,7 +36,6 @@ export interface FeatureToggles {
|
|||||||
influxdbBackendMigration?: boolean;
|
influxdbBackendMigration?: boolean;
|
||||||
newNavigation?: boolean;
|
newNavigation?: boolean;
|
||||||
showFeatureFlagsInUI?: boolean;
|
showFeatureFlagsInUI?: boolean;
|
||||||
disable_http_request_histogram?: boolean;
|
|
||||||
publicDashboards?: boolean;
|
publicDashboards?: boolean;
|
||||||
lokiLive?: boolean;
|
lokiLive?: boolean;
|
||||||
swaggerUi?: boolean;
|
swaggerUi?: boolean;
|
||||||
|
|||||||
@@ -24,12 +24,6 @@ var (
|
|||||||
// MProxyStatus is a metric proxy http response status
|
// MProxyStatus is a metric proxy http response status
|
||||||
MProxyStatus *prometheus.CounterVec
|
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 is a metric amount of users who started the signup flow
|
||||||
MApiUserSignUpStarted prometheus.Counter
|
MApiUserSignUpStarted prometheus.Counter
|
||||||
|
|
||||||
@@ -226,23 +220,6 @@ func init() {
|
|||||||
Namespace: ExporterName,
|
Namespace: ExporterName,
|
||||||
}, []string{"code"}, httpStatusCodes...)
|
}, []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{
|
MApiUserSignUpStarted = newCounterStartingAtZero(prometheus.CounterOpts{
|
||||||
Name: "api_user_signup_started_total",
|
Name: "api_user_signup_started_total",
|
||||||
Help: "amount of users who started the signup flow",
|
Help: "amount of users who started the signup flow",
|
||||||
@@ -615,8 +592,6 @@ func initMetricVars() {
|
|||||||
MPageStatus,
|
MPageStatus,
|
||||||
MApiStatus,
|
MApiStatus,
|
||||||
MProxyStatus,
|
MProxyStatus,
|
||||||
MHttpRequestTotal,
|
|
||||||
MHttpRequestSummary,
|
|
||||||
MApiUserSignUpStarted,
|
MApiUserSignUpStarted,
|
||||||
MApiUserSignUpCompleted,
|
MApiUserSignUpCompleted,
|
||||||
MApiUserSignUpInvite,
|
MApiUserSignUpInvite,
|
||||||
|
|||||||
@@ -66,31 +66,22 @@ func RequestMetrics(features featuremgmt.FeatureToggles) web.Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
status := rw.Status()
|
status := rw.Status()
|
||||||
|
|
||||||
code := sanitizeCode(status)
|
code := sanitizeCode(status)
|
||||||
method := sanitizeMethod(req.Method)
|
|
||||||
|
|
||||||
// enable histogram and disable summaries + counters for http requests.
|
// avoiding the sanitize functions for in the new instrumentation
|
||||||
if features.IsEnabled(featuremgmt.FlagDisableHttpRequestHistogram) {
|
// since they dont make much sense. We should remove them later.
|
||||||
duration := time.Since(now).Nanoseconds() / int64(time.Millisecond)
|
histogram := httpRequestDurationHistogram.
|
||||||
metrics.MHttpRequestTotal.WithLabelValues(handler, code, method).Inc()
|
WithLabelValues(handler, code, req.Method)
|
||||||
metrics.MHttpRequestSummary.WithLabelValues(handler, code, method).Observe(float64(duration))
|
if traceID := tracing.TraceIDFromContext(c.Req.Context(), true); traceID != "" {
|
||||||
} else {
|
// Need to type-convert the Observer to an
|
||||||
// avoiding the sanitize functions for in the new instrumentation
|
// ExemplarObserver. This will always work for a
|
||||||
// since they dont make much sense. We should remove them later.
|
// HistogramVec.
|
||||||
histogram := httpRequestDurationHistogram.
|
histogram.(prometheus.ExemplarObserver).ObserveWithExemplar(
|
||||||
WithLabelValues(handler, code, req.Method)
|
time.Since(now).Seconds(), prometheus.Labels{"traceID": traceID},
|
||||||
if traceID := tracing.TraceIDFromContext(c.Req.Context(), true); traceID != "" {
|
)
|
||||||
// Need to type-convert the Observer to an
|
return
|
||||||
// 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())
|
|
||||||
}
|
}
|
||||||
|
histogram.Observe(time.Since(now).Seconds())
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case strings.HasPrefix(req.RequestURI, "/api/datasources/proxy"):
|
case strings.HasPrefix(req.RequestURI, "/api/datasources/proxy"):
|
||||||
@@ -142,10 +133,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
|
// 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
|
// currently 0, sanitizeCode will return 200, for consistency with behavior in
|
||||||
// the stdlib.
|
// the stdlib.
|
||||||
|
|||||||
@@ -117,11 +117,6 @@ var (
|
|||||||
State: FeatureStateAlpha,
|
State: FeatureStateAlpha,
|
||||||
RequiresDevMode: true,
|
RequiresDevMode: true,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Name: "disable_http_request_histogram",
|
|
||||||
Description: "Do not create histograms for http requests",
|
|
||||||
State: FeatureStateAlpha,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Name: "publicDashboards",
|
Name: "publicDashboards",
|
||||||
Description: "enables public access to dashboards",
|
Description: "enables public access to dashboards",
|
||||||
|
|||||||
@@ -87,10 +87,6 @@ const (
|
|||||||
// Show feature flags in the settings UI
|
// Show feature flags in the settings UI
|
||||||
FlagShowFeatureFlagsInUI = "showFeatureFlagsInUI"
|
FlagShowFeatureFlagsInUI = "showFeatureFlagsInUI"
|
||||||
|
|
||||||
// FlagDisableHttpRequestHistogram
|
|
||||||
// Do not create histograms for http requests
|
|
||||||
FlagDisableHttpRequestHistogram = "disable_http_request_histogram"
|
|
||||||
|
|
||||||
// FlagPublicDashboards
|
// FlagPublicDashboards
|
||||||
// enables public access to dashboards
|
// enables public access to dashboards
|
||||||
FlagPublicDashboards = "publicDashboards"
|
FlagPublicDashboards = "publicDashboards"
|
||||||
|
|||||||
@@ -18,14 +18,13 @@ import (
|
|||||||
|
|
||||||
func TestFeatureToggleFiles(t *testing.T) {
|
func TestFeatureToggleFiles(t *testing.T) {
|
||||||
legacyNames := map[string]bool{
|
legacyNames := map[string]bool{
|
||||||
"httpclientprovider_azure_auth": true,
|
"httpclientprovider_azure_auth": true,
|
||||||
"service-accounts": true,
|
"service-accounts": true,
|
||||||
"database_metrics": true,
|
"database_metrics": true,
|
||||||
"live-config": true,
|
"live-config": true,
|
||||||
"live-pipeline": true,
|
"live-pipeline": true,
|
||||||
"live-service-web-worker": true,
|
"live-service-web-worker": true,
|
||||||
"prometheus_azure_auth": true,
|
"prometheus_azure_auth": true,
|
||||||
"disable_http_request_histogram": true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("verify files", func(t *testing.T) {
|
t.Run("verify files", func(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user