mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Improve tracing
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
parent
25e2c05a47
commit
2aabf7cc2c
|
@ -77,12 +77,7 @@ type PostingsForMatchersCache struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
var matcherStrs []string
|
|
||||||
for _, m := range ms {
|
|
||||||
matcherStrs = append(matcherStrs, m.String())
|
|
||||||
}
|
|
||||||
ctx, span := otel.Tracer("").Start(ctx, "PostingsForMatchersCache.PostingsForMatchers", trace.WithAttributes(
|
ctx, span := otel.Tracer("").Start(ctx, "PostingsForMatchersCache.PostingsForMatchers", trace.WithAttributes(
|
||||||
attribute.StringSlice("matchers", matcherStrs),
|
|
||||||
attribute.Bool("concurrent", concurrent),
|
attribute.Bool("concurrent", concurrent),
|
||||||
attribute.Bool("force", c.force),
|
attribute.Bool("force", c.force),
|
||||||
))
|
))
|
||||||
|
@ -94,6 +89,8 @@ func (c *PostingsForMatchersCache) PostingsForMatchers(ctx context.Context, ix I
|
||||||
span.RecordError(err)
|
span.RecordError(err)
|
||||||
return p, err
|
return p, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
span.AddEvent("using cache")
|
||||||
c.expire()
|
c.expire()
|
||||||
p, err := c.postingsForMatchersPromise(ctx, ix, ms)(ctx)
|
p, err := c.postingsForMatchersPromise(ctx, ix, ms)(ctx)
|
||||||
span.RecordError(err)
|
span.RecordError(err)
|
||||||
|
@ -138,26 +135,24 @@ 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) {
|
||||||
ctx, span := otel.Tracer("").Start(ctx, "PostingsForMatchersCache.postingsForMatchersPromise")
|
key := matchersKey(ms)
|
||||||
|
ctx, span := otel.Tracer("").Start(ctx, "PostingsForMatchersCache.postingsForMatchersPromise", trace.WithAttributes(
|
||||||
|
attribute.String("cache_key", key),
|
||||||
|
))
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
promise := new(postingsForMatcherPromise)
|
promise := new(postingsForMatcherPromise)
|
||||||
promise.done = make(chan struct{})
|
promise.done = make(chan struct{})
|
||||||
|
|
||||||
key := matchersKey(ms)
|
|
||||||
oldPromise, loaded := c.calls.LoadOrStore(key, promise)
|
oldPromise, loaded := c.calls.LoadOrStore(key, promise)
|
||||||
if loaded {
|
if loaded {
|
||||||
// promise was not stored, we return a previously stored promise, that's possibly being fulfilled in another goroutine
|
// promise was not stored, we return a previously stored promise, that's possibly being fulfilled in another goroutine
|
||||||
span.AddEvent("using cached postingsForMatchers promise", trace.WithAttributes(
|
span.AddEvent("using cached postingsForMatchers promise")
|
||||||
attribute.String("key", key),
|
|
||||||
))
|
|
||||||
close(promise.done)
|
close(promise.done)
|
||||||
return oldPromise.(*postingsForMatcherPromise).result
|
return oldPromise.(*postingsForMatcherPromise).result
|
||||||
}
|
}
|
||||||
|
|
||||||
span.AddEvent("no postingsForMatchers promise in cache, executing query", trace.WithAttributes(
|
span.AddEvent("no postingsForMatchers promise in cache, executing query")
|
||||||
attribute.String("key", key)),
|
|
||||||
)
|
|
||||||
|
|
||||||
// promise was stored, close its channel after fulfilment
|
// promise was stored, close its channel after fulfilment
|
||||||
defer close(promise.done)
|
defer close(promise.done)
|
||||||
|
|
Loading…
Reference in a new issue