Skip to content

Commit c7fa62f

Browse files
updated deps, changed log formatting
1 parent 894d69b commit c7fa62f

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ require (
3636
github.com/grpc-ecosystem/go-grpc-middleware/providers/kit/v2 v2.0.0-20201002093600-73cf2ae9d891
3737
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.2.0.20201207153454-9f6bf00c00a7
3838
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
39-
github.com/hashicorp/golang-lru v0.6.0
39+
github.com/hashicorp/golang-lru/v2 v2.0.7
4040
github.com/jpillora/backoff v1.0.0
4141
github.com/json-iterator/go v1.1.12
4242
github.com/klauspost/compress v1.17.7

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,7 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
11531153
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
11541154
github.com/hashicorp/golang-lru v0.6.0 h1:uL2shRDx7RTrOrTCUZEGP/wJUFiUI8QT6E7z5o8jga4=
11551155
github.com/hashicorp/golang-lru v0.6.0/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
1156+
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
11561157
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
11571158
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
11581159
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=

internal/cortex/frontend/transport/handler.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func NewHandler(cfg HandlerConfig, roundTripper http.RoundTripper, log log.Logge
8181
LruCache, err = lru.New(cfg.FailedQueryCacheCapacity)
8282
if err != nil {
8383
LruCache = nil
84-
level.Error(log).Log("msg", "Failed to create LruCache", "err", err)
84+
level.Warn(log).Log("msg", "Failed to create LruCache", "error", err)
8585
}
8686
}
8787

@@ -142,7 +142,6 @@ func (f *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
142142
var ctx context.Context
143143
stats, ctx = querier_stats.ContextWithEmptyStats(r.Context())
144144
r = r.WithContext(ctx)
145-
level.Info(util_log.WithContext(r.Context(), f.log)).Log("msg", "Query Stats Enabled")
146145
}
147146

148147
defer func() {
@@ -165,7 +164,11 @@ func (f *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
165164
// Check if query in cache and whether value exceeds time range length.
166165
if value, ok := f.lruCache.Get(queryExpressionNormalized); ok && value.(int) >= queryExpressionRangeLength {
167166
w.WriteHeader(http.StatusForbidden)
168-
level.Warn(util_log.WithContext(r.Context(), f.log)).Log("msg", "Retrieved query from cache", "Query expression", queryExpressionNormalized)
167+
level.Info(util_log.WithContext(r.Context(), f.log)).Log(
168+
"msg", "Retrieved query from cache",
169+
"normalized_query", queryExpressionNormalized,
170+
"range_seconds", queryExpressionRangeLength,
171+
)
169172
f.cachedHits.Inc()
170173
return
171174
}
@@ -227,7 +230,10 @@ func (f *Handler) updateFailedQueryCache(err error, queryExpressionNormalized st
227230
// Checking if error code extracted successfully.
228231
if codeExtract == nil || len(codeExtract) < 2 {
229232
level.Error(util_log.WithContext(r.Context(), f.log)).Log(
230-
"msg", "Error string regex conversion error")
233+
"msg", "Error string regex conversion error",
234+
"normalized_query", queryExpressionNormalized,
235+
"range_seconds", queryExpressionRangeLength,
236+
"error", err)
231237
return
232238
}
233239

@@ -237,14 +243,21 @@ func (f *Handler) updateFailedQueryCache(err error, queryExpressionNormalized st
237243
// Checking if error code extracted properly from string.
238244
if strConvError != nil {
239245
level.Error(util_log.WithContext(r.Context(), f.log)).Log(
240-
"msg", "String to int conversion error")
246+
"msg", "String to int conversion error",
247+
"normalized_query", queryExpressionNormalized,
248+
"range_seconds", queryExpressionRangeLength,
249+
"error", err)
241250
return
242251
}
243252

244253
// If error should be cached, store it in cache.
245254
if !isCacheableError(errCode) {
246255
level.Debug(util_log.WithContext(r.Context(), f.log)).Log(
247-
"msg", "Query not cached due to non-cacheable error code")
256+
"msg", "Query not cached due to non-cacheable error code",
257+
"normalized_query", queryExpressionNormalized,
258+
"range_seconds", queryExpressionRangeLength,
259+
"error", err,
260+
)
248261
return
249262
}
250263

@@ -257,7 +270,12 @@ func (f *Handler) updateFailedQueryCache(err error, queryExpressionNormalized st
257270
}
258271

259272
level.Debug(util_log.WithContext(r.Context(), f.log)).Log(
260-
"msg", "Query cached", "response ")
273+
"msg", "Cached a failed query",
274+
"normalized_query", queryExpressionNormalized,
275+
"range_seconds", queryExpressionRangeLength,
276+
"error", err,
277+
)
278+
261279
}
262280

263281
// isCacheableError Returns true if response code is in pre-defined cacheable errors list, else returns false.

0 commit comments

Comments
 (0)