mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Create Tracer once per PostingsForMatchersCache
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
parent
403abaee79
commit
46bf26e841
|
@ -53,6 +53,8 @@ func NewPostingsForMatchersCache(ttl time.Duration, maxItems int, maxBytes int64
|
||||||
|
|
||||||
timeNow: time.Now,
|
timeNow: time.Now,
|
||||||
postingsForMatchers: PostingsForMatchers,
|
postingsForMatchers: PostingsForMatchers,
|
||||||
|
|
||||||
|
tracer: otel.Tracer(""),
|
||||||
}
|
}
|
||||||
|
|
||||||
return b
|
return b
|
||||||
|
@ -75,10 +77,12 @@ type PostingsForMatchersCache struct {
|
||||||
timeNow func() time.Time
|
timeNow func() time.Time
|
||||||
// postingsForMatchers can be replaced for testing purposes
|
// postingsForMatchers can be replaced for testing purposes
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
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 := otel.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),
|
attribute.Bool("force", c.force),
|
||||||
))
|
))
|
||||||
|
@ -109,10 +113,11 @@ 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) {
|
||||||
ctx, span := otel.Tracer("").Start(ctx, "postingsForMatcherPromise.result")
|
ctx, span := p.tracer.Start(ctx, "postingsForMatcherPromise.result")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
@ -143,13 +148,15 @@ func (p *postingsForMatcherPromise) result(ctx context.Context) (index.Postings,
|
||||||
|
|
||||||
func (c *PostingsForMatchersCache) postingsForMatchersPromise(ctx context.Context, ix IndexPostingsReader, ms []*labels.Matcher) func(context.Context) (index.Postings, error) {
|
func (c *PostingsForMatchersCache) postingsForMatchersPromise(ctx context.Context, ix IndexPostingsReader, ms []*labels.Matcher) func(context.Context) (index.Postings, error) {
|
||||||
key := matchersKey(ms)
|
key := matchersKey(ms)
|
||||||
ctx, span := otel.Tracer("").Start(ctx, "PostingsForMatchersCache.postingsForMatchersPromise", trace.WithAttributes(
|
ctx, span := c.tracer.Start(ctx, "PostingsForMatchersCache.postingsForMatchersPromise", trace.WithAttributes(
|
||||||
attribute.String("cache_key", key),
|
attribute.String("cache_key", key),
|
||||||
))
|
))
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
promise := new(postingsForMatcherPromise)
|
promise := &postingsForMatcherPromise{
|
||||||
promise.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)
|
||||||
if loaded {
|
if loaded {
|
||||||
|
|
Loading…
Reference in a new issue