Commit graph

27 commits

Author SHA1 Message Date
Dimitar Dimitrov a14f40efb9
Rephrase return log line 2023-12-13 10:49:58 +01:00
Dimitar Dimitrov f4cd11318c
PostingsForMatchersCache: don't create new spans, reduce logging verbosity
Creating a new span for each promQL matcher for each query can end up being too verbose to navigate in grafana. This PR replaces the span with a trace log.

Overall starting a span was also expensive - according to profiles it's about 9% of the CPU of PostingsForMatchers and it's about 25% of the memory allocations. Adding events is about 2% of the CPU and ~5% of the allocations.

In addition to that it removes some log lines in `postingsForMatchersPromise` because I think they just log the same thing multiple times. I also removed some calls to AddEvent to amortize the cost of tracing further.
2023-12-12 18:46:59 +01:00
Arve Knudsen d1c7983f22 Don't end non-owned span
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2023-11-10 08:11:06 +01:00
Arve Knudsen e1e64f36c2
Apply suggestions from code review
Co-authored-by: Charles Korn <charleskorn@users.noreply.github.com>
2023-11-10 08:02:13 +01:00
Arve Knudsen 92606f3b52 Fix trace event
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2023-11-09 17:08:59 +01:00
Arve Knudsen 83b0ed7bdb Clean up
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2023-11-09 16:58:06 +01:00
Arve Knudsen ef70a6e6cf Allocate tracing attributes up front
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2023-11-09 16:57:56 +01:00
Arve Knudsen 46bf26e841 Create Tracer once per PostingsForMatchersCache
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2023-11-09 15:31:31 +01:00
Arve Knudsen 403abaee79 Set span status on error
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2023-11-09 15:31:31 +01:00
Arve Knudsen 7c313be3b5 Remove unnecessary event attributes
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2023-11-09 15:31:31 +01:00
Arve Knudsen 2aabf7cc2c Improve tracing
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2023-11-09 15:31:31 +01:00
Arve Knudsen 25e2c05a47 Implement review feedback
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2023-11-09 15:31:31 +01:00
Arve Knudsen 6c0910a289 Update tsdb/postings_for_matchers_cache.go
Co-authored-by: Charles Korn <charleskorn@users.noreply.github.com>
2023-11-09 15:31:31 +01:00
Arve Knudsen ca4cdeb1af Apply suggestions from code review
Co-authored-by: Charles Korn <charleskorn@users.noreply.github.com>
2023-11-09 15:31:31 +01:00
Arve Knudsen 8ece24ddb0 PostingsForMatchersCache: Add tracing
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2023-11-09 15:31:31 +01:00
György Krajcsovits 1149f7e9e1 Fix lint errors: dot at comment end
Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
2023-11-02 21:09:38 +01:00
Arve Knudsen efcd876b50 Ensure deterministic execution, for tests
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2023-10-20 16:21:26 +02:00
Charles Korn 6dcebc9e25
Don't allow cancelled contexts to poison the postings for matchers cache.
Signed-off-by: Charles Korn <charles.korn@grafana.com>
2023-10-20 15:48:14 +11:00
Oleg Zaytsev 5fdf784243 Refactor PostingsForMatcherCache promise
Extract promise payload as a struct, to make size calculation easier.

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
2023-09-28 11:44:03 +02:00
Marco Pracucci 9bcca44ac4
Addressed review comments
Signed-off-by: Marco Pracucci <marco@pracucci.com>
2023-09-28 10:32:19 +02:00
Marco Pracucci 0a8b79ad29
Do not measure size of sync.WaitGroup
Signed-off-by: Marco Pracucci <marco@pracucci.com>
2023-09-27 15:50:39 +02:00
Marco Pracucci 3c68ce252e
Add PostingsForMatchers cache size by bytes support
Signed-off-by: Marco Pracucci <marco@pracucci.com>
2023-09-27 15:25:39 +02:00
Arve Knudsen 85df1d4013 Merge remote-tracking branch 'prometheus/main' into chore/sync-prometheus
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2023-09-21 09:19:23 +02:00
Arve Knudsen e48d4e5835 Merge remote-tracking branch 'prometheus/main' into chore/sync-prometheus
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2023-09-18 09:29:42 +02:00
Oleg Zaytsev d23859dee2
Allow forcing usage of PostingsForMatchersCache
When out-of-order is enabled, queries go through both Head and OOOHead,
and they both execute the same PostingsForMatchers call, as memSeries
are shared for both.

In some cases these calls can be heavy, and also frequent. We can
deduplicate those calls by using the PostingsForMatchers cache that we
already use for query sharding.

The usage of this cache can skip a newly appended series in the results
for the duration of the ttl.

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
2022-12-28 13:44:10 +01:00
Peter Štibraný 294c155bb6 Merge remote-tracking branch 'upstream/main' into merge-upstream 2021-11-18 15:48:40 +01:00
Christian Simon 50c1060328
Implement PostingsCloner and implement promise/future pattern for PostingsForMatchers (#14)
* Fix tests not closing head/block properly

Close Head properly in TestWalRepair_DecodingError
Close Block properly in  TestReadIndexFormatV1

Co-authored-by: Christian Simon <simon@swine.de>
Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>

* Implement PostingsCloner

PostingsCloner allows obtaining independend clones of a Postings, that
can be used for subsequent calls.

Co-authored-by: Christian Simon <simon@swine.de>
Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>

* IndexReader.PostingsForMatchers() and implement Cache

IndexReader now offers the PostingsForMatchers functionality, which is
provided by PostingsForMatchersCache.

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
Co-authored-by: Marco Pracucci <marco@pracucci.com>
Co-authored-by: Peter Štibraný <peter.stibrany@grafana.com>

Co-authored-by: Oleg Zaytsev <mail@olegzaytsev.com>
Co-authored-by: Marco Pracucci <marco@pracucci.com>
Co-authored-by: Peter Štibraný <peter.stibrany@grafana.com>
2021-10-07 15:16:09 +02:00