From d68ae30bcdef769e5f47108575854cd60efb69b3 Mon Sep 17 00:00:00 2001 From: Nick Pillitteri <56quarters@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:31:59 -0400 Subject: [PATCH] Update to latest dskit commit (#8343) Specifically, pulls in https://github.com/grafana/dskit/pull/530 to fix an issue where we may inadvertently cache things forever. Signed-off-by: Nick Pillitteri --- CHANGELOG.md | 1 + go.mod | 2 +- go.sum | 4 +-- .../grafana/dskit/cache/memcached_client.go | 31 +++++++++++-------- .../grafana/dskit/middleware/logging.go | 4 ++- .../grafana/dskit/spanprofiler/tracer.go | 3 ++ vendor/modules.txt | 2 +- 7 files changed, 29 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17e59a6fabe..7481d936de6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -92,6 +92,7 @@ * [BUGFIX] Distributor: Don't discard time series with invalid exemplars, just drop affected exemplars. #8224 * [BUGFIX] Ingester: fixed in-memory series count when replaying a corrupted WAL. #8295 * [BUGFIX] Ingester: fix context cancellation handling when a query is busy looking up series in the TSDB index and `-blocks-storage.tsdb.head-postings-for-matchers-cache*` or `-blocks-storage.tsdb.block-postings-for-matchers-cache*` are in use. #8337 +* [BUGFIX] Querier: fix edge case where bucket indexes are sometimes cached forever instead of with the expected TTL. #8343 ### Mixin diff --git a/go.mod b/go.mod index ca607ef4d5c..938dc0774a6 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/golang/snappy v0.0.4 github.com/google/gopacket v1.1.19 github.com/gorilla/mux v1.8.1 - github.com/grafana/dskit v0.0.0-20240528015923-27d7d41066d3 + github.com/grafana/dskit v0.0.0-20240611171734-87c7e9e7a4fe github.com/grafana/e2e v0.1.2-0.20240118170847-db90b84177fc github.com/hashicorp/golang-lru v1.0.2 // indirect github.com/json-iterator/go v1.1.12 diff --git a/go.sum b/go.sum index 21b28d6a92f..037ac76d4db 100644 --- a/go.sum +++ b/go.sum @@ -507,8 +507,8 @@ github.com/grafana-tools/sdk v0.0.0-20220919052116-6562121319fc h1:PXZQA2WCxe85T github.com/grafana-tools/sdk v0.0.0-20220919052116-6562121319fc/go.mod h1:AHHlOEv1+GGQ3ktHMlhuTUwo3zljV3QJbC0+8o2kn+4= github.com/grafana/alerting v0.0.0-20240607182251-835aff588914 h1:WXLbSnnomltxdNcE20CI8RD8quZ/L0YpXP0WK+0S1BU= github.com/grafana/alerting v0.0.0-20240607182251-835aff588914/go.mod h1:U7Ta3K4T7jVgqGSYuPsfuPKHFiL2GbCZSHa3nHjmCos= -github.com/grafana/dskit v0.0.0-20240528015923-27d7d41066d3 h1:k8vINlI4w+RYc37NRwQlRe/IHYoEbu6KAe2XdGDeV1U= -github.com/grafana/dskit v0.0.0-20240528015923-27d7d41066d3/go.mod h1:HvSf3uf8Ps2vPpzHeAFyZTdUcbVr+Rxpq1xcx7J/muc= +github.com/grafana/dskit v0.0.0-20240611171734-87c7e9e7a4fe h1:PpBnljz9oYSp05pCcQl27n69cL9fNeFH+wkG/ga6oGs= +github.com/grafana/dskit v0.0.0-20240611171734-87c7e9e7a4fe/go.mod h1:HvSf3uf8Ps2vPpzHeAFyZTdUcbVr+Rxpq1xcx7J/muc= github.com/grafana/e2e v0.1.2-0.20240118170847-db90b84177fc h1:BW+LjKJDz0So5LI8UZfW5neWeKpSkWqhmGjQFzcFfLM= github.com/grafana/e2e v0.1.2-0.20240118170847-db90b84177fc/go.mod h1:JVmqPBe8A/pZWwRoJW5ZjyALeY5OXMzPl7LrVXOdZAI= github.com/grafana/goautoneg v0.0.0-20240607115440-f335c04c58ce h1:WI1olbgS+sEl77qxEYbmt9TgRUz7iLqmjh8lYPpGlKQ= diff --git a/vendor/github.com/grafana/dskit/cache/memcached_client.go b/vendor/github.com/grafana/dskit/cache/memcached_client.go index 5a5cdc23ebd..a22f8035449 100644 --- a/vendor/github.com/grafana/dskit/cache/memcached_client.go +++ b/vendor/github.com/grafana/dskit/cache/memcached_client.go @@ -315,22 +315,27 @@ func (c *MemcachedClient) Name() string { } func (c *MemcachedClient) SetMultiAsync(data map[string][]byte, ttl time.Duration) { - c.setMultiAsync(data, ttl, func(key string, buf []byte, ttl time.Duration) error { - return c.client.Set(&memcache.Item{ - Key: key, - Value: buf, - Expiration: int32(ttl.Seconds()), - }) - }) + c.setMultiAsync(data, ttl, c.setSingleItem) } func (c *MemcachedClient) SetAsync(key string, value []byte, ttl time.Duration) { - c.setAsync(key, value, ttl, func(key string, buf []byte, ttl time.Duration) error { - return c.client.Set(&memcache.Item{ - Key: key, - Value: buf, - Expiration: int32(ttl.Seconds()), - }) + c.setAsync(key, value, ttl, c.setSingleItem) +} + +func (c *MemcachedClient) setSingleItem(key string, value []byte, ttl time.Duration) error { + ttlSeconds := int32(ttl.Seconds()) + // If a TTL of exactly 0 is passed, we honor it and pass it to Memcached which will + // interpret it as an infinite TTL. However, if we get a non-zero TTL that is truncated + // to 0 seconds, we discard the update since the caller didn't intend to set an infinite + // TTL. + if ttl != 0 && ttlSeconds <= 0 { + return nil + } + + return c.client.Set(&memcache.Item{ + Key: key, + Value: value, + Expiration: ttlSeconds, }) } diff --git a/vendor/github.com/grafana/dskit/middleware/logging.go b/vendor/github.com/grafana/dskit/middleware/logging.go index fe00d3a8284..c2306292b3f 100644 --- a/vendor/github.com/grafana/dskit/middleware/logging.go +++ b/vendor/github.com/grafana/dskit/middleware/logging.go @@ -56,9 +56,11 @@ func NewLogMiddleware(log log.Logger, logRequestHeaders bool, logRequestAtInfoLe // logWithRequest information from the request and context as fields. func (l Log) logWithRequest(r *http.Request) log.Logger { localLog := l.Log - traceID, ok := tracing.ExtractTraceID(r.Context()) + traceID, ok := tracing.ExtractSampledTraceID(r.Context()) if ok { localLog = log.With(localLog, "trace_id", traceID) + } else if traceID != "" { + localLog = log.With(localLog, "trace_id_unsampled", traceID) } if l.SourceIPs != nil { diff --git a/vendor/github.com/grafana/dskit/spanprofiler/tracer.go b/vendor/github.com/grafana/dskit/spanprofiler/tracer.go index c28b52b11d4..e4ed2974a4a 100644 --- a/vendor/github.com/grafana/dskit/spanprofiler/tracer.go +++ b/vendor/github.com/grafana/dskit/spanprofiler/tracer.go @@ -41,6 +41,9 @@ func (t *tracer) StartSpan(operationName string, opts ...opentracing.StartSpanOp if !ok { return span } + if !spanCtx.IsSampled() { + return span + } // pprof labels are attached only once, at the span root level. if !isRootSpan(opts...) { return span diff --git a/vendor/modules.txt b/vendor/modules.txt index a1d78efea34..b21c6a5e17d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -597,7 +597,7 @@ github.com/grafana/alerting/receivers/webex github.com/grafana/alerting/receivers/webhook github.com/grafana/alerting/receivers/wecom github.com/grafana/alerting/templates -# github.com/grafana/dskit v0.0.0-20240528015923-27d7d41066d3 +# github.com/grafana/dskit v0.0.0-20240611171734-87c7e9e7a4fe ## explicit; go 1.20 github.com/grafana/dskit/backoff github.com/grafana/dskit/ballast