web: add slo group to request meta (#74765)
Signed-off-by: bergquist <carl.bergquist@gmail.com>
This commit is contained in:
@@ -45,6 +45,10 @@ func RequestMetrics(features featuremgmt.FeatureToggles, cfg *setting.Cfg, promR
|
||||
histogramLabels = append(histogramLabels, "team")
|
||||
}
|
||||
|
||||
if features.IsEnabled(featuremgmt.FlagHttpSLOLevels) {
|
||||
histogramLabels = append(histogramLabels, "slo_group")
|
||||
}
|
||||
|
||||
httpRequestDurationHistogram := prometheus.NewHistogramVec(
|
||||
prometheus.HistogramOpts{
|
||||
Namespace: "grafana",
|
||||
@@ -95,6 +99,10 @@ func RequestMetrics(features featuremgmt.FeatureToggles, cfg *setting.Cfg, promR
|
||||
labelValues = append(labelValues, rmd.Team)
|
||||
}
|
||||
|
||||
if features.IsEnabled(featuremgmt.FlagHttpSLOLevels) {
|
||||
labelValues = append(labelValues, string(rmd.SLOGroup))
|
||||
}
|
||||
|
||||
// avoiding the sanitize functions for in the new instrumentation
|
||||
// since they dont make much sense. We should remove them later.
|
||||
histogram := httpRequestDurationHistogram.
|
||||
|
||||
@@ -20,13 +20,38 @@ const (
|
||||
StatusSourceDownstream StatusSource = "downstream"
|
||||
)
|
||||
|
||||
type rMDContextKey struct{}
|
||||
|
||||
type RequestMetaData struct {
|
||||
Team string
|
||||
StatusSource StatusSource
|
||||
SLOGroup SLOGroup
|
||||
}
|
||||
|
||||
type SLOGroup string
|
||||
|
||||
const (
|
||||
// SLOGroupHighFast is the default slo group for handlers in Grafana
|
||||
// Most handlers should respond quickly
|
||||
SLOGroupHighFast SLOGroup = "high-fast"
|
||||
|
||||
// SLOGroupHighMedium is used for handlers that might take some
|
||||
// time to respond.
|
||||
SLOGroupHighMedium SLOGroup = "high-medium"
|
||||
|
||||
// SLOGroupHighSlow is used by handlers that proxies requests downstream.
|
||||
// We expect an high successrate but without latency garantess
|
||||
SLOGroupHighSlow SLOGroup = "high-slow"
|
||||
|
||||
// SLOGroupLow should only be used for experimental features
|
||||
// that might not be stable enough for our normal SLO
|
||||
SLOGroupLow SLOGroup = "low"
|
||||
|
||||
// SLOGroupNone means that errors are expect for this handler and
|
||||
// it should not be included in the SLO.
|
||||
SLOGroupNone SLOGroup = "none"
|
||||
)
|
||||
|
||||
type rMDContextKey struct{}
|
||||
|
||||
var requestMetaDataContextKey = rMDContextKey{}
|
||||
|
||||
// SetupRequestMetadata injects defaul request metadata values
|
||||
@@ -96,5 +121,14 @@ func defaultRequestMetadata() RequestMetaData {
|
||||
return RequestMetaData{
|
||||
Team: TeamCore,
|
||||
StatusSource: StatusSourceServer,
|
||||
SLOGroup: SLOGroupHighFast,
|
||||
}
|
||||
}
|
||||
|
||||
// SetSLOGroup creates an middleware that sets the SLOGroup for the request
|
||||
func SetSLOGroup(lvl SLOGroup) web.Handler {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
v := GetRequestMetaData(r.Context())
|
||||
v.SLOGroup = lvl
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user