Loki: Add X-Query-Tags header for logs sample and data sample (#62333)

This commit is contained in:
Ivana Huckova
2023-01-27 16:41:40 +01:00
committed by GitHub
parent 9453bec819
commit d0e95f8c95
8 changed files with 115 additions and 38 deletions

View File

@ -85,8 +85,11 @@ func makeDataRequest(ctx context.Context, lokiDsUrl string, query lokiQuery) (*h
return nil, err
}
if query.VolumeQuery {
req.Header.Set("X-Query-Tags", "Source=logvolhist")
if query.SupportingQueryType != SupportingQueryNone {
value := getSupportingQueryHeaderValue(req, query.SupportingQueryType)
if value != "" {
req.Header.Set("X-Query-Tags", "Source="+value)
}
}
return req, nil
@ -223,3 +226,18 @@ func (api *LokiAPI) RawQuery(ctx context.Context, resourcePath string) (RawLokiR
return encodedBytes, nil
}
func getSupportingQueryHeaderValue(req *http.Request, supportingQueryType SupportingQueryType) string {
value := ""
switch supportingQueryType {
case SupportingQueryLogsVolume:
value = "logvolhist"
case SupportingQueryLogsSample:
value = "logsample"
case SupportingQueryDataSample:
value = "datasample"
default: //ignore
}
return value
}