web: add slo group to request meta (#74765)

Signed-off-by: bergquist <carl.bergquist@gmail.com>
This commit is contained in:
Carl Bergquist
2023-09-22 11:52:28 +03:00
committed by GitHub
parent 61cdfba87a
commit e5fbc4a4cd
8 changed files with 71 additions and 14 deletions
+36 -2
View File
@@ -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
}
}