mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Clean up
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
parent
e3b8667fb1
commit
83b0ed7bdb
|
@ -47,7 +47,6 @@ func NewPostingsForMatchersCache(ttl time.Duration, maxItems int, maxBytes int64
|
||||||
cached: list.New(),
|
cached: list.New(),
|
||||||
|
|
||||||
ttl: ttl,
|
ttl: ttl,
|
||||||
ttlAttrib: attribute.Stringer("ttl", ttl),
|
|
||||||
maxItems: maxItems,
|
maxItems: maxItems,
|
||||||
maxBytes: maxBytes,
|
maxBytes: maxBytes,
|
||||||
force: force,
|
force: force,
|
||||||
|
@ -56,6 +55,8 @@ func NewPostingsForMatchersCache(ttl time.Duration, maxItems int, maxBytes int64
|
||||||
postingsForMatchers: PostingsForMatchers,
|
postingsForMatchers: PostingsForMatchers,
|
||||||
|
|
||||||
tracer: otel.Tracer(""),
|
tracer: otel.Tracer(""),
|
||||||
|
ttlAttrib: attribute.Stringer("ttl", ttl),
|
||||||
|
forceAttrib: attribute.Bool("force", force),
|
||||||
}
|
}
|
||||||
|
|
||||||
return b
|
return b
|
||||||
|
@ -70,7 +71,6 @@ type PostingsForMatchersCache struct {
|
||||||
cachedBytes int64
|
cachedBytes int64
|
||||||
|
|
||||||
ttl time.Duration
|
ttl time.Duration
|
||||||
ttlAttrib attribute.KeyValue
|
|
||||||
maxItems int
|
maxItems int
|
||||||
maxBytes int64
|
maxBytes int64
|
||||||
force bool
|
force bool
|
||||||
|
@ -81,12 +81,16 @@ type PostingsForMatchersCache struct {
|
||||||
postingsForMatchers func(ctx context.Context, ix IndexPostingsReader, ms ...*labels.Matcher) (index.Postings, error)
|
postingsForMatchers func(ctx context.Context, ix IndexPostingsReader, ms ...*labels.Matcher) (index.Postings, error)
|
||||||
|
|
||||||
tracer trace.Tracer
|
tracer trace.Tracer
|
||||||
|
// Preallocated for performance
|
||||||
|
ttlAttrib attribute.KeyValue
|
||||||
|
forceAttrib attribute.KeyValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *PostingsForMatchersCache) PostingsForMatchers(ctx context.Context, ix IndexPostingsReader, concurrent bool, ms ...*labels.Matcher) (index.Postings, error) {
|
func (c *PostingsForMatchersCache) PostingsForMatchers(ctx context.Context, ix IndexPostingsReader, concurrent bool, ms ...*labels.Matcher) (index.Postings, error) {
|
||||||
ctx, span := c.tracer.Start(ctx, "PostingsForMatchersCache.PostingsForMatchers", trace.WithAttributes(
|
ctx, span := c.tracer.Start(ctx, "PostingsForMatchersCache.PostingsForMatchers", trace.WithAttributes(
|
||||||
attribute.Bool("concurrent", concurrent),
|
attribute.Bool("concurrent", concurrent),
|
||||||
attribute.Bool("force", c.force),
|
c.ttlAttrib,
|
||||||
|
c.forceAttrib,
|
||||||
))
|
))
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
|
@ -115,7 +119,6 @@ type postingsForMatcherPromise struct {
|
||||||
|
|
||||||
cloner *index.PostingsCloner
|
cloner *index.PostingsCloner
|
||||||
err error
|
err error
|
||||||
tracer trace.Tracer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *postingsForMatcherPromise) result(ctx context.Context) (index.Postings, error) {
|
func (p *postingsForMatcherPromise) result(ctx context.Context) (index.Postings, error) {
|
||||||
|
@ -154,7 +157,6 @@ func (c *PostingsForMatchersCache) postingsForMatchersPromise(ctx context.Contex
|
||||||
|
|
||||||
promise := &postingsForMatcherPromise{
|
promise := &postingsForMatcherPromise{
|
||||||
done: make(chan struct{}),
|
done: make(chan struct{}),
|
||||||
tracer: c.tracer,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
oldPromise, loaded := c.calls.LoadOrStore(key, promise)
|
oldPromise, loaded := c.calls.LoadOrStore(key, promise)
|
||||||
|
@ -254,9 +256,7 @@ func (c *PostingsForMatchersCache) created(ctx context.Context, key string, ts t
|
||||||
span := trace.SpanFromContext(ctx)
|
span := trace.SpanFromContext(ctx)
|
||||||
|
|
||||||
if c.ttl <= 0 {
|
if c.ttl <= 0 {
|
||||||
span.AddEvent("deleting cached promise since c.ttl <= 0", trace.WithAttributes(
|
span.AddEvent("deleting cached promise since c.ttl <= 0")
|
||||||
c.ttlAttrib,
|
|
||||||
))
|
|
||||||
c.calls.Delete(key)
|
c.calls.Delete(key)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -271,7 +271,6 @@ func (c *PostingsForMatchersCache) created(ctx context.Context, key string, ts t
|
||||||
})
|
})
|
||||||
c.cachedBytes += sizeBytes
|
c.cachedBytes += sizeBytes
|
||||||
span.AddEvent("added cached value to expiry queue", trace.WithAttributes(
|
span.AddEvent("added cached value to expiry queue", trace.WithAttributes(
|
||||||
c.ttlAttrib,
|
|
||||||
attribute.Stringer("timestamp", ts),
|
attribute.Stringer("timestamp", ts),
|
||||||
attribute.Int64("size in bytes", sizeBytes),
|
attribute.Int64("size in bytes", sizeBytes),
|
||||||
attribute.Int64("cached bytes", c.cachedBytes),
|
attribute.Int64("cached bytes", c.cachedBytes),
|
||||||
|
|
Loading…
Reference in a new issue