mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
* consoles: exclude iowait and steal from CPU Utilisation 'iowait' and 'steal' indicate specific idle/wait states, which shouldn't be counted into CPU Utilisation. Also see https://github.com/prometheus-operator/kube-prometheus/pull/796 and https://github.com/kubernetes-monitoring/kubernetes-mixin/pull/667. Per the iostat man page: %idle Show the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request. %iowait Show the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request. %steal Show the percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor. Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com> * tsdb: shrink txRing with smaller integers 4 billion active transactions ought to be enough for anyone. Signed-off-by: Bryan Boreham <bjboreham@gmail.com> * tsdb: create isolation transaction slice on demand When Prometheus restarts it creates every series read in from the WAL, but many of those series will be finished, and never receive any more samples. By defering allocation of the txRing slice to when it is first needed, we save 32 bytes per stale series. Signed-off-by: Bryan Boreham <bjboreham@gmail.com> * add cluster variable to Overview dashboard Signed-off-by: Erik Sommer <ersotech@posteo.de> * promql: simplify Native Histogram arithmetics Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com> * Cut 2.49.0-rc.0 (#13270) * Cut 2.49.0-rc.0 Signed-off-by: bwplotka <bwplotka@gmail.com> * Removed the duplicate. Signed-off-by: bwplotka <bwplotka@gmail.com> --------- Signed-off-by: bwplotka <bwplotka@gmail.com> * Add unit protobuf parser Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it> * Go on adding protobuf parsing for unit Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it> * ui: create a reproduction for https://github.com/prometheus/prometheus/issues/13292 Signed-off-by: machine424 <ayoubmrini424@gmail.com> * Get conditional right Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it> * Get VM Scale Set NIC (#13283) Calling `*armnetwork.InterfacesClient.Get()` doesn't work for Scale Set VM NIC, because these use a different Resource ID format. Use `*armnetwork.InterfacesClient.GetVirtualMachineScaleSetNetworkInterface()` instead. This needs both the scale set name and the instance ID, so add an `InstanceID` field to the `virtualMachine` struct. `InstanceID` is empty for a VM that isn't a ScaleSetVM. Signed-off-by: Daniel Nicholls <daniel.nicholls@resdiary.com> * Cut v2.49.0-rc.1 Signed-off-by: bwplotka <bwplotka@gmail.com> * Delete debugging lines, amend error message for unit Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it> * Correct order in error message Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it> * Consider storage.ErrTooOldSample as non-retryable Signed-off-by: Daniel Kerbel <nmdanny@gmail.com> * scrape_test.go: Increase scrape interval in TestScrapeLoopCache to reduce potential flakiness Signed-off-by: machine424 <ayoubmrini424@gmail.com> * Avoid creating string for suffix, consider counters without _total suffix Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it> * build(deps): bump github.com/prometheus/client_golang Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.17.0 to 1.18.0. - [Release notes](https://github.com/prometheus/client_golang/releases) - [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md) - [Commits](https://github.com/prometheus/client_golang/compare/v1.17.0...v1.18.0) --- updated-dependencies: - dependency-name: github.com/prometheus/client_golang dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump actions/setup-node from 3.8.1 to 4.0.1 Bumps [actions/setup-node](https://github.com/actions/setup-node) from 3.8.1 to 4.0.1. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](5e21ff4d9b...b39b52d121
) --- updated-dependencies: - dependency-name: actions/setup-node dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * scripts: sort file list in embed directive Otherwise the resulting string depends on find, which afaict depends on the underlying filesystem. A stable file list make it easier to detect UI changes in downstreams that need to track UI assets. Signed-off-by: Jan Fajerski <jfajersk@redhat.com> * Fix DataTableProps['data'] for resultType string Signed-off-by: Kevin Mingtarja <kevin.mingtarja@gmail.com> * Fix handling of scalar and string in isHeatmapData Signed-off-by: Kevin Mingtarja <kevin.mingtarja@gmail.com> * build(deps): bump github.com/influxdata/influxdb Bumps [github.com/influxdata/influxdb](https://github.com/influxdata/influxdb) from 1.11.2 to 1.11.4. - [Release notes](https://github.com/influxdata/influxdb/releases) - [Commits](https://github.com/influxdata/influxdb/compare/v1.11.2...v1.11.4) --- updated-dependencies: - dependency-name: github.com/influxdata/influxdb dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump github.com/prometheus/prometheus Bumps [github.com/prometheus/prometheus](https://github.com/prometheus/prometheus) from 0.48.0 to 0.48.1. - [Release notes](https://github.com/prometheus/prometheus/releases) - [Changelog](https://github.com/prometheus/prometheus/blob/main/CHANGELOG.md) - [Commits](https://github.com/prometheus/prometheus/compare/v0.48.0...v0.48.1) --- updated-dependencies: - dependency-name: github.com/prometheus/prometheus dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Bump client_golang to v1.18.0 (#13373) Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com> * Drop old inmemory samples (#13002) * Drop old inmemory samples Co-authored-by: Paschalis Tsilias <paschalis.tsilias@grafana.com> Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com> Signed-off-by: Marc Tuduri <marctc@protonmail.com> * Avoid copying timeseries when the feature is disabled Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com> Signed-off-by: Marc Tuduri <marctc@protonmail.com> * Run gofmt Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com> Signed-off-by: Marc Tuduri <marctc@protonmail.com> * Clarify docs Signed-off-by: Marc Tuduri <marctc@protonmail.com> * Add more logging info Signed-off-by: Marc Tuduri <marctc@protonmail.com> * Remove loggers Signed-off-by: Marc Tuduri <marctc@protonmail.com> * optimize function and add tests Signed-off-by: Marc Tuduri <marctc@protonmail.com> * Simplify filter Signed-off-by: Marc Tuduri <marctc@protonmail.com> * rename var Signed-off-by: Marc Tuduri <marctc@protonmail.com> * Update help info from metrics Signed-off-by: Marc Tuduri <marctc@protonmail.com> * use metrics to keep track of drop elements during buildWriteRequest Signed-off-by: Marc Tuduri <marctc@protonmail.com> * rename var in tests Signed-off-by: Marc Tuduri <marctc@protonmail.com> * pass time.Now as parameter Signed-off-by: Marc Tuduri <marctc@protonmail.com> * Change buildwriterequest during retries Signed-off-by: Marc Tuduri <marctc@protonmail.com> * Revert "Remove loggers" This reverts commit 54f91dfcae20488944162335ab4ad8be459df1ab. Signed-off-by: Marc Tuduri <marctc@protonmail.com> * use log level debug for loggers Signed-off-by: Marc Tuduri <marctc@protonmail.com> * Fix linter Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com> * Remove noisy debug-level logs; add 'reason' label to drop metrics Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com> * Remove accidentally committed files Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com> * Propagate logger to buildWriteRequest to log dropped data Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com> * Fix docs comment Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com> * Make drop reason more specific Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com> * Remove unnecessary pass of logger Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com> * Use snake_case for reason label Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com> * Fix dropped samples metric Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com> --------- Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com> Signed-off-by: Marc Tuduri <marctc@protonmail.com> Signed-off-by: Paschalis Tsilias <tpaschalis@users.noreply.github.com> Co-authored-by: Paschalis Tsilias <paschalis.tsilias@grafana.com> Co-authored-by: Paschalis Tsilias <tpaschalis@users.noreply.github.com> * fix(discovery): allow requireUpdate util to timeout in discovery/file/file_test.go. The loop ran indefinitely if the condition isn't met. Before, each iteration created a new timer channel which was always outpaced by the other timer channel with smaller duration. minor detail: There was a memory leak: resources of the ~10 previous timers were constantly kept. With the fix, we may keep the resources of one timer around for defaultWait but this isn't worth the changes to make it right. Signed-off-by: machine424 <ayoubmrini424@gmail.com> * Merge pull request #13371 from kevinmingtarja/fix-isHeatmapData ui: fix handling of scalar and string in isHeatmapData * tsdb/{index,compact}: allow using custom postings encoding format (#13242) * tsdb/{index,compact}: allow using custom postings encoding format We would like to experiment with a different postings encoding format in Thanos so in this change I am proposing adding another argument to `NewWriter` which would allow users to change the format if needed. Also, wire the leveled compactor so that it would be possible to change the format there too. Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com> * tsdb/compact: use a struct for leveled compactor options As discussed on Slack, let's use a struct for the options in leveled compactor. Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com> * tsdb: make changes after Bryan's review - Make changes less intrusive - Turn the postings encoder type into a function - Add NewWriterWithEncoder() Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com> --------- Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com> * Cut 2.49.0-rc.2 Signed-off-by: bwplotka <bwplotka@gmail.com> * build(deps): bump actions/setup-go from 3.5.0 to 5.0.0 in /scripts (#13362) Bumps [actions/setup-go](https://github.com/actions/setup-go) from 3.5.0 to 5.0.0. - [Release notes](https://github.com/actions/setup-go/releases) - [Commits](6edd4406fa...0c52d547c9
) --- updated-dependencies: - dependency-name: actions/setup-go dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump github/codeql-action from 2.22.8 to 3.22.12 (#13358) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2.22.8 to 3.22.12. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](407ffafae6...012739e508
) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * put @nexucis has a release shepherd (#13383) Signed-off-by: Augustin Husson <augustin.husson@amadeus.com> * Add analyze histograms command to promtool (#12331) Add `query analyze` command to promtool This command analyzes the buckets of classic and native histograms, based on data queried from the Prometheus query API, i.e. it doesn't require direct access to the TSDB files. Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com> --------- Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com> * included instance in all necessary descriptions Signed-off-by: Erik Sommer <ersotech@posteo.de> * tsdb/compact: fix passing merge func Fixing a very small logical problem I've introduced :(. Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com> * tsdb: add enable overlapping compaction This functionality is needed in downstream projects because they have a separate component that does compaction. Upstreaming7c8e9a2a76/tsdb/compact.go (L323-L325)
. Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com> * Cut 2.49.0 Signed-off-by: bwplotka <bwplotka@gmail.com> * promtool: allow setting multiple matchers to "promtool tsdb dump" command. (#13296) Conditions are ANDed inside the same matcher but matchers are ORed Including unit tests for "promtool tsdb dump". Refactor some matchers scraping utils. Signed-off-by: machine424 <ayoubmrini424@gmail.com> * Fixed changelog Signed-off-by: bwplotka <bwplotka@gmail.com> * tsdb/main: wire "EnableOverlappingCompaction" to tsdb.Options (#13398) This added the https://github.com/prometheus/prometheus/pull/13393 "EnableOverlappingCompaction" parameter to the compactor code but not to the tsdb.Options. I forgot about that. Add it to `tsdb.Options` too and set it to `true` in Prometheus. Copy/paste the description from https://github.com/prometheus/prometheus/pull/13393#issuecomment-1891787986 Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com> * Issue #13268: fix quality value in accept header Signed-off-by: Kumar Kalpadiptya Roy <kalpadiptya.roy@outlook.com> * Cut 2.49.1 with scrape q= bugfix. Signed-off-by: bwplotka <bwplotka@gmail.com> * Cut 2.49.1 web package. Signed-off-by: bwplotka <bwplotka@gmail.com> * Restore more efficient version of NewPossibleNonCounterInfo annotation (#13022) Restore more efficient version of NewPossibleNonCounterInfo annotation Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com> --------- Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com> * Fix regressions introduced by #13242 Signed-off-by: Marco Pracucci <marco@pracucci.com> * fix slice copy in 1.20 (#13389) The slices package is added to the standard library in Go 1.21; we need to import from the exp area to maintain compatibility with Go 1.20. Signed-off-by: tyltr <tylitianrui@126.com> * Docs: Query Basics: link to rate (#10538) Co-authored-by: Julien Pivotto <roidelapluie@o11y.eu> * chore(kubernetes): check preconditions earlier and avoid unnecessary checks or iterations Signed-off-by: machine424 <ayoubmrini424@gmail.com> * Examples: link to `rate` for new users (#10535) * Examples: link to `rate` for new users Signed-off-by: Ted Robertson 10043369+tredondo@users.noreply.github.com Co-authored-by: Bryan Boreham <bjboreham@gmail.com> * promql: use natural sort in sort_by_label and sort_by_label_desc (#13411) These functions are intended for humans, as robots can already sort the results however they please. Humans like things sorted "naturally": * https://blog.codinghorror.com/sorting-for-humans-natural-sort-order/ A similar thing has been done to Grafana, which is also used by humans: * https://github.com/grafana/grafana/pull/78024 * https://github.com/grafana/grafana/pull/78494 Signed-off-by: Ivan Babrou <github@ivan.computer> * TestLabelValuesWithMatchers: Add test case Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * remove obsolete build tag Signed-off-by: tyltr <tylitianrui@126.com> * Upgrade some golang dependencies for resty 2.11 Signed-off-by: Israel Blancas <iblancasa@gmail.com> * Native Histograms: support `native_histogram_min_bucket_factor` in scrape_config (#13222) Native Histograms: support native_histogram_min_bucket_factor in scrape_config --------- Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com> Signed-off-by: Björn Rabenstein <github@rabenste.in> Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com> Co-authored-by: Björn Rabenstein <github@rabenste.in> * Add warnings for histogramRate applied with isCounter not matching counter/gauge histogram (#13392) Add warnings for histogramRate applied with isCounter not matching counter/gauge histogram --------- Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com> * Minor fixes to otlp vendor update script Signed-off-by: Goutham <gouthamve@gmail.com> * build(deps): bump github.com/hetznercloud/hcloud-go/v2 Bumps [github.com/hetznercloud/hcloud-go/v2](https://github.com/hetznercloud/hcloud-go) from 2.4.0 to 2.6.0. - [Release notes](https://github.com/hetznercloud/hcloud-go/releases) - [Changelog](https://github.com/hetznercloud/hcloud-go/blob/main/CHANGELOG.md) - [Commits](https://github.com/hetznercloud/hcloud-go/compare/v2.4.0...v2.6.0) --- updated-dependencies: - dependency-name: github.com/hetznercloud/hcloud-go/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Enhanced visibility for `promtool test rules` with JSON colored formatting (#13342) * Added diff flag for unit test to improvise readability & debugging Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com> * Removed blank spaces Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com> * Fixed linting error Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com> * Added cli flags to documentation Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com> * Revert unrrelated linting fixes Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com> * Fixed review suggestions Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com> * Cleanup Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com> * Updated flag description Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com> * Updated flag description Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com> --------- Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com> * storage: skip merging when no remote storage configured Prometheus is hard-coded to use a fanout storage between TSDB and a remote storage which by default is empty. This change detects the empty storage and skips merging between result sets, which would make `Select()` sort results. Bottom line: we skip a sort unless there really is some remote storage configured. Signed-off-by: Bryan Boreham <bjboreham@gmail.com> * Remove csmarchbanks from remote write owners (#13432) I have not had the time to keep up with remote write and have no plans to work on it in the near future so I am withdrawing my maintainership of that part of the codebase. I continue to focus on client_python. Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com> * add more context cancellation check at evaluation time Signed-off-by: Ben Ye <benye@amazon.com> * Optimize label values with matchers by taking shortcuts (#13426) Don't calculate postings beforehand: we may not need them. If all matchers are for the requested label, we can just filter its values. Also, if there are no values at all, no need to run any kind of logic. Also add more labelValuesWithMatchers benchmarks Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com> * Add automatic memory limit handling Enable automatic detection of memory limits and configure GOMEMLIMIT to match. * Also includes a flag to allow controlling the reserved ratio. Signed-off-by: SuperQ <superq@gmail.com> * Update OSSF badge link (#13433) Provide a more user friendly interface Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * SD Managers taking over responsibility for registration of debug metrics (#13375) SD Managers take over responsibility for SD metrics registration --------- Signed-off-by: Paulin Todev <paulin.todev@gmail.com> Signed-off-by: Björn Rabenstein <github@rabenste.in> Co-authored-by: Björn Rabenstein <github@rabenste.in> * Optimize histogram iterators (#13340) Optimize histogram iterators Histogram iterators allocate new objects in the AtHistogram and AtFloatHistogram methods, which makes calculating rates over long ranges expensive. In #13215 we allowed an existing object to be reused when converting an integer histogram to a float histogram. This commit follows the same idea and allows injecting an existing object in the AtHistogram and AtFloatHistogram methods. When the injected value is nil, iterators allocate new histograms, otherwise they populate and return the injected object. The commit also adds a CopyTo method to Histogram and FloatHistogram which is used in the BufferedIterator to overwrite items in the ring instead of making new copies. Note that a specialized HPoint pool is needed for all of this to work (`matrixSelectorHPool`). --------- Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com> Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com> * doc: Mark `mad_over_time` as experimental (#13440) We forgot to do that in https://github.com/prometheus/prometheus/pull/13059 Signed-off-by: beorn7 <beorn@grafana.com> * Change metric label for Puppetdb from 'http' to 'puppetdb' Signed-off-by: Paulin Todev <paulin.todev@gmail.com> * mirror metrics.proto change & generate code Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com> * TestHeadLabelValuesWithMatchers: Add test case (#13414) Add test case to TestHeadLabelValuesWithMatchers, while fixing a couple of typos in other test cases. Also enclosing some implicit sub-tests in a `t.Run` call to make them explicitly sub-tests. Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * update all go dependencies (#13438) Signed-off-by: Augustin Husson <husson.augustin@gmail.com> * build(deps): bump the k8s-io group with 2 updates (#13454) Bumps the k8s-io group with 2 updates: [k8s.io/api](https://github.com/kubernetes/api) and [k8s.io/client-go](https://github.com/kubernetes/client-go). Updates `k8s.io/api` from 0.28.4 to 0.29.1 - [Commits](https://github.com/kubernetes/api/compare/v0.28.4...v0.29.1) Updates `k8s.io/client-go` from 0.28.4 to 0.29.1 - [Changelog](https://github.com/kubernetes/client-go/blob/master/CHANGELOG.md) - [Commits](https://github.com/kubernetes/client-go/compare/v0.28.4...v0.29.1) --- updated-dependencies: - dependency-name: k8s.io/api dependency-type: direct:production update-type: version-update:semver-minor dependency-group: k8s-io - dependency-name: k8s.io/client-go dependency-type: direct:production update-type: version-update:semver-minor dependency-group: k8s-io ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump the go-opentelemetry-io group with 1 update (#13453) Bumps the go-opentelemetry-io group with 1 update: [go.opentelemetry.io/collector/semconv](https://github.com/open-telemetry/opentelemetry-collector). Updates `go.opentelemetry.io/collector/semconv` from 0.92.0 to 0.93.0 - [Release notes](https://github.com/open-telemetry/opentelemetry-collector/releases) - [Changelog](https://github.com/open-telemetry/opentelemetry-collector/blob/main/CHANGELOG-API.md) - [Commits](https://github.com/open-telemetry/opentelemetry-collector/compare/v0.92.0...v0.93.0) --- updated-dependencies: - dependency-name: go.opentelemetry.io/collector/semconv dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-opentelemetry-io ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump actions/upload-artifact from 3.1.3 to 4.0.0 (#13355) Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3.1.3 to 4.0.0. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](a8a3f3ad30...c7d193f32e
) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump bufbuild/buf-push-action (#13357) Bumps [bufbuild/buf-push-action](https://github.com/bufbuild/buf-push-action) from 342fc4cdcf29115a01cf12a2c6dd6aac68dc51e1 to a654ff18effe4641ebea4a4ce242c49800728459. - [Release notes](https://github.com/bufbuild/buf-push-action/releases) - [Commits](342fc4cdcf...a654ff18ef
) --- updated-dependencies: - dependency-name: bufbuild/buf-push-action dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Labels: Add DropMetricName function, used in PromQL (#13446) This function is called very frequently when executing PromQL functions, and we can do it much more efficiently inside Labels. In the common case that `__name__` comes first in the labels, we simply re-point to start at the next label, which is nearly free. `DropMetricName` is now so cheap I removed the cache - benchmarks show everything still goes faster. Signed-off-by: Bryan Boreham <bjboreham@gmail.com> * tsdb: simplify internal series delete function (#13261) Lifting an optimisation from Agent code, `seriesHashmap.del` can use the unique series reference, doesn't need to check Labels. Also streamline the logic for deleting from `unique` and `conflicts` maps, and add some comments to help the next person. Signed-off-by: Bryan Boreham <bjboreham@gmail.com> * otlptranslator/update-copy.sh: Fix sed command lines Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Rollback k8s.io requirements (#13462) Rollback k8s.io Go modules to v0.28.6 to avoid forcing upgrade of Go to 1.21. This allows us to keep compatibility with the currently supported upstream Go releases. Signed-off-by: SuperQ <superq@gmail.com> * Make update-copy.sh work for both OSX and GNU sed Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Name @beorn7 and @krajorama as maintainers for native histograms I have been the de-facto maintainer for native histograms from the beginning. So let's put this into MAINTAINERS.md. In addition, I hereby proposose George Krajcsovits AKA Krajo as a co-maintainer. He has contributed a lot of native histogram code, but more importantly, he has contributed substantially to reviewing other contributors' native histogram code, up to a point where I was merely rubberstamping the PRs he had already reviewed. I'm confident that he is ready to to be granted commit rights as outlined in the "Maintainers" section of the governance: https://prometheus.io/governance/#maintainers According to the same section of the governance, I will announce the proposed change on the developers mailing list and will give some time for lazy consensus before merging this PR. Signed-off-by: beorn7 <beorn@grafana.com> * ui/fix: correct url handling for stacked graphs (#13460) Signed-off-by: Yury Moladau <yurymolodov@gmail.com> * tsdb: use cheaper Mutex on series Mutex is 8 bytes; RWMutex is 24 bytes and much more complicated. Since `RLock` is only used in two places, `UpdateMetadata` and `Delete`, neither of which are hotspots, we should use the cheaper one. Signed-off-by: Bryan Boreham <bjboreham@gmail.com> * Fix last_over_time for native histograms The last_over_time retains a histogram sample without making a copy. This sample is now coming from the buffered iterator used for windowing functions, and can be reused for reading subsequent samples as the iterator progresses. I would propose copying the sample in the last_over_time function, similar to how it is done for rate, sum_over_time and others. Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com> * Implementation NOTE: Rebased from main after refactor in #13014 Signed-off-by: Danny Kopping <danny.kopping@grafana.com> * Add feature flag Signed-off-by: Danny Kopping <danny.kopping@grafana.com> * Refactor concurrency control Signed-off-by: Danny Kopping <danny.kopping@grafana.com> * Optimising dependencies/dependents funcs to not produce new slices each request Signed-off-by: Danny Kopping <danny.kopping@grafana.com> * Refactoring Signed-off-by: Danny Kopping <danny.kopping@grafana.com> * Rename flag Signed-off-by: Danny Kopping <danny.kopping@grafana.com> * Refactoring for performance, and to allow controller to be overridden Signed-off-by: Danny Kopping <danny.kopping@grafana.com> * Block until all rules, both sync & async, have completed evaluating Updated & added tests Review feedback nits Return empty map if not indeterminate Use highWatermark to track inflight requests counter Appease the linter Clarify feature flag Signed-off-by: Danny Kopping <danny.kopping@grafana.com> * Fix typo in CLI flag description Signed-off-by: Marco Pracucci <marco@pracucci.com> * Fixed auto-generated doc Signed-off-by: Marco Pracucci <marco@pracucci.com> * Improve doc Signed-off-by: Marco Pracucci <marco@pracucci.com> * Simplify the design to update concurrency controller once the rule evaluation has done Signed-off-by: Marco Pracucci <marco@pracucci.com> * Add more test cases to TestDependenciesEdgeCases Signed-off-by: Marco Pracucci <marco@pracucci.com> * Added more test cases to TestDependenciesEdgeCases Signed-off-by: Marco Pracucci <marco@pracucci.com> * Improved RuleConcurrencyController interface doc Signed-off-by: Marco Pracucci <marco@pracucci.com> * Introduced sequentialRuleEvalController Signed-off-by: Marco Pracucci <marco@pracucci.com> * Remove superfluous nil check in Group.metrics Signed-off-by: Marco Pracucci <marco@pracucci.com> * api: Serialize discovered and target labels into JSON directly (#13469) Converted maps into labels.Labels to avoid a lot of copying of data which leads to very high memory consumption while opening the /service-discovery endpoint in the Prometheus UI Signed-off-by: Leegin <114397475+Leegin-darknight@users.noreply.github.com> * api: Serialize discovered labels into JSON directly in dropped targets (#13484) Converted maps into labels.Labels to avoid a lot of copying of data which leads to very high memory consumption while opening the /service-discovery endpoint in the Prometheus UI Signed-off-by: Leegin <114397475+Leegin-darknight@users.noreply.github.com> * Add ShardedPostings() support to TSDB (#10421) This PR is a reference implementation of the proposal described in #10420. In addition to what described in #10420, in this PR I've introduced labels.StableHash(). The idea is to offer an hashing function which doesn't change over time, and that's used by query sharding in order to get a stable behaviour over time. The implementation of labels.StableHash() is the hashing function used by Prometheus before stringlabels, and what's used by Grafana Mimir for query sharding (because built before stringlabels was a thing). Follow up work As mentioned in #10420, if this PR is accepted I'm also open to upload another foundamental piece used by Grafana Mimir query sharding to accelerate the query execution: an optional, configurable and fast in-memory cache for the series hashes. Signed-off-by: Marco Pracucci <marco@pracucci.com> * storage/remote: document why two benchmarks are skipped One was silently doing nothing; one was doing something but the work didn't go up linearly with iteration count. Signed-off-by: Bryan Boreham <bjboreham@gmail.com> * Pod status changes not discovered by Kube Endpoints SD (#13337) * fix(discovery/kubernetes/endpoints): react to changes on Pods because some modifications can occur on them without triggering an update on the related Endpoints (The Pod phase changing from Pending to Running e.g.). --------- Signed-off-by: machine424 <ayoubmrini424@gmail.com> Co-authored-by: Guillermo Sanchez Gavier <gsanchez@newrelic.com> * Small improvements, add const, remove copypasta (#8106) Signed-off-by: Mikhail Fesenko <proggga@gmail.com> Signed-off-by: Jesus Vazquez <jesusvzpg@gmail.com> * Proposal to improve FPointSlice and HPointSlice allocation. (#13448) * Reusing points slice from previous series when the slice is under utilized * Adding comments on the bench test Signed-off-by: Alan Protasio <alanprot@gmail.com> * lint Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com> * go mod tidy Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com> --------- Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com> Signed-off-by: Bryan Boreham <bjboreham@gmail.com> Signed-off-by: Erik Sommer <ersotech@posteo.de> Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com> Signed-off-by: bwplotka <bwplotka@gmail.com> Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it> Signed-off-by: machine424 <ayoubmrini424@gmail.com> Signed-off-by: Daniel Nicholls <daniel.nicholls@resdiary.com> Signed-off-by: Daniel Kerbel <nmdanny@gmail.com> Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Jan Fajerski <jfajersk@redhat.com> Signed-off-by: Kevin Mingtarja <kevin.mingtarja@gmail.com> Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com> Signed-off-by: Marc Tuduri <marctc@protonmail.com> Signed-off-by: Paschalis Tsilias <tpaschalis@users.noreply.github.com> Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com> Signed-off-by: Augustin Husson <augustin.husson@amadeus.com> Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com> Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> Signed-off-by: Kumar Kalpadiptya Roy <kalpadiptya.roy@outlook.com> Signed-off-by: Marco Pracucci <marco@pracucci.com> Signed-off-by: tyltr <tylitianrui@126.com> Signed-off-by: Ted Robertson 10043369+tredondo@users.noreply.github.com Signed-off-by: Ivan Babrou <github@ivan.computer> Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> Signed-off-by: Israel Blancas <iblancasa@gmail.com> Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com> Signed-off-by: Björn Rabenstein <github@rabenste.in> Signed-off-by: Goutham <gouthamve@gmail.com> Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com> Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com> Signed-off-by: Ben Ye <benye@amazon.com> Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com> Signed-off-by: SuperQ <superq@gmail.com> Signed-off-by: Ben Kochie <superq@gmail.com> Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> Signed-off-by: Paulin Todev <paulin.todev@gmail.com> Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com> Signed-off-by: beorn7 <beorn@grafana.com> Signed-off-by: Augustin Husson <husson.augustin@gmail.com> Signed-off-by: Yury Moladau <yurymolodov@gmail.com> Signed-off-by: Danny Kopping <danny.kopping@grafana.com> Signed-off-by: Leegin <114397475+Leegin-darknight@users.noreply.github.com> Signed-off-by: Mikhail Fesenko <proggga@gmail.com> Signed-off-by: Jesus Vazquez <jesusvzpg@gmail.com> Signed-off-by: Alan Protasio <alanprot@gmail.com> Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com> Co-authored-by: Julian Wiedmann <jwi@linux.ibm.com> Co-authored-by: Bryan Boreham <bjboreham@gmail.com> Co-authored-by: Erik Sommer <ersotech@posteo.de> Co-authored-by: Linas Medziunas <linas.medziunas@gmail.com> Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com> Co-authored-by: Arianna Vespri <arianna.vespri@yahoo.it> Co-authored-by: machine424 <ayoubmrini424@gmail.com> Co-authored-by: daniel-resdiary <109083091+daniel-resdiary@users.noreply.github.com> Co-authored-by: Daniel Kerbel <nmdanny@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jan Fajerski <jfajersk@redhat.com> Co-authored-by: Kevin Mingtarja <kevin.mingtarja@gmail.com> Co-authored-by: Paschalis Tsilias <tpaschalis@users.noreply.github.com> Co-authored-by: Marc Tudurí <marctc@protonmail.com> Co-authored-by: Paschalis Tsilias <paschalis.tsilias@grafana.com> Co-authored-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com> Co-authored-by: Augustin Husson <husson.augustin@gmail.com> Co-authored-by: Björn Rabenstein <beorn@grafana.com> Co-authored-by: zenador <zenador@users.noreply.github.com> Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: Ben Kochie <superq@gmail.com> Co-authored-by: Kumar Kalpadiptya Roy <kalpadiptya.roy@outlook.com> Co-authored-by: Marco Pracucci <marco@pracucci.com> Co-authored-by: tyltr <tylitianrui@126.com> Co-authored-by: Ted Robertson <10043369+tredondo@users.noreply.github.com> Co-authored-by: Julien Pivotto <roidelapluie@o11y.eu> Co-authored-by: Matthias Loibl <mail@matthiasloibl.com> Co-authored-by: Ivan Babrou <github@ivan.computer> Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> Co-authored-by: Israel Blancas <iblancasa@gmail.com> Co-authored-by: Ziqi Zhao <zhaoziqi9146@gmail.com> Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com> Co-authored-by: Björn Rabenstein <github@rabenste.in> Co-authored-by: Goutham <gouthamve@gmail.com> Co-authored-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com> Co-authored-by: Chris Marchbanks <csmarchbanks@gmail.com> Co-authored-by: Ben Ye <benye@amazon.com> Co-authored-by: Oleg Zaytsev <mail@olegzaytsev.com> Co-authored-by: Matthieu MOREL <matthieu.morel35@gmail.com> Co-authored-by: Paulin Todev <paulin.todev@gmail.com> Co-authored-by: Filip Petkovski <filip.petkovsky@gmail.com> Co-authored-by: Yury Molodov <yurymolodov@gmail.com> Co-authored-by: Danny Kopping <danny.kopping@grafana.com> Co-authored-by: Leegin <114397475+Leegin-darknight@users.noreply.github.com> Co-authored-by: Guillermo Sanchez Gavier <gsanchez@newrelic.com> Co-authored-by: Mikhail Fesenko <proggga@gmail.com> Co-authored-by: Alan Protasio <alanprot@gmail.com>
3675 lines
120 KiB
Go
3675 lines
120 KiB
Go
// Copyright 2017 The Prometheus Authors
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package tsdb
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"math"
|
|
"math/rand"
|
|
"path/filepath"
|
|
"sort"
|
|
"strconv"
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/oklog/ulid"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/prometheus/prometheus/model/histogram"
|
|
"github.com/prometheus/prometheus/model/labels"
|
|
"github.com/prometheus/prometheus/storage"
|
|
"github.com/prometheus/prometheus/tsdb/chunkenc"
|
|
"github.com/prometheus/prometheus/tsdb/chunks"
|
|
"github.com/prometheus/prometheus/tsdb/index"
|
|
"github.com/prometheus/prometheus/tsdb/tombstones"
|
|
"github.com/prometheus/prometheus/tsdb/tsdbutil"
|
|
"github.com/prometheus/prometheus/util/annotations"
|
|
)
|
|
|
|
// TODO(bwplotka): Replace those mocks with remote.concreteSeriesSet.
|
|
type mockSeriesSet struct {
|
|
next func() bool
|
|
series func() storage.Series
|
|
ws func() annotations.Annotations
|
|
err func() error
|
|
}
|
|
|
|
func (m *mockSeriesSet) Next() bool { return m.next() }
|
|
func (m *mockSeriesSet) At() storage.Series { return m.series() }
|
|
func (m *mockSeriesSet) Err() error { return m.err() }
|
|
func (m *mockSeriesSet) Warnings() annotations.Annotations { return m.ws() }
|
|
|
|
func newMockSeriesSet(list []storage.Series) *mockSeriesSet {
|
|
i := -1
|
|
return &mockSeriesSet{
|
|
next: func() bool {
|
|
i++
|
|
return i < len(list)
|
|
},
|
|
series: func() storage.Series {
|
|
return list[i]
|
|
},
|
|
err: func() error { return nil },
|
|
ws: func() annotations.Annotations { return nil },
|
|
}
|
|
}
|
|
|
|
type mockChunkSeriesSet struct {
|
|
next func() bool
|
|
series func() storage.ChunkSeries
|
|
ws func() annotations.Annotations
|
|
err func() error
|
|
}
|
|
|
|
func (m *mockChunkSeriesSet) Next() bool { return m.next() }
|
|
func (m *mockChunkSeriesSet) At() storage.ChunkSeries { return m.series() }
|
|
func (m *mockChunkSeriesSet) Err() error { return m.err() }
|
|
func (m *mockChunkSeriesSet) Warnings() annotations.Annotations { return m.ws() }
|
|
|
|
func newMockChunkSeriesSet(list []storage.ChunkSeries) *mockChunkSeriesSet {
|
|
i := -1
|
|
return &mockChunkSeriesSet{
|
|
next: func() bool {
|
|
i++
|
|
return i < len(list)
|
|
},
|
|
series: func() storage.ChunkSeries {
|
|
return list[i]
|
|
},
|
|
err: func() error { return nil },
|
|
ws: func() annotations.Annotations { return nil },
|
|
}
|
|
}
|
|
|
|
type seriesSamples struct {
|
|
lset map[string]string
|
|
chunks [][]sample
|
|
}
|
|
|
|
// Index: labels -> postings -> chunkMetas -> chunkRef.
|
|
// ChunkReader: ref -> vals.
|
|
func createIdxChkReaders(t *testing.T, tc []seriesSamples) (IndexReader, ChunkReader, int64, int64) {
|
|
sort.Slice(tc, func(i, j int) bool {
|
|
return labels.Compare(labels.FromMap(tc[i].lset), labels.FromMap(tc[i].lset)) < 0
|
|
})
|
|
|
|
postings := index.NewMemPostings()
|
|
chkReader := mockChunkReader(make(map[chunks.ChunkRef]chunkenc.Chunk))
|
|
lblIdx := make(map[string]map[string]struct{})
|
|
mi := newMockIndex()
|
|
blockMint := int64(math.MaxInt64)
|
|
blockMaxt := int64(math.MinInt64)
|
|
|
|
var chunkRef chunks.ChunkRef
|
|
for i, s := range tc {
|
|
i++ // 0 is not a valid posting.
|
|
metas := make([]chunks.Meta, 0, len(s.chunks))
|
|
for _, chk := range s.chunks {
|
|
if chk[0].t < blockMint {
|
|
blockMint = chk[0].t
|
|
}
|
|
if chk[len(chk)-1].t > blockMaxt {
|
|
blockMaxt = chk[len(chk)-1].t
|
|
}
|
|
|
|
metas = append(metas, chunks.Meta{
|
|
MinTime: chk[0].t,
|
|
MaxTime: chk[len(chk)-1].t,
|
|
Ref: chunkRef,
|
|
})
|
|
|
|
switch {
|
|
case chk[0].fh != nil:
|
|
chunk := chunkenc.NewFloatHistogramChunk()
|
|
app, _ := chunk.Appender()
|
|
for _, smpl := range chk {
|
|
require.NotNil(t, smpl.fh, "chunk can only contain one type of sample")
|
|
_, _, _, err := app.AppendFloatHistogram(nil, smpl.t, smpl.fh, true)
|
|
require.NoError(t, err, "chunk should be appendable")
|
|
}
|
|
chkReader[chunkRef] = chunk
|
|
case chk[0].h != nil:
|
|
chunk := chunkenc.NewHistogramChunk()
|
|
app, _ := chunk.Appender()
|
|
for _, smpl := range chk {
|
|
require.NotNil(t, smpl.h, "chunk can only contain one type of sample")
|
|
_, _, _, err := app.AppendHistogram(nil, smpl.t, smpl.h, true)
|
|
require.NoError(t, err, "chunk should be appendable")
|
|
}
|
|
chkReader[chunkRef] = chunk
|
|
default:
|
|
chunk := chunkenc.NewXORChunk()
|
|
app, _ := chunk.Appender()
|
|
for _, smpl := range chk {
|
|
require.Nil(t, smpl.h, "chunk can only contain one type of sample")
|
|
require.Nil(t, smpl.fh, "chunk can only contain one type of sample")
|
|
app.Append(smpl.t, smpl.f)
|
|
}
|
|
chkReader[chunkRef] = chunk
|
|
}
|
|
chunkRef++
|
|
}
|
|
ls := labels.FromMap(s.lset)
|
|
require.NoError(t, mi.AddSeries(storage.SeriesRef(i), ls, metas...))
|
|
|
|
postings.Add(storage.SeriesRef(i), ls)
|
|
|
|
ls.Range(func(l labels.Label) {
|
|
vs, present := lblIdx[l.Name]
|
|
if !present {
|
|
vs = map[string]struct{}{}
|
|
lblIdx[l.Name] = vs
|
|
}
|
|
vs[l.Value] = struct{}{}
|
|
})
|
|
}
|
|
|
|
require.NoError(t, postings.Iter(func(l labels.Label, p index.Postings) error {
|
|
return mi.WritePostings(l.Name, l.Value, p)
|
|
}))
|
|
return mi, chkReader, blockMint, blockMaxt
|
|
}
|
|
|
|
type blockQuerierTestCase struct {
|
|
mint, maxt int64
|
|
ms []*labels.Matcher
|
|
hints *storage.SelectHints
|
|
exp storage.SeriesSet
|
|
expChks storage.ChunkSeriesSet
|
|
}
|
|
|
|
func testBlockQuerier(t *testing.T, c blockQuerierTestCase, ir IndexReader, cr ChunkReader, stones *tombstones.MemTombstones) {
|
|
t.Run("sample", func(t *testing.T) {
|
|
q := blockQuerier{
|
|
blockBaseQuerier: &blockBaseQuerier{
|
|
index: ir,
|
|
chunks: cr,
|
|
tombstones: stones,
|
|
|
|
mint: c.mint,
|
|
maxt: c.maxt,
|
|
},
|
|
}
|
|
|
|
res := q.Select(context.Background(), false, c.hints, c.ms...)
|
|
defer func() { require.NoError(t, q.Close()) }()
|
|
|
|
for {
|
|
eok, rok := c.exp.Next(), res.Next()
|
|
require.Equal(t, eok, rok)
|
|
|
|
if !eok {
|
|
require.Empty(t, res.Warnings())
|
|
break
|
|
}
|
|
sexp := c.exp.At()
|
|
sres := res.At()
|
|
require.Equal(t, sexp.Labels(), sres.Labels())
|
|
|
|
smplExp, errExp := storage.ExpandSamples(sexp.Iterator(nil), nil)
|
|
smplRes, errRes := storage.ExpandSamples(sres.Iterator(nil), nil)
|
|
|
|
require.Equal(t, errExp, errRes)
|
|
require.Equal(t, smplExp, smplRes)
|
|
}
|
|
require.NoError(t, res.Err())
|
|
})
|
|
|
|
t.Run("chunk", func(t *testing.T) {
|
|
q := blockChunkQuerier{
|
|
blockBaseQuerier: &blockBaseQuerier{
|
|
index: ir,
|
|
chunks: cr,
|
|
tombstones: stones,
|
|
|
|
mint: c.mint,
|
|
maxt: c.maxt,
|
|
},
|
|
}
|
|
res := q.Select(context.Background(), false, c.hints, c.ms...)
|
|
defer func() { require.NoError(t, q.Close()) }()
|
|
|
|
for {
|
|
eok, rok := c.expChks.Next(), res.Next()
|
|
require.Equal(t, eok, rok)
|
|
|
|
if !eok {
|
|
require.Empty(t, res.Warnings())
|
|
break
|
|
}
|
|
sexpChks := c.expChks.At()
|
|
sres := res.At()
|
|
|
|
require.Equal(t, sexpChks.Labels(), sres.Labels())
|
|
|
|
chksExp, errExp := storage.ExpandChunks(sexpChks.Iterator(nil))
|
|
rmChunkRefs(chksExp)
|
|
chksRes, errRes := storage.ExpandChunks(sres.Iterator(nil))
|
|
rmChunkRefs(chksRes)
|
|
require.Equal(t, errExp, errRes)
|
|
|
|
require.Equal(t, len(chksExp), len(chksRes))
|
|
var exp, act [][]chunks.Sample
|
|
for i := range chksExp {
|
|
samples, err := storage.ExpandSamples(chksExp[i].Chunk.Iterator(nil), nil)
|
|
require.NoError(t, err)
|
|
exp = append(exp, samples)
|
|
samples, err = storage.ExpandSamples(chksRes[i].Chunk.Iterator(nil), nil)
|
|
require.NoError(t, err)
|
|
act = append(act, samples)
|
|
}
|
|
|
|
require.Equal(t, exp, act)
|
|
}
|
|
require.NoError(t, res.Err())
|
|
})
|
|
}
|
|
|
|
func TestBlockQuerier(t *testing.T) {
|
|
for _, c := range []blockQuerierTestCase{
|
|
{
|
|
mint: 0,
|
|
maxt: 0,
|
|
ms: []*labels.Matcher{},
|
|
exp: newMockSeriesSet([]storage.Series{}),
|
|
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{}),
|
|
},
|
|
{
|
|
mint: 0,
|
|
maxt: 0,
|
|
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "a", "a")},
|
|
exp: newMockSeriesSet([]storage.Series{}),
|
|
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{}),
|
|
},
|
|
{
|
|
mint: 1,
|
|
maxt: 0,
|
|
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "a", "a")},
|
|
exp: newMockSeriesSet([]storage.Series{}),
|
|
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{}),
|
|
},
|
|
{
|
|
mint: math.MinInt64,
|
|
maxt: math.MaxInt64,
|
|
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "a", "x")},
|
|
exp: newMockSeriesSet([]storage.Series{}),
|
|
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{}),
|
|
},
|
|
{
|
|
mint: math.MinInt64,
|
|
maxt: math.MaxInt64,
|
|
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "a", ".*")},
|
|
exp: newMockSeriesSet([]storage.Series{
|
|
storage.NewListSeries(labels.FromStrings("a", "a"),
|
|
[]chunks.Sample{sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 4, nil, nil}, sample{5, 2, nil, nil}, sample{6, 3, nil, nil}, sample{7, 4, nil, nil}},
|
|
),
|
|
storage.NewListSeries(labels.FromStrings("a", "a", "b", "b"),
|
|
[]chunks.Sample{sample{1, 1, nil, nil}, sample{2, 2, nil, nil}, sample{3, 3, nil, nil}, sample{5, 3, nil, nil}, sample{6, 6, nil, nil}},
|
|
),
|
|
storage.NewListSeries(labels.FromStrings("b", "b"),
|
|
[]chunks.Sample{sample{1, 3, nil, nil}, sample{2, 2, nil, nil}, sample{3, 6, nil, nil}, sample{5, 1, nil, nil}, sample{6, 7, nil, nil}, sample{7, 2, nil, nil}},
|
|
),
|
|
}),
|
|
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{
|
|
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a"),
|
|
[]chunks.Sample{sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 4, nil, nil}}, []chunks.Sample{sample{5, 2, nil, nil}, sample{6, 3, nil, nil}, sample{7, 4, nil, nil}},
|
|
),
|
|
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a", "b", "b"),
|
|
[]chunks.Sample{sample{1, 1, nil, nil}, sample{2, 2, nil, nil}, sample{3, 3, nil, nil}}, []chunks.Sample{sample{5, 3, nil, nil}, sample{6, 6, nil, nil}},
|
|
),
|
|
storage.NewListChunkSeriesFromSamples(labels.FromStrings("b", "b"),
|
|
[]chunks.Sample{sample{1, 3, nil, nil}, sample{2, 2, nil, nil}, sample{3, 6, nil, nil}}, []chunks.Sample{sample{5, 1, nil, nil}, sample{6, 7, nil, nil}, sample{7, 2, nil, nil}},
|
|
),
|
|
}),
|
|
},
|
|
{
|
|
mint: 2,
|
|
maxt: 6,
|
|
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "a", "a")},
|
|
exp: newMockSeriesSet([]storage.Series{
|
|
storage.NewListSeries(labels.FromStrings("a", "a"),
|
|
[]chunks.Sample{sample{2, 3, nil, nil}, sample{3, 4, nil, nil}, sample{5, 2, nil, nil}, sample{6, 3, nil, nil}},
|
|
),
|
|
storage.NewListSeries(labels.FromStrings("a", "a", "b", "b"),
|
|
[]chunks.Sample{sample{2, 2, nil, nil}, sample{3, 3, nil, nil}, sample{5, 3, nil, nil}, sample{6, 6, nil, nil}},
|
|
),
|
|
}),
|
|
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{
|
|
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a"),
|
|
[]chunks.Sample{sample{2, 3, nil, nil}, sample{3, 4, nil, nil}}, []chunks.Sample{sample{5, 2, nil, nil}, sample{6, 3, nil, nil}},
|
|
),
|
|
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a", "b", "b"),
|
|
[]chunks.Sample{sample{2, 2, nil, nil}, sample{3, 3, nil, nil}}, []chunks.Sample{sample{5, 3, nil, nil}, sample{6, 6, nil, nil}},
|
|
),
|
|
}),
|
|
},
|
|
{
|
|
// This test runs a query disabling trimming. All chunks containing at least 1 sample within the queried
|
|
// time range will be returned.
|
|
mint: 2,
|
|
maxt: 6,
|
|
hints: &storage.SelectHints{Start: 2, End: 6, DisableTrimming: true},
|
|
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "a", "a")},
|
|
exp: newMockSeriesSet([]storage.Series{
|
|
storage.NewListSeries(labels.FromStrings("a", "a"),
|
|
[]chunks.Sample{sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 4, nil, nil}, sample{5, 2, nil, nil}, sample{6, 3, nil, nil}, sample{7, 4, nil, nil}},
|
|
),
|
|
storage.NewListSeries(labels.FromStrings("a", "a", "b", "b"),
|
|
[]chunks.Sample{sample{1, 1, nil, nil}, sample{2, 2, nil, nil}, sample{3, 3, nil, nil}, sample{5, 3, nil, nil}, sample{6, 6, nil, nil}},
|
|
),
|
|
}),
|
|
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{
|
|
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a"),
|
|
[]chunks.Sample{sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 4, nil, nil}},
|
|
[]chunks.Sample{sample{5, 2, nil, nil}, sample{6, 3, nil, nil}, sample{7, 4, nil, nil}},
|
|
),
|
|
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a", "b", "b"),
|
|
[]chunks.Sample{sample{1, 1, nil, nil}, sample{2, 2, nil, nil}, sample{3, 3, nil, nil}},
|
|
[]chunks.Sample{sample{5, 3, nil, nil}, sample{6, 6, nil, nil}},
|
|
),
|
|
}),
|
|
},
|
|
{
|
|
// This test runs a query disabling trimming. All chunks containing at least 1 sample within the queried
|
|
// time range will be returned.
|
|
mint: 5,
|
|
maxt: 6,
|
|
hints: &storage.SelectHints{Start: 5, End: 6, DisableTrimming: true},
|
|
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "a", "a")},
|
|
exp: newMockSeriesSet([]storage.Series{
|
|
storage.NewListSeries(labels.FromStrings("a", "a"),
|
|
[]chunks.Sample{sample{5, 2, nil, nil}, sample{6, 3, nil, nil}, sample{7, 4, nil, nil}},
|
|
),
|
|
storage.NewListSeries(labels.FromStrings("a", "a", "b", "b"),
|
|
[]chunks.Sample{sample{5, 3, nil, nil}, sample{6, 6, nil, nil}},
|
|
),
|
|
}),
|
|
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{
|
|
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a"),
|
|
[]chunks.Sample{sample{5, 2, nil, nil}, sample{6, 3, nil, nil}, sample{7, 4, nil, nil}},
|
|
),
|
|
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a", "b", "b"),
|
|
[]chunks.Sample{sample{5, 3, nil, nil}, sample{6, 6, nil, nil}},
|
|
),
|
|
}),
|
|
},
|
|
} {
|
|
t.Run("", func(t *testing.T) {
|
|
ir, cr, _, _ := createIdxChkReaders(t, testData)
|
|
testBlockQuerier(t, c, ir, cr, tombstones.NewMemTombstones())
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestBlockQuerier_AgainstHeadWithOpenChunks(t *testing.T) {
|
|
for _, c := range []blockQuerierTestCase{
|
|
{
|
|
mint: 0,
|
|
maxt: 0,
|
|
ms: []*labels.Matcher{},
|
|
exp: newMockSeriesSet([]storage.Series{}),
|
|
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{}),
|
|
},
|
|
{
|
|
mint: 0,
|
|
maxt: 0,
|
|
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "a", "a")},
|
|
exp: newMockSeriesSet([]storage.Series{}),
|
|
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{}),
|
|
},
|
|
{
|
|
mint: 1,
|
|
maxt: 0,
|
|
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "a", "a")},
|
|
exp: newMockSeriesSet([]storage.Series{}),
|
|
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{}),
|
|
},
|
|
{
|
|
mint: math.MinInt64,
|
|
maxt: math.MaxInt64,
|
|
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "a", "x")},
|
|
exp: newMockSeriesSet([]storage.Series{}),
|
|
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{}),
|
|
},
|
|
{
|
|
mint: math.MinInt64,
|
|
maxt: math.MaxInt64,
|
|
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "a", ".*")},
|
|
exp: newMockSeriesSet([]storage.Series{
|
|
storage.NewListSeries(labels.FromStrings("a", "a"),
|
|
[]chunks.Sample{sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 4, nil, nil}, sample{5, 2, nil, nil}, sample{6, 3, nil, nil}, sample{7, 4, nil, nil}},
|
|
),
|
|
storage.NewListSeries(labels.FromStrings("a", "a", "b", "b"),
|
|
[]chunks.Sample{sample{1, 1, nil, nil}, sample{2, 2, nil, nil}, sample{3, 3, nil, nil}, sample{5, 3, nil, nil}, sample{6, 6, nil, nil}},
|
|
),
|
|
storage.NewListSeries(labels.FromStrings("b", "b"),
|
|
[]chunks.Sample{sample{1, 3, nil, nil}, sample{2, 2, nil, nil}, sample{3, 6, nil, nil}, sample{5, 1, nil, nil}, sample{6, 7, nil, nil}, sample{7, 2, nil, nil}},
|
|
),
|
|
}),
|
|
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{
|
|
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a"),
|
|
[]chunks.Sample{sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 4, nil, nil}, sample{5, 2, nil, nil}, sample{6, 3, nil, nil}, sample{7, 4, nil, nil}},
|
|
),
|
|
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a", "b", "b"),
|
|
[]chunks.Sample{sample{1, 1, nil, nil}, sample{2, 2, nil, nil}, sample{3, 3, nil, nil}, sample{5, 3, nil, nil}, sample{6, 6, nil, nil}},
|
|
),
|
|
storage.NewListChunkSeriesFromSamples(labels.FromStrings("b", "b"),
|
|
[]chunks.Sample{sample{1, 3, nil, nil}, sample{2, 2, nil, nil}, sample{3, 6, nil, nil}, sample{5, 1, nil, nil}, sample{6, 7, nil, nil}, sample{7, 2, nil, nil}},
|
|
),
|
|
}),
|
|
},
|
|
{
|
|
mint: 2,
|
|
maxt: 6,
|
|
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "a", "a")},
|
|
exp: newMockSeriesSet([]storage.Series{
|
|
storage.NewListSeries(labels.FromStrings("a", "a"),
|
|
[]chunks.Sample{sample{2, 3, nil, nil}, sample{3, 4, nil, nil}, sample{5, 2, nil, nil}, sample{6, 3, nil, nil}},
|
|
),
|
|
storage.NewListSeries(labels.FromStrings("a", "a", "b", "b"),
|
|
[]chunks.Sample{sample{2, 2, nil, nil}, sample{3, 3, nil, nil}, sample{5, 3, nil, nil}, sample{6, 6, nil, nil}},
|
|
),
|
|
}),
|
|
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{
|
|
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a"),
|
|
[]chunks.Sample{sample{2, 3, nil, nil}, sample{3, 4, nil, nil}, sample{5, 2, nil, nil}, sample{6, 3, nil, nil}},
|
|
),
|
|
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a", "b", "b"),
|
|
[]chunks.Sample{sample{2, 2, nil, nil}, sample{3, 3, nil, nil}, sample{5, 3, nil, nil}, sample{6, 6, nil, nil}},
|
|
),
|
|
}),
|
|
},
|
|
} {
|
|
t.Run("", func(t *testing.T) {
|
|
opts := DefaultHeadOptions()
|
|
opts.ChunkRange = 2 * time.Hour.Milliseconds()
|
|
h, err := NewHead(nil, nil, nil, nil, opts, nil)
|
|
require.NoError(t, err)
|
|
defer h.Close()
|
|
|
|
app := h.Appender(context.Background())
|
|
for _, s := range testData {
|
|
for _, chk := range s.chunks {
|
|
for _, sample := range chk {
|
|
_, err = app.Append(0, labels.FromMap(s.lset), sample.t, sample.f)
|
|
require.NoError(t, err)
|
|
}
|
|
}
|
|
}
|
|
require.NoError(t, app.Commit())
|
|
|
|
hr := NewRangeHead(h, c.mint, c.maxt)
|
|
ir, err := hr.Index()
|
|
require.NoError(t, err)
|
|
defer ir.Close()
|
|
|
|
cr, err := hr.Chunks()
|
|
require.NoError(t, err)
|
|
defer cr.Close()
|
|
|
|
testBlockQuerier(t, c, ir, cr, tombstones.NewMemTombstones())
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestBlockQuerier_TrimmingDoesNotModifyOriginalTombstoneIntervals(t *testing.T) {
|
|
ctx := context.Background()
|
|
c := blockQuerierTestCase{
|
|
mint: 2,
|
|
maxt: 6,
|
|
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "a", "a")},
|
|
exp: newMockSeriesSet([]storage.Series{
|
|
storage.NewListSeries(labels.FromStrings("a", "a"),
|
|
[]chunks.Sample{sample{3, 4, nil, nil}, sample{5, 2, nil, nil}, sample{6, 3, nil, nil}},
|
|
),
|
|
storage.NewListSeries(labels.FromStrings("a", "a", "b", "b"),
|
|
[]chunks.Sample{sample{3, 3, nil, nil}, sample{5, 3, nil, nil}, sample{6, 6, nil, nil}},
|
|
),
|
|
}),
|
|
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{
|
|
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a"),
|
|
[]chunks.Sample{sample{3, 4, nil, nil}}, []chunks.Sample{sample{5, 2, nil, nil}, sample{6, 3, nil, nil}},
|
|
),
|
|
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a", "b", "b"),
|
|
[]chunks.Sample{sample{3, 3, nil, nil}}, []chunks.Sample{sample{5, 3, nil, nil}, sample{6, 6, nil, nil}},
|
|
),
|
|
}),
|
|
}
|
|
ir, cr, _, _ := createIdxChkReaders(t, testData)
|
|
stones := tombstones.NewMemTombstones()
|
|
p, err := ir.Postings(ctx, "a", "a")
|
|
require.NoError(t, err)
|
|
refs, err := index.ExpandPostings(p)
|
|
require.NoError(t, err)
|
|
for _, ref := range refs {
|
|
stones.AddInterval(ref, tombstones.Interval{Mint: 1, Maxt: 2})
|
|
}
|
|
testBlockQuerier(t, c, ir, cr, stones)
|
|
for _, ref := range refs {
|
|
intervals, err := stones.Get(ref)
|
|
require.NoError(t, err)
|
|
// Without copy, the intervals could be [math.MinInt64, 2].
|
|
require.Equal(t, tombstones.Intervals{{Mint: 1, Maxt: 2}}, intervals)
|
|
}
|
|
}
|
|
|
|
var testData = []seriesSamples{
|
|
{
|
|
lset: map[string]string{"a": "a"},
|
|
chunks: [][]sample{
|
|
{{1, 2, nil, nil}, {2, 3, nil, nil}, {3, 4, nil, nil}},
|
|
{{5, 2, nil, nil}, {6, 3, nil, nil}, {7, 4, nil, nil}},
|
|
},
|
|
},
|
|
{
|
|
lset: map[string]string{"a": "a", "b": "b"},
|
|
chunks: [][]sample{
|
|
{{1, 1, nil, nil}, {2, 2, nil, nil}, {3, 3, nil, nil}},
|
|
{{5, 3, nil, nil}, {6, 6, nil, nil}},
|
|
},
|
|
},
|
|
{
|
|
lset: map[string]string{"b": "b"},
|
|
chunks: [][]sample{
|
|
{{1, 3, nil, nil}, {2, 2, nil, nil}, {3, 6, nil, nil}},
|
|
{{5, 1, nil, nil}, {6, 7, nil, nil}, {7, 2, nil, nil}},
|
|
},
|
|
},
|
|
}
|
|
|
|
func TestBlockQuerierDelete(t *testing.T) {
|
|
stones := tombstones.NewTestMemTombstones([]tombstones.Intervals{
|
|
{{Mint: 1, Maxt: 3}},
|
|
{{Mint: 1, Maxt: 3}, {Mint: 6, Maxt: 10}},
|
|
{{Mint: 6, Maxt: 10}},
|
|
})
|
|
|
|
for _, c := range []blockQuerierTestCase{
|
|
{
|
|
mint: 0,
|
|
maxt: 0,
|
|
ms: []*labels.Matcher{},
|
|
exp: newMockSeriesSet([]storage.Series{}),
|
|
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{}),
|
|
},
|
|
{
|
|
mint: 0,
|
|
maxt: 0,
|
|
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "a", "a")},
|
|
exp: newMockSeriesSet([]storage.Series{}),
|
|
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{}),
|
|
},
|
|
{
|
|
mint: 1,
|
|
maxt: 0,
|
|
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "a", "a")},
|
|
exp: newMockSeriesSet([]storage.Series{}),
|
|
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{}),
|
|
},
|
|
{
|
|
mint: math.MinInt64,
|
|
maxt: math.MaxInt64,
|
|
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "a", "x")},
|
|
exp: newMockSeriesSet([]storage.Series{}),
|
|
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{}),
|
|
},
|
|
{
|
|
mint: math.MinInt64,
|
|
maxt: math.MaxInt64,
|
|
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "a", ".*")},
|
|
exp: newMockSeriesSet([]storage.Series{
|
|
storage.NewListSeries(labels.FromStrings("a", "a"),
|
|
[]chunks.Sample{sample{5, 2, nil, nil}, sample{6, 3, nil, nil}, sample{7, 4, nil, nil}},
|
|
),
|
|
storage.NewListSeries(labels.FromStrings("a", "a", "b", "b"),
|
|
[]chunks.Sample{sample{5, 3, nil, nil}},
|
|
),
|
|
storage.NewListSeries(labels.FromStrings("b", "b"),
|
|
[]chunks.Sample{sample{1, 3, nil, nil}, sample{2, 2, nil, nil}, sample{3, 6, nil, nil}, sample{5, 1, nil, nil}},
|
|
),
|
|
}),
|
|
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{
|
|
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a"),
|
|
[]chunks.Sample{sample{5, 2, nil, nil}, sample{6, 3, nil, nil}, sample{7, 4, nil, nil}},
|
|
),
|
|
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a", "b", "b"),
|
|
[]chunks.Sample{sample{5, 3, nil, nil}},
|
|
),
|
|
storage.NewListChunkSeriesFromSamples(labels.FromStrings("b", "b"),
|
|
[]chunks.Sample{sample{1, 3, nil, nil}, sample{2, 2, nil, nil}, sample{3, 6, nil, nil}}, []chunks.Sample{sample{5, 1, nil, nil}},
|
|
),
|
|
}),
|
|
},
|
|
{
|
|
mint: 2,
|
|
maxt: 6,
|
|
ms: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "a", "a")},
|
|
exp: newMockSeriesSet([]storage.Series{
|
|
storage.NewListSeries(labels.FromStrings("a", "a"),
|
|
[]chunks.Sample{sample{5, 2, nil, nil}, sample{6, 3, nil, nil}},
|
|
),
|
|
storage.NewListSeries(labels.FromStrings("a", "a", "b", "b"),
|
|
[]chunks.Sample{sample{5, 3, nil, nil}},
|
|
),
|
|
}),
|
|
expChks: newMockChunkSeriesSet([]storage.ChunkSeries{
|
|
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a"),
|
|
[]chunks.Sample{sample{5, 2, nil, nil}, sample{6, 3, nil, nil}},
|
|
),
|
|
storage.NewListChunkSeriesFromSamples(labels.FromStrings("a", "a", "b", "b"),
|
|
[]chunks.Sample{sample{5, 3, nil, nil}},
|
|
),
|
|
}),
|
|
},
|
|
} {
|
|
t.Run("", func(t *testing.T) {
|
|
ir, cr, _, _ := createIdxChkReaders(t, testData)
|
|
testBlockQuerier(t, c, ir, cr, stones)
|
|
})
|
|
}
|
|
}
|
|
|
|
type fakeChunksReader struct {
|
|
ChunkReader
|
|
chks map[chunks.ChunkRef]chunkenc.Chunk
|
|
iterables map[chunks.ChunkRef]chunkenc.Iterable
|
|
}
|
|
|
|
func createFakeReaderAndNotPopulatedChunks(s ...[]chunks.Sample) (*fakeChunksReader, []chunks.Meta) {
|
|
f := &fakeChunksReader{
|
|
chks: map[chunks.ChunkRef]chunkenc.Chunk{},
|
|
iterables: map[chunks.ChunkRef]chunkenc.Iterable{},
|
|
}
|
|
chks := make([]chunks.Meta, 0, len(s))
|
|
|
|
for ref, samples := range s {
|
|
chk, _ := chunks.ChunkFromSamples(samples)
|
|
f.chks[chunks.ChunkRef(ref)] = chk.Chunk
|
|
|
|
chks = append(chks, chunks.Meta{
|
|
Ref: chunks.ChunkRef(ref),
|
|
MinTime: chk.MinTime,
|
|
MaxTime: chk.MaxTime,
|
|
})
|
|
}
|
|
return f, chks
|
|
}
|
|
|
|
// Samples in each slice are assumed to be sorted.
|
|
func createFakeReaderAndIterables(s ...[]chunks.Sample) (*fakeChunksReader, []chunks.Meta) {
|
|
f := &fakeChunksReader{
|
|
chks: map[chunks.ChunkRef]chunkenc.Chunk{},
|
|
iterables: map[chunks.ChunkRef]chunkenc.Iterable{},
|
|
}
|
|
chks := make([]chunks.Meta, 0, len(s))
|
|
|
|
for ref, samples := range s {
|
|
f.iterables[chunks.ChunkRef(ref)] = &mockIterable{s: samples}
|
|
|
|
var minTime, maxTime int64
|
|
if len(samples) > 0 {
|
|
minTime = samples[0].T()
|
|
maxTime = samples[len(samples)-1].T()
|
|
}
|
|
chks = append(chks, chunks.Meta{
|
|
Ref: chunks.ChunkRef(ref),
|
|
MinTime: minTime,
|
|
MaxTime: maxTime,
|
|
})
|
|
}
|
|
return f, chks
|
|
}
|
|
|
|
func (r *fakeChunksReader) ChunkOrIterable(meta chunks.Meta) (chunkenc.Chunk, chunkenc.Iterable, error) {
|
|
if chk, ok := r.chks[meta.Ref]; ok {
|
|
return chk, nil, nil
|
|
}
|
|
|
|
if it, ok := r.iterables[meta.Ref]; ok {
|
|
return nil, it, nil
|
|
}
|
|
return nil, nil, fmt.Errorf("chunk or iterable not found at ref %v", meta.Ref)
|
|
}
|
|
|
|
type mockIterable struct {
|
|
s []chunks.Sample
|
|
}
|
|
|
|
func (it *mockIterable) Iterator(chunkenc.Iterator) chunkenc.Iterator {
|
|
return &mockSampleIterator{
|
|
s: it.s,
|
|
idx: -1,
|
|
}
|
|
}
|
|
|
|
type mockSampleIterator struct {
|
|
s []chunks.Sample
|
|
idx int
|
|
}
|
|
|
|
func (it *mockSampleIterator) Seek(t int64) chunkenc.ValueType {
|
|
for ; it.idx < len(it.s); it.idx++ {
|
|
if it.idx != -1 && it.s[it.idx].T() >= t {
|
|
return it.s[it.idx].Type()
|
|
}
|
|
}
|
|
|
|
return chunkenc.ValNone
|
|
}
|
|
|
|
func (it *mockSampleIterator) At() (int64, float64) {
|
|
return it.s[it.idx].T(), it.s[it.idx].F()
|
|
}
|
|
|
|
func (it *mockSampleIterator) AtHistogram(*histogram.Histogram) (int64, *histogram.Histogram) {
|
|
return it.s[it.idx].T(), it.s[it.idx].H()
|
|
}
|
|
|
|
func (it *mockSampleIterator) AtFloatHistogram(*histogram.FloatHistogram) (int64, *histogram.FloatHistogram) {
|
|
return it.s[it.idx].T(), it.s[it.idx].FH()
|
|
}
|
|
|
|
func (it *mockSampleIterator) AtT() int64 {
|
|
return it.s[it.idx].T()
|
|
}
|
|
|
|
func (it *mockSampleIterator) Next() chunkenc.ValueType {
|
|
if it.idx < len(it.s)-1 {
|
|
it.idx++
|
|
return it.s[it.idx].Type()
|
|
}
|
|
|
|
return chunkenc.ValNone
|
|
}
|
|
|
|
func (it *mockSampleIterator) Err() error { return nil }
|
|
|
|
func TestPopulateWithTombSeriesIterators(t *testing.T) {
|
|
type minMaxTimes struct {
|
|
minTime, maxTime int64
|
|
}
|
|
cases := []struct {
|
|
name string
|
|
samples [][]chunks.Sample
|
|
|
|
expected []chunks.Sample
|
|
expectedChks []chunks.Meta
|
|
expectedMinMaxTimes []minMaxTimes
|
|
|
|
intervals tombstones.Intervals
|
|
|
|
// Seek being zero means do not test seek.
|
|
seek int64
|
|
seekSuccess bool
|
|
|
|
// Set this to true if a sample slice will form multiple chunks.
|
|
skipChunkTest bool
|
|
|
|
skipIterableTest bool
|
|
}{
|
|
{
|
|
name: "no chunk",
|
|
samples: [][]chunks.Sample{},
|
|
},
|
|
{
|
|
name: "one empty chunk", // This should never happen.
|
|
samples: [][]chunks.Sample{{}},
|
|
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{0, 0}},
|
|
// iterables with no samples will return no chunks instead of empty chunks
|
|
skipIterableTest: true,
|
|
},
|
|
{
|
|
name: "one empty iterable",
|
|
samples: [][]chunks.Sample{{}},
|
|
|
|
// iterables with no samples will return no chunks
|
|
expectedChks: nil,
|
|
skipChunkTest: true,
|
|
},
|
|
{
|
|
name: "three empty chunks", // This should never happen.
|
|
samples: [][]chunks.Sample{{}, {}, {}},
|
|
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{}),
|
|
assureChunkFromSamples(t, []chunks.Sample{}),
|
|
assureChunkFromSamples(t, []chunks.Sample{}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{0, 0}, {0, 0}, {0, 0}},
|
|
// iterables with no samples will return no chunks instead of empty chunks
|
|
skipIterableTest: true,
|
|
},
|
|
{
|
|
name: "three empty iterables",
|
|
samples: [][]chunks.Sample{{}, {}, {}},
|
|
|
|
// iterables with no samples will return no chunks
|
|
expectedChks: nil,
|
|
skipChunkTest: true,
|
|
},
|
|
{
|
|
name: "one chunk",
|
|
samples: [][]chunks.Sample{
|
|
{sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil}},
|
|
},
|
|
|
|
expected: []chunks.Sample{
|
|
sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{1, 6}},
|
|
},
|
|
{
|
|
name: "two full chunks",
|
|
samples: [][]chunks.Sample{
|
|
{sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil}},
|
|
{sample{7, 89, nil, nil}, sample{9, 8, nil, nil}},
|
|
},
|
|
|
|
expected: []chunks.Sample{
|
|
sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil}, sample{7, 89, nil, nil}, sample{9, 8, nil, nil},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{7, 89, nil, nil}, sample{9, 8, nil, nil},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{1, 6}, {7, 9}},
|
|
},
|
|
{
|
|
name: "three full chunks",
|
|
samples: [][]chunks.Sample{
|
|
{sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil}},
|
|
{sample{7, 89, nil, nil}, sample{9, 8, nil, nil}},
|
|
{sample{10, 22, nil, nil}, sample{203, 3493, nil, nil}},
|
|
},
|
|
|
|
expected: []chunks.Sample{
|
|
sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil}, sample{7, 89, nil, nil}, sample{9, 8, nil, nil}, sample{10, 22, nil, nil}, sample{203, 3493, nil, nil},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{7, 89, nil, nil}, sample{9, 8, nil, nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{10, 22, nil, nil}, sample{203, 3493, nil, nil},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{1, 6}, {7, 9}, {10, 203}},
|
|
},
|
|
// Seek cases.
|
|
{
|
|
name: "three empty chunks and seek", // This should never happen.
|
|
samples: [][]chunks.Sample{{}, {}, {}},
|
|
seek: 1,
|
|
|
|
seekSuccess: false,
|
|
},
|
|
{
|
|
name: "two chunks and seek beyond chunks",
|
|
samples: [][]chunks.Sample{
|
|
{sample{1, 2, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil}},
|
|
{sample{7, 89, nil, nil}, sample{9, 8, nil, nil}},
|
|
},
|
|
seek: 10,
|
|
|
|
seekSuccess: false,
|
|
},
|
|
{
|
|
name: "two chunks and seek on middle of first chunk",
|
|
samples: [][]chunks.Sample{
|
|
{sample{1, 2, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil}},
|
|
{sample{7, 89, nil, nil}, sample{9, 8, nil, nil}},
|
|
},
|
|
seek: 2,
|
|
|
|
seekSuccess: true,
|
|
expected: []chunks.Sample{
|
|
sample{3, 5, nil, nil}, sample{6, 1, nil, nil}, sample{7, 89, nil, nil}, sample{9, 8, nil, nil},
|
|
},
|
|
},
|
|
{
|
|
name: "two chunks and seek before first chunk",
|
|
samples: [][]chunks.Sample{
|
|
{sample{1, 2, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil}},
|
|
{sample{7, 89, nil, nil}, sample{9, 8, nil, nil}},
|
|
},
|
|
seek: -32,
|
|
|
|
seekSuccess: true,
|
|
expected: []chunks.Sample{
|
|
sample{1, 2, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil}, sample{7, 89, nil, nil}, sample{9, 8, nil, nil},
|
|
},
|
|
},
|
|
// Deletion / Trim cases.
|
|
{
|
|
name: "no chunk with deletion interval",
|
|
samples: [][]chunks.Sample{},
|
|
intervals: tombstones.Intervals{{Mint: 20, Maxt: 21}},
|
|
},
|
|
{
|
|
name: "two chunks with trimmed first and last samples from edge chunks",
|
|
samples: [][]chunks.Sample{
|
|
{sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil}},
|
|
{sample{7, 89, nil, nil}, sample{9, 8, nil, nil}},
|
|
},
|
|
intervals: tombstones.Intervals{{Mint: math.MinInt64, Maxt: 2}}.Add(tombstones.Interval{Mint: 9, Maxt: math.MaxInt64}),
|
|
|
|
expected: []chunks.Sample{
|
|
sample{3, 5, nil, nil}, sample{6, 1, nil, nil}, sample{7, 89, nil, nil},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{3, 5, nil, nil}, sample{6, 1, nil, nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{7, 89, nil, nil},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{3, 6}, {7, 7}},
|
|
},
|
|
{
|
|
name: "two chunks with trimmed middle sample of first chunk",
|
|
samples: [][]chunks.Sample{
|
|
{sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil}},
|
|
{sample{7, 89, nil, nil}, sample{9, 8, nil, nil}},
|
|
},
|
|
intervals: tombstones.Intervals{{Mint: 2, Maxt: 3}},
|
|
|
|
expected: []chunks.Sample{
|
|
sample{1, 2, nil, nil}, sample{6, 1, nil, nil}, sample{7, 89, nil, nil}, sample{9, 8, nil, nil},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{1, 2, nil, nil}, sample{6, 1, nil, nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{7, 89, nil, nil}, sample{9, 8, nil, nil},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{1, 6}, {7, 9}},
|
|
},
|
|
{
|
|
name: "two chunks with deletion across two chunks",
|
|
samples: [][]chunks.Sample{
|
|
{sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil}},
|
|
{sample{7, 89, nil, nil}, sample{9, 8, nil, nil}},
|
|
},
|
|
intervals: tombstones.Intervals{{Mint: 6, Maxt: 7}},
|
|
|
|
expected: []chunks.Sample{
|
|
sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 5, nil, nil}, sample{9, 8, nil, nil},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 5, nil, nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{9, 8, nil, nil},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{1, 3}, {9, 9}},
|
|
},
|
|
{
|
|
name: "two chunks with first chunk deleted",
|
|
samples: [][]chunks.Sample{
|
|
{sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil}},
|
|
{sample{7, 89, nil, nil}, sample{9, 8, nil, nil}},
|
|
},
|
|
intervals: tombstones.Intervals{{Mint: 1, Maxt: 6}},
|
|
|
|
expected: []chunks.Sample{
|
|
sample{7, 89, nil, nil}, sample{9, 8, nil, nil},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{7, 89, nil, nil}, sample{9, 8, nil, nil},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{7, 9}},
|
|
},
|
|
// Deletion with seek.
|
|
{
|
|
name: "two chunks with trimmed first and last samples from edge chunks, seek from middle of first chunk",
|
|
samples: [][]chunks.Sample{
|
|
{sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil}},
|
|
{sample{7, 89, nil, nil}, sample{9, 8, nil, nil}},
|
|
},
|
|
intervals: tombstones.Intervals{{Mint: math.MinInt64, Maxt: 2}}.Add(tombstones.Interval{Mint: 9, Maxt: math.MaxInt64}),
|
|
|
|
seek: 3,
|
|
seekSuccess: true,
|
|
expected: []chunks.Sample{
|
|
sample{3, 5, nil, nil}, sample{6, 1, nil, nil}, sample{7, 89, nil, nil},
|
|
},
|
|
},
|
|
{
|
|
name: "one chunk where all samples are trimmed",
|
|
samples: [][]chunks.Sample{
|
|
{sample{2, 3, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil}},
|
|
{sample{7, 89, nil, nil}, sample{9, 8, nil, nil}},
|
|
},
|
|
intervals: tombstones.Intervals{{Mint: math.MinInt64, Maxt: 3}}.Add(tombstones.Interval{Mint: 4, Maxt: math.MaxInt64}),
|
|
|
|
expected: nil,
|
|
expectedChks: nil,
|
|
},
|
|
{
|
|
name: "one histogram chunk",
|
|
samples: [][]chunks.Sample{
|
|
{
|
|
sample{1, 0, tsdbutil.GenerateTestHistogram(1), nil},
|
|
sample{2, 0, tsdbutil.GenerateTestHistogram(2), nil},
|
|
sample{3, 0, tsdbutil.GenerateTestHistogram(3), nil},
|
|
sample{6, 0, tsdbutil.GenerateTestHistogram(6), nil},
|
|
},
|
|
},
|
|
expected: []chunks.Sample{
|
|
sample{1, 0, tsdbutil.GenerateTestHistogram(1), nil},
|
|
sample{2, 0, tsdbutil.SetHistogramNotCounterReset(tsdbutil.GenerateTestHistogram(2)), nil},
|
|
sample{3, 0, tsdbutil.SetHistogramNotCounterReset(tsdbutil.GenerateTestHistogram(3)), nil},
|
|
sample{6, 0, tsdbutil.SetHistogramNotCounterReset(tsdbutil.GenerateTestHistogram(6)), nil},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{1, 0, tsdbutil.GenerateTestHistogram(1), nil},
|
|
sample{2, 0, tsdbutil.SetHistogramNotCounterReset(tsdbutil.GenerateTestHistogram(2)), nil},
|
|
sample{3, 0, tsdbutil.SetHistogramNotCounterReset(tsdbutil.GenerateTestHistogram(3)), nil},
|
|
sample{6, 0, tsdbutil.SetHistogramNotCounterReset(tsdbutil.GenerateTestHistogram(6)), nil},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{1, 6}},
|
|
},
|
|
{
|
|
name: "one histogram chunk intersect with earlier deletion interval",
|
|
samples: [][]chunks.Sample{
|
|
{
|
|
sample{1, 0, tsdbutil.GenerateTestHistogram(1), nil},
|
|
sample{2, 0, tsdbutil.GenerateTestHistogram(2), nil},
|
|
sample{3, 0, tsdbutil.GenerateTestHistogram(3), nil},
|
|
sample{6, 0, tsdbutil.GenerateTestHistogram(6), nil},
|
|
},
|
|
},
|
|
intervals: tombstones.Intervals{{Mint: 1, Maxt: 2}},
|
|
expected: []chunks.Sample{
|
|
sample{3, 0, tsdbutil.SetHistogramNotCounterReset(tsdbutil.GenerateTestHistogram(3)), nil},
|
|
sample{6, 0, tsdbutil.SetHistogramNotCounterReset(tsdbutil.GenerateTestHistogram(6)), nil},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{3, 0, tsdbutil.SetHistogramNotCounterReset(tsdbutil.GenerateTestHistogram(3)), nil},
|
|
sample{6, 0, tsdbutil.SetHistogramNotCounterReset(tsdbutil.GenerateTestHistogram(6)), nil},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{3, 6}},
|
|
},
|
|
{
|
|
name: "one histogram chunk intersect with later deletion interval",
|
|
samples: [][]chunks.Sample{
|
|
{
|
|
sample{1, 0, tsdbutil.GenerateTestHistogram(1), nil},
|
|
sample{2, 0, tsdbutil.GenerateTestHistogram(2), nil},
|
|
sample{3, 0, tsdbutil.GenerateTestHistogram(3), nil},
|
|
sample{6, 0, tsdbutil.GenerateTestHistogram(6), nil},
|
|
},
|
|
},
|
|
intervals: tombstones.Intervals{{Mint: 5, Maxt: 20}},
|
|
expected: []chunks.Sample{
|
|
sample{1, 0, tsdbutil.GenerateTestHistogram(1), nil},
|
|
sample{2, 0, tsdbutil.SetHistogramNotCounterReset(tsdbutil.GenerateTestHistogram(2)), nil},
|
|
sample{3, 0, tsdbutil.SetHistogramNotCounterReset(tsdbutil.GenerateTestHistogram(3)), nil},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{1, 0, tsdbutil.GenerateTestHistogram(1), nil},
|
|
sample{2, 0, tsdbutil.SetHistogramNotCounterReset(tsdbutil.GenerateTestHistogram(2)), nil},
|
|
sample{3, 0, tsdbutil.SetHistogramNotCounterReset(tsdbutil.GenerateTestHistogram(3)), nil},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{1, 3}},
|
|
},
|
|
{
|
|
name: "one float histogram chunk",
|
|
samples: [][]chunks.Sample{
|
|
{
|
|
sample{1, 0, nil, tsdbutil.GenerateTestFloatHistogram(1)},
|
|
sample{2, 0, nil, tsdbutil.GenerateTestFloatHistogram(2)},
|
|
sample{3, 0, nil, tsdbutil.GenerateTestFloatHistogram(3)},
|
|
sample{6, 0, nil, tsdbutil.GenerateTestFloatHistogram(6)},
|
|
},
|
|
},
|
|
expected: []chunks.Sample{
|
|
sample{1, 0, nil, tsdbutil.GenerateTestFloatHistogram(1)},
|
|
sample{2, 0, nil, tsdbutil.SetFloatHistogramNotCounterReset(tsdbutil.GenerateTestFloatHistogram(2))},
|
|
sample{3, 0, nil, tsdbutil.SetFloatHistogramNotCounterReset(tsdbutil.GenerateTestFloatHistogram(3))},
|
|
sample{6, 0, nil, tsdbutil.SetFloatHistogramNotCounterReset(tsdbutil.GenerateTestFloatHistogram(6))},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{1, 0, nil, tsdbutil.GenerateTestFloatHistogram(1)},
|
|
sample{2, 0, nil, tsdbutil.SetFloatHistogramNotCounterReset(tsdbutil.GenerateTestFloatHistogram(2))},
|
|
sample{3, 0, nil, tsdbutil.SetFloatHistogramNotCounterReset(tsdbutil.GenerateTestFloatHistogram(3))},
|
|
sample{6, 0, nil, tsdbutil.SetFloatHistogramNotCounterReset(tsdbutil.GenerateTestFloatHistogram(6))},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{1, 6}},
|
|
},
|
|
{
|
|
name: "one float histogram chunk intersect with earlier deletion interval",
|
|
samples: [][]chunks.Sample{
|
|
{
|
|
sample{1, 0, nil, tsdbutil.GenerateTestFloatHistogram(1)},
|
|
sample{2, 0, nil, tsdbutil.GenerateTestFloatHistogram(2)},
|
|
sample{3, 0, nil, tsdbutil.GenerateTestFloatHistogram(3)},
|
|
sample{6, 0, nil, tsdbutil.GenerateTestFloatHistogram(6)},
|
|
},
|
|
},
|
|
intervals: tombstones.Intervals{{Mint: 1, Maxt: 2}},
|
|
expected: []chunks.Sample{
|
|
sample{3, 0, nil, tsdbutil.SetFloatHistogramNotCounterReset(tsdbutil.GenerateTestFloatHistogram(3))},
|
|
sample{6, 0, nil, tsdbutil.SetFloatHistogramNotCounterReset(tsdbutil.GenerateTestFloatHistogram(6))},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{3, 0, nil, tsdbutil.SetFloatHistogramNotCounterReset(tsdbutil.GenerateTestFloatHistogram(3))},
|
|
sample{6, 0, nil, tsdbutil.SetFloatHistogramNotCounterReset(tsdbutil.GenerateTestFloatHistogram(6))},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{3, 6}},
|
|
},
|
|
{
|
|
name: "one float histogram chunk intersect with later deletion interval",
|
|
samples: [][]chunks.Sample{
|
|
{
|
|
sample{1, 0, nil, tsdbutil.GenerateTestFloatHistogram(1)},
|
|
sample{2, 0, nil, tsdbutil.GenerateTestFloatHistogram(2)},
|
|
sample{3, 0, nil, tsdbutil.GenerateTestFloatHistogram(3)},
|
|
sample{6, 0, nil, tsdbutil.GenerateTestFloatHistogram(6)},
|
|
},
|
|
},
|
|
intervals: tombstones.Intervals{{Mint: 5, Maxt: 20}},
|
|
expected: []chunks.Sample{
|
|
sample{1, 0, nil, tsdbutil.GenerateTestFloatHistogram(1)},
|
|
sample{2, 0, nil, tsdbutil.SetFloatHistogramNotCounterReset(tsdbutil.GenerateTestFloatHistogram(2))},
|
|
sample{3, 0, nil, tsdbutil.SetFloatHistogramNotCounterReset(tsdbutil.GenerateTestFloatHistogram(3))},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{1, 0, nil, tsdbutil.GenerateTestFloatHistogram(1)},
|
|
sample{2, 0, nil, tsdbutil.SetFloatHistogramNotCounterReset(tsdbutil.GenerateTestFloatHistogram(2))},
|
|
sample{3, 0, nil, tsdbutil.SetFloatHistogramNotCounterReset(tsdbutil.GenerateTestFloatHistogram(3))},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{1, 3}},
|
|
},
|
|
{
|
|
name: "one gauge histogram chunk",
|
|
samples: [][]chunks.Sample{
|
|
{
|
|
sample{1, 0, tsdbutil.GenerateTestGaugeHistogram(1), nil},
|
|
sample{2, 0, tsdbutil.GenerateTestGaugeHistogram(2), nil},
|
|
sample{3, 0, tsdbutil.GenerateTestGaugeHistogram(3), nil},
|
|
sample{6, 0, tsdbutil.GenerateTestGaugeHistogram(6), nil},
|
|
},
|
|
},
|
|
expected: []chunks.Sample{
|
|
sample{1, 0, tsdbutil.GenerateTestGaugeHistogram(1), nil},
|
|
sample{2, 0, tsdbutil.GenerateTestGaugeHistogram(2), nil},
|
|
sample{3, 0, tsdbutil.GenerateTestGaugeHistogram(3), nil},
|
|
sample{6, 0, tsdbutil.GenerateTestGaugeHistogram(6), nil},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{1, 0, tsdbutil.GenerateTestGaugeHistogram(1), nil},
|
|
sample{2, 0, tsdbutil.GenerateTestGaugeHistogram(2), nil},
|
|
sample{3, 0, tsdbutil.GenerateTestGaugeHistogram(3), nil},
|
|
sample{6, 0, tsdbutil.GenerateTestGaugeHistogram(6), nil},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{1, 6}},
|
|
},
|
|
{
|
|
name: "one gauge histogram chunk intersect with earlier deletion interval",
|
|
samples: [][]chunks.Sample{
|
|
{
|
|
sample{1, 0, tsdbutil.GenerateTestGaugeHistogram(1), nil},
|
|
sample{2, 0, tsdbutil.GenerateTestGaugeHistogram(2), nil},
|
|
sample{3, 0, tsdbutil.GenerateTestGaugeHistogram(3), nil},
|
|
sample{6, 0, tsdbutil.GenerateTestGaugeHistogram(6), nil},
|
|
},
|
|
},
|
|
intervals: tombstones.Intervals{{Mint: 1, Maxt: 2}},
|
|
expected: []chunks.Sample{
|
|
sample{3, 0, tsdbutil.GenerateTestGaugeHistogram(3), nil},
|
|
sample{6, 0, tsdbutil.GenerateTestGaugeHistogram(6), nil},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{3, 0, tsdbutil.GenerateTestGaugeHistogram(3), nil},
|
|
sample{6, 0, tsdbutil.GenerateTestGaugeHistogram(6), nil},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{3, 6}},
|
|
},
|
|
{
|
|
name: "one gauge histogram chunk intersect with later deletion interval",
|
|
samples: [][]chunks.Sample{
|
|
{
|
|
sample{1, 0, tsdbutil.GenerateTestGaugeHistogram(1), nil},
|
|
sample{2, 0, tsdbutil.GenerateTestGaugeHistogram(2), nil},
|
|
sample{3, 0, tsdbutil.GenerateTestGaugeHistogram(3), nil},
|
|
sample{6, 0, tsdbutil.GenerateTestGaugeHistogram(6), nil},
|
|
},
|
|
},
|
|
intervals: tombstones.Intervals{{Mint: 5, Maxt: 20}},
|
|
expected: []chunks.Sample{
|
|
sample{1, 0, tsdbutil.GenerateTestGaugeHistogram(1), nil},
|
|
sample{2, 0, tsdbutil.GenerateTestGaugeHistogram(2), nil},
|
|
sample{3, 0, tsdbutil.GenerateTestGaugeHistogram(3), nil},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{1, 0, tsdbutil.GenerateTestGaugeHistogram(1), nil},
|
|
sample{2, 0, tsdbutil.GenerateTestGaugeHistogram(2), nil},
|
|
sample{3, 0, tsdbutil.GenerateTestGaugeHistogram(3), nil},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{1, 3}},
|
|
},
|
|
{
|
|
name: "one gauge float histogram",
|
|
samples: [][]chunks.Sample{
|
|
{
|
|
sample{1, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(1)},
|
|
sample{2, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(2)},
|
|
sample{3, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(3)},
|
|
sample{6, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(6)},
|
|
},
|
|
},
|
|
expected: []chunks.Sample{
|
|
sample{1, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(1)},
|
|
sample{2, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(2)},
|
|
sample{3, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(3)},
|
|
sample{6, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(6)},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{1, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(1)},
|
|
sample{2, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(2)},
|
|
sample{3, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(3)},
|
|
sample{6, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(6)},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{1, 6}},
|
|
},
|
|
{
|
|
name: "one gauge float histogram chunk intersect with earlier deletion interval",
|
|
samples: [][]chunks.Sample{
|
|
{
|
|
sample{1, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(1)},
|
|
sample{2, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(2)},
|
|
sample{3, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(3)},
|
|
sample{6, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(6)},
|
|
},
|
|
},
|
|
intervals: tombstones.Intervals{{Mint: 1, Maxt: 2}},
|
|
expected: []chunks.Sample{
|
|
sample{3, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(3)},
|
|
sample{6, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(6)},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{3, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(3)},
|
|
sample{6, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(6)},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{3, 6}},
|
|
},
|
|
{
|
|
name: "one gauge float histogram chunk intersect with later deletion interval",
|
|
samples: [][]chunks.Sample{
|
|
{
|
|
sample{1, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(1)},
|
|
sample{2, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(2)},
|
|
sample{3, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(3)},
|
|
sample{6, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(6)},
|
|
},
|
|
},
|
|
intervals: tombstones.Intervals{{Mint: 5, Maxt: 20}},
|
|
expected: []chunks.Sample{
|
|
sample{1, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(1)},
|
|
sample{2, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(2)},
|
|
sample{3, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(3)},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{1, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(1)},
|
|
sample{2, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(2)},
|
|
sample{3, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(3)},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{1, 3}},
|
|
},
|
|
{
|
|
name: "three full mixed chunks",
|
|
samples: [][]chunks.Sample{
|
|
{sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil}},
|
|
{
|
|
sample{7, 0, tsdbutil.GenerateTestGaugeHistogram(89), nil},
|
|
sample{9, 0, tsdbutil.GenerateTestGaugeHistogram(8), nil},
|
|
},
|
|
{
|
|
sample{10, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(22)},
|
|
sample{203, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(3493)},
|
|
},
|
|
},
|
|
|
|
expected: []chunks.Sample{
|
|
sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil}, sample{7, 0, tsdbutil.GenerateTestGaugeHistogram(89), nil}, sample{9, 0, tsdbutil.GenerateTestGaugeHistogram(8), nil}, sample{10, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(22)}, sample{203, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(3493)},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{1, 2, nil, nil}, sample{2, 3, nil, nil}, sample{3, 5, nil, nil}, sample{6, 1, nil, nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{7, 0, tsdbutil.GenerateTestGaugeHistogram(89), nil},
|
|
sample{9, 0, tsdbutil.GenerateTestGaugeHistogram(8), nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{10, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(22)},
|
|
sample{203, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(3493)},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{1, 6}, {7, 9}, {10, 203}},
|
|
},
|
|
{
|
|
name: "three full mixed chunks in different order",
|
|
samples: [][]chunks.Sample{
|
|
{
|
|
sample{7, 0, tsdbutil.GenerateTestGaugeHistogram(89), nil},
|
|
sample{9, 0, tsdbutil.GenerateTestGaugeHistogram(8), nil},
|
|
},
|
|
{sample{11, 2, nil, nil}, sample{12, 3, nil, nil}, sample{13, 5, nil, nil}, sample{16, 1, nil, nil}},
|
|
{
|
|
sample{100, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(22)},
|
|
sample{203, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(3493)},
|
|
},
|
|
},
|
|
|
|
expected: []chunks.Sample{
|
|
sample{7, 0, tsdbutil.GenerateTestGaugeHistogram(89), nil}, sample{9, 0, tsdbutil.GenerateTestGaugeHistogram(8), nil}, sample{11, 2, nil, nil}, sample{12, 3, nil, nil}, sample{13, 5, nil, nil}, sample{16, 1, nil, nil}, sample{100, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(22)}, sample{203, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(3493)},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{7, 0, tsdbutil.GenerateTestGaugeHistogram(89), nil},
|
|
sample{9, 0, tsdbutil.GenerateTestGaugeHistogram(8), nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{11, 2, nil, nil}, sample{12, 3, nil, nil}, sample{13, 5, nil, nil}, sample{16, 1, nil, nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{100, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(22)},
|
|
sample{203, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(3493)},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{7, 9}, {11, 16}, {100, 203}},
|
|
},
|
|
{
|
|
name: "three full mixed chunks in different order intersect with deletion interval",
|
|
samples: [][]chunks.Sample{
|
|
{
|
|
sample{7, 0, tsdbutil.GenerateTestGaugeHistogram(89), nil},
|
|
sample{9, 0, tsdbutil.GenerateTestGaugeHistogram(8), nil},
|
|
},
|
|
{sample{11, 2, nil, nil}, sample{12, 3, nil, nil}, sample{13, 5, nil, nil}, sample{16, 1, nil, nil}},
|
|
{
|
|
sample{100, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(22)},
|
|
sample{203, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(3493)},
|
|
},
|
|
},
|
|
intervals: tombstones.Intervals{{Mint: 8, Maxt: 11}, {Mint: 15, Maxt: 150}},
|
|
|
|
expected: []chunks.Sample{
|
|
sample{7, 0, tsdbutil.GenerateTestGaugeHistogram(89), nil}, sample{12, 3, nil, nil}, sample{13, 5, nil, nil}, sample{203, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(3493)},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{7, 0, tsdbutil.GenerateTestGaugeHistogram(89), nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{12, 3, nil, nil}, sample{13, 5, nil, nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{203, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(3493)},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{7, 7}, {12, 13}, {203, 203}},
|
|
},
|
|
{
|
|
name: "three full mixed chunks overlapping",
|
|
samples: [][]chunks.Sample{
|
|
{
|
|
sample{7, 0, tsdbutil.GenerateTestGaugeHistogram(89), nil},
|
|
sample{12, 0, tsdbutil.GenerateTestGaugeHistogram(8), nil},
|
|
},
|
|
{sample{11, 2, nil, nil}, sample{12, 3, nil, nil}, sample{13, 5, nil, nil}, sample{16, 1, nil, nil}},
|
|
{
|
|
sample{10, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(22)},
|
|
sample{203, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(3493)},
|
|
},
|
|
},
|
|
|
|
expected: []chunks.Sample{
|
|
sample{7, 0, tsdbutil.GenerateTestGaugeHistogram(89), nil}, sample{12, 0, tsdbutil.GenerateTestGaugeHistogram(8), nil}, sample{11, 2, nil, nil}, sample{12, 3, nil, nil}, sample{13, 5, nil, nil}, sample{16, 1, nil, nil}, sample{10, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(22)}, sample{203, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(3493)},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{7, 0, tsdbutil.GenerateTestGaugeHistogram(89), nil},
|
|
sample{12, 0, tsdbutil.GenerateTestGaugeHistogram(8), nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{11, 2, nil, nil}, sample{12, 3, nil, nil}, sample{13, 5, nil, nil}, sample{16, 1, nil, nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{10, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(22)},
|
|
sample{203, 0, nil, tsdbutil.GenerateTestGaugeFloatHistogram(3493)},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{{7, 12}, {11, 16}, {10, 203}},
|
|
},
|
|
{
|
|
// This case won't actually happen until OOO native histograms is implemented.
|
|
// Issue: https://github.com/prometheus/prometheus/issues/11220.
|
|
name: "int histogram iterables with counter resets",
|
|
samples: [][]chunks.Sample{
|
|
{
|
|
sample{7, 0, tsdbutil.GenerateTestHistogram(8), nil},
|
|
sample{8, 0, tsdbutil.GenerateTestHistogram(9), nil},
|
|
// Counter reset should be detected when chunks are created from the iterable.
|
|
sample{12, 0, tsdbutil.GenerateTestHistogram(5), nil},
|
|
sample{15, 0, tsdbutil.GenerateTestHistogram(6), nil},
|
|
sample{16, 0, tsdbutil.GenerateTestHistogram(7), nil},
|
|
// Counter reset should be detected when chunks are created from the iterable.
|
|
sample{17, 0, tsdbutil.GenerateTestHistogram(5), nil},
|
|
},
|
|
{
|
|
sample{18, 0, tsdbutil.GenerateTestHistogram(6), nil},
|
|
sample{19, 0, tsdbutil.GenerateTestHistogram(7), nil},
|
|
// Counter reset should be detected when chunks are created from the iterable.
|
|
sample{20, 0, tsdbutil.GenerateTestHistogram(5), nil},
|
|
sample{21, 0, tsdbutil.GenerateTestHistogram(6), nil},
|
|
},
|
|
},
|
|
|
|
expected: []chunks.Sample{
|
|
sample{7, 0, tsdbutil.GenerateTestHistogram(8), nil},
|
|
sample{8, 0, tsdbutil.GenerateTestHistogram(9), nil},
|
|
sample{12, 0, tsdbutil.GenerateTestHistogram(5), nil},
|
|
sample{15, 0, tsdbutil.GenerateTestHistogram(6), nil},
|
|
sample{16, 0, tsdbutil.GenerateTestHistogram(7), nil},
|
|
sample{17, 0, tsdbutil.GenerateTestHistogram(5), nil},
|
|
sample{18, 0, tsdbutil.GenerateTestHistogram(6), nil},
|
|
sample{19, 0, tsdbutil.GenerateTestHistogram(7), nil},
|
|
sample{20, 0, tsdbutil.GenerateTestHistogram(5), nil},
|
|
sample{21, 0, tsdbutil.GenerateTestHistogram(6), nil},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{7, 0, tsdbutil.GenerateTestHistogram(8), nil},
|
|
sample{8, 0, tsdbutil.SetHistogramNotCounterReset(tsdbutil.GenerateTestHistogram(9)), nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{12, 0, tsdbutil.SetHistogramCounterReset(tsdbutil.GenerateTestHistogram(5)), nil},
|
|
sample{15, 0, tsdbutil.SetHistogramNotCounterReset(tsdbutil.GenerateTestHistogram(6)), nil},
|
|
sample{16, 0, tsdbutil.SetHistogramNotCounterReset(tsdbutil.GenerateTestHistogram(7)), nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{17, 0, tsdbutil.SetHistogramCounterReset(tsdbutil.GenerateTestHistogram(5)), nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{18, 0, tsdbutil.GenerateTestHistogram(6), nil},
|
|
sample{19, 0, tsdbutil.SetHistogramNotCounterReset(tsdbutil.GenerateTestHistogram(7)), nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{20, 0, tsdbutil.SetHistogramCounterReset(tsdbutil.GenerateTestHistogram(5)), nil},
|
|
sample{21, 0, tsdbutil.SetHistogramNotCounterReset(tsdbutil.GenerateTestHistogram(6)), nil},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{
|
|
{7, 8},
|
|
{12, 16},
|
|
{17, 17},
|
|
{18, 19},
|
|
{20, 21},
|
|
},
|
|
|
|
// Skipping chunk test - can't create a single chunk for each
|
|
// sample slice since there are counter resets in the middle of
|
|
// the slices.
|
|
skipChunkTest: true,
|
|
},
|
|
{
|
|
// This case won't actually happen until OOO native histograms is implemented.
|
|
// Issue: https://github.com/prometheus/prometheus/issues/11220.
|
|
name: "float histogram iterables with counter resets",
|
|
samples: [][]chunks.Sample{
|
|
{
|
|
sample{7, 0, nil, tsdbutil.GenerateTestFloatHistogram(8)},
|
|
sample{8, 0, nil, tsdbutil.GenerateTestFloatHistogram(9)},
|
|
// Counter reset should be detected when chunks are created from the iterable.
|
|
sample{12, 0, nil, tsdbutil.GenerateTestFloatHistogram(5)},
|
|
sample{15, 0, nil, tsdbutil.GenerateTestFloatHistogram(6)},
|
|
sample{16, 0, nil, tsdbutil.GenerateTestFloatHistogram(7)},
|
|
// Counter reset should be detected when chunks are created from the iterable.
|
|
sample{17, 0, nil, tsdbutil.GenerateTestFloatHistogram(5)},
|
|
},
|
|
{
|
|
sample{18, 0, nil, tsdbutil.GenerateTestFloatHistogram(6)},
|
|
sample{19, 0, nil, tsdbutil.GenerateTestFloatHistogram(7)},
|
|
// Counter reset should be detected when chunks are created from the iterable.
|
|
sample{20, 0, nil, tsdbutil.GenerateTestFloatHistogram(5)},
|
|
sample{21, 0, nil, tsdbutil.GenerateTestFloatHistogram(6)},
|
|
},
|
|
},
|
|
|
|
expected: []chunks.Sample{
|
|
sample{7, 0, nil, tsdbutil.GenerateTestFloatHistogram(8)},
|
|
sample{8, 0, nil, tsdbutil.GenerateTestFloatHistogram(9)},
|
|
sample{12, 0, nil, tsdbutil.GenerateTestFloatHistogram(5)},
|
|
sample{15, 0, nil, tsdbutil.GenerateTestFloatHistogram(6)},
|
|
sample{16, 0, nil, tsdbutil.GenerateTestFloatHistogram(7)},
|
|
sample{17, 0, nil, tsdbutil.GenerateTestFloatHistogram(5)},
|
|
sample{18, 0, nil, tsdbutil.GenerateTestFloatHistogram(6)},
|
|
sample{19, 0, nil, tsdbutil.GenerateTestFloatHistogram(7)},
|
|
sample{20, 0, nil, tsdbutil.GenerateTestFloatHistogram(5)},
|
|
sample{21, 0, nil, tsdbutil.GenerateTestFloatHistogram(6)},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{7, 0, nil, tsdbutil.GenerateTestFloatHistogram(8)},
|
|
sample{8, 0, nil, tsdbutil.SetFloatHistogramNotCounterReset(tsdbutil.GenerateTestFloatHistogram(9))},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{12, 0, nil, tsdbutil.SetFloatHistogramCounterReset(tsdbutil.GenerateTestFloatHistogram(5))},
|
|
sample{15, 0, nil, tsdbutil.SetFloatHistogramNotCounterReset(tsdbutil.GenerateTestFloatHistogram(6))},
|
|
sample{16, 0, nil, tsdbutil.SetFloatHistogramNotCounterReset(tsdbutil.GenerateTestFloatHistogram(7))},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{17, 0, nil, tsdbutil.SetFloatHistogramCounterReset(tsdbutil.GenerateTestFloatHistogram(5))},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{18, 0, nil, tsdbutil.GenerateTestFloatHistogram(6)},
|
|
sample{19, 0, nil, tsdbutil.SetFloatHistogramNotCounterReset(tsdbutil.GenerateTestFloatHistogram(7))},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{20, 0, nil, tsdbutil.SetFloatHistogramCounterReset(tsdbutil.GenerateTestFloatHistogram(5))},
|
|
sample{21, 0, nil, tsdbutil.SetFloatHistogramNotCounterReset(tsdbutil.GenerateTestFloatHistogram(6))},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{
|
|
{7, 8},
|
|
{12, 16},
|
|
{17, 17},
|
|
{18, 19},
|
|
{20, 21},
|
|
},
|
|
|
|
// Skipping chunk test - can't create a single chunk for each
|
|
// sample slice since there are counter resets in the middle of
|
|
// the slices.
|
|
skipChunkTest: true,
|
|
},
|
|
{
|
|
// This case won't actually happen until OOO native histograms is implemented.
|
|
// Issue: https://github.com/prometheus/prometheus/issues/11220.
|
|
name: "iterables with mixed encodings and counter resets",
|
|
samples: [][]chunks.Sample{
|
|
{
|
|
sample{7, 0, tsdbutil.GenerateTestHistogram(8), nil},
|
|
sample{8, 0, tsdbutil.GenerateTestHistogram(9), nil},
|
|
sample{9, 0, nil, tsdbutil.GenerateTestFloatHistogram(10)},
|
|
sample{10, 0, nil, tsdbutil.GenerateTestFloatHistogram(11)},
|
|
sample{11, 0, nil, tsdbutil.GenerateTestFloatHistogram(12)},
|
|
sample{12, 13, nil, nil},
|
|
sample{13, 14, nil, nil},
|
|
sample{14, 0, tsdbutil.GenerateTestHistogram(8), nil},
|
|
// Counter reset should be detected when chunks are created from the iterable.
|
|
sample{15, 0, tsdbutil.GenerateTestHistogram(7), nil},
|
|
},
|
|
{
|
|
sample{18, 0, tsdbutil.GenerateTestHistogram(6), nil},
|
|
sample{19, 45, nil, nil},
|
|
},
|
|
},
|
|
|
|
expected: []chunks.Sample{
|
|
sample{7, 0, tsdbutil.GenerateTestHistogram(8), nil},
|
|
sample{8, 0, tsdbutil.GenerateTestHistogram(9), nil},
|
|
sample{9, 0, nil, tsdbutil.GenerateTestFloatHistogram(10)},
|
|
sample{10, 0, nil, tsdbutil.GenerateTestFloatHistogram(11)},
|
|
sample{11, 0, nil, tsdbutil.GenerateTestFloatHistogram(12)},
|
|
sample{12, 13, nil, nil},
|
|
sample{13, 14, nil, nil},
|
|
sample{14, 0, tsdbutil.GenerateTestHistogram(8), nil},
|
|
sample{15, 0, tsdbutil.GenerateTestHistogram(7), nil},
|
|
sample{18, 0, tsdbutil.GenerateTestHistogram(6), nil},
|
|
sample{19, 45, nil, nil},
|
|
},
|
|
expectedChks: []chunks.Meta{
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{7, 0, tsdbutil.GenerateTestHistogram(8), nil},
|
|
sample{8, 0, tsdbutil.GenerateTestHistogram(9), nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{9, 0, nil, tsdbutil.GenerateTestFloatHistogram(10)},
|
|
sample{10, 0, nil, tsdbutil.GenerateTestFloatHistogram(11)},
|
|
sample{11, 0, nil, tsdbutil.GenerateTestFloatHistogram(12)},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{12, 13, nil, nil},
|
|
sample{13, 14, nil, nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{14, 0, tsdbutil.GenerateTestHistogram(8), nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{15, 0, tsdbutil.SetHistogramCounterReset(tsdbutil.GenerateTestHistogram(7)), nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{18, 0, tsdbutil.GenerateTestHistogram(6), nil},
|
|
}),
|
|
assureChunkFromSamples(t, []chunks.Sample{
|
|
sample{19, 45, nil, nil},
|
|
}),
|
|
},
|
|
expectedMinMaxTimes: []minMaxTimes{
|
|
{7, 8},
|
|
{9, 11},
|
|
{12, 13},
|
|
{14, 14},
|
|
{15, 15},
|
|
{18, 18},
|
|
{19, 19},
|
|
},
|
|
|
|
skipChunkTest: true,
|
|
},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Run("sample", func(t *testing.T) {
|
|
var f *fakeChunksReader
|
|
var chkMetas []chunks.Meta
|
|
// If the test case wants to skip the chunks test, it probably
|
|
// means you can't create valid chunks from sample slices,
|
|
// therefore create iterables over the samples instead.
|
|
if tc.skipChunkTest {
|
|
f, chkMetas = createFakeReaderAndIterables(tc.samples...)
|
|
} else {
|
|
f, chkMetas = createFakeReaderAndNotPopulatedChunks(tc.samples...)
|
|
}
|
|
it := &populateWithDelSeriesIterator{}
|
|
it.reset(ulid.ULID{}, f, chkMetas, tc.intervals)
|
|
|
|
var r []chunks.Sample
|
|
if tc.seek != 0 {
|
|
require.Equal(t, tc.seekSuccess, it.Seek(tc.seek) == chunkenc.ValFloat)
|
|
require.Equal(t, tc.seekSuccess, it.Seek(tc.seek) == chunkenc.ValFloat) // Next one should be noop.
|
|
|
|
if tc.seekSuccess {
|
|
// After successful seek iterator is ready. Grab the value.
|
|
t, v := it.At()
|
|
r = append(r, sample{t: t, f: v})
|
|
}
|
|
}
|
|
expandedResult, err := storage.ExpandSamples(it, newSample)
|
|
require.NoError(t, err)
|
|
r = append(r, expandedResult...)
|
|
require.Equal(t, tc.expected, r)
|
|
})
|
|
t.Run("chunk", func(t *testing.T) {
|
|
if tc.skipChunkTest {
|
|
t.Skip()
|
|
}
|
|
f, chkMetas := createFakeReaderAndNotPopulatedChunks(tc.samples...)
|
|
it := &populateWithDelChunkSeriesIterator{}
|
|
it.reset(ulid.ULID{}, f, chkMetas, tc.intervals)
|
|
|
|
if tc.seek != 0 {
|
|
// Chunk iterator does not have Seek method.
|
|
return
|
|
}
|
|
expandedResult, err := storage.ExpandChunks(it)
|
|
require.NoError(t, err)
|
|
|
|
// We don't care about ref IDs for comparison, only chunk's samples matters.
|
|
rmChunkRefs(expandedResult)
|
|
rmChunkRefs(tc.expectedChks)
|
|
require.Equal(t, tc.expectedChks, expandedResult)
|
|
|
|
for i, meta := range expandedResult {
|
|
require.Equal(t, tc.expectedMinMaxTimes[i].minTime, meta.MinTime)
|
|
require.Equal(t, tc.expectedMinMaxTimes[i].maxTime, meta.MaxTime)
|
|
}
|
|
})
|
|
t.Run("iterables", func(t *testing.T) {
|
|
if tc.skipIterableTest {
|
|
t.Skip()
|
|
}
|
|
f, chkMetas := createFakeReaderAndIterables(tc.samples...)
|
|
it := &populateWithDelChunkSeriesIterator{}
|
|
it.reset(ulid.ULID{}, f, chkMetas, tc.intervals)
|
|
|
|
if tc.seek != 0 {
|
|
// Chunk iterator does not have Seek method.
|
|
return
|
|
}
|
|
expandedResult, err := storage.ExpandChunks(it)
|
|
require.NoError(t, err)
|
|
|
|
// We don't care about ref IDs for comparison, only chunk's samples matters.
|
|
rmChunkRefs(expandedResult)
|
|
rmChunkRefs(tc.expectedChks)
|
|
require.Equal(t, tc.expectedChks, expandedResult)
|
|
|
|
for i, meta := range expandedResult {
|
|
require.Equal(t, tc.expectedMinMaxTimes[i].minTime, meta.MinTime)
|
|
require.Equal(t, tc.expectedMinMaxTimes[i].maxTime, meta.MaxTime)
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
func rmChunkRefs(chks []chunks.Meta) {
|
|
for i := range chks {
|
|
chks[i].Ref = 0
|
|
}
|
|
}
|
|
|
|
func checkCurrVal(t *testing.T, valType chunkenc.ValueType, it *populateWithDelSeriesIterator, expectedTs, expectedValue int) {
|
|
switch valType {
|
|
case chunkenc.ValFloat:
|
|
ts, v := it.At()
|
|
require.Equal(t, int64(expectedTs), ts)
|
|
require.Equal(t, float64(expectedValue), v)
|
|
case chunkenc.ValHistogram:
|
|
ts, h := it.AtHistogram(nil)
|
|
require.Equal(t, int64(expectedTs), ts)
|
|
h.CounterResetHint = histogram.UnknownCounterReset
|
|
require.Equal(t, tsdbutil.GenerateTestHistogram(expectedValue), h)
|
|
case chunkenc.ValFloatHistogram:
|
|
ts, h := it.AtFloatHistogram(nil)
|
|
require.Equal(t, int64(expectedTs), ts)
|
|
h.CounterResetHint = histogram.UnknownCounterReset
|
|
require.Equal(t, tsdbutil.GenerateTestFloatHistogram(expectedValue), h)
|
|
default:
|
|
panic("unexpected value type")
|
|
}
|
|
}
|
|
|
|
// Regression for: https://github.com/prometheus/tsdb/pull/97
|
|
func TestPopulateWithDelSeriesIterator_DoubleSeek(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
valType chunkenc.ValueType
|
|
chks [][]chunks.Sample
|
|
}{
|
|
{
|
|
name: "float",
|
|
valType: chunkenc.ValFloat,
|
|
chks: [][]chunks.Sample{
|
|
{},
|
|
{sample{1, 1, nil, nil}, sample{2, 2, nil, nil}, sample{3, 3, nil, nil}},
|
|
{sample{4, 4, nil, nil}, sample{5, 5, nil, nil}},
|
|
},
|
|
},
|
|
{
|
|
name: "histogram",
|
|
valType: chunkenc.ValHistogram,
|
|
chks: [][]chunks.Sample{
|
|
{},
|
|
{sample{1, 0, tsdbutil.GenerateTestHistogram(1), nil}, sample{2, 0, tsdbutil.GenerateTestHistogram(2), nil}, sample{3, 0, tsdbutil.GenerateTestHistogram(3), nil}},
|
|
{sample{4, 0, tsdbutil.GenerateTestHistogram(4), nil}, sample{5, 0, tsdbutil.GenerateTestHistogram(5), nil}},
|
|
},
|
|
},
|
|
{
|
|
name: "float histogram",
|
|
valType: chunkenc.ValFloatHistogram,
|
|
chks: [][]chunks.Sample{
|
|
{},
|
|
{sample{1, 0, nil, tsdbutil.GenerateTestFloatHistogram(1)}, sample{2, 0, nil, tsdbutil.GenerateTestFloatHistogram(2)}, sample{3, 0, nil, tsdbutil.GenerateTestFloatHistogram(3)}},
|
|
{sample{4, 0, nil, tsdbutil.GenerateTestFloatHistogram(4)}, sample{5, 0, nil, tsdbutil.GenerateTestFloatHistogram(5)}},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
f, chkMetas := createFakeReaderAndNotPopulatedChunks(tc.chks...)
|
|
it := &populateWithDelSeriesIterator{}
|
|
it.reset(ulid.ULID{}, f, chkMetas, nil)
|
|
require.Equal(t, tc.valType, it.Seek(1))
|
|
require.Equal(t, tc.valType, it.Seek(2))
|
|
require.Equal(t, tc.valType, it.Seek(2))
|
|
checkCurrVal(t, tc.valType, it, 2, 2)
|
|
require.Equal(t, int64(0), chkMetas[0].MinTime)
|
|
require.Equal(t, int64(1), chkMetas[1].MinTime)
|
|
require.Equal(t, int64(4), chkMetas[2].MinTime)
|
|
})
|
|
}
|
|
}
|
|
|
|
// Regression when seeked chunks were still found via binary search and we always
|
|
// skipped to the end when seeking a value in the current chunk.
|
|
func TestPopulateWithDelSeriesIterator_SeekInCurrentChunk(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
valType chunkenc.ValueType
|
|
chks [][]chunks.Sample
|
|
}{
|
|
{
|
|
name: "float",
|
|
valType: chunkenc.ValFloat,
|
|
chks: [][]chunks.Sample{
|
|
{},
|
|
{sample{1, 2, nil, nil}, sample{3, 4, nil, nil}, sample{5, 6, nil, nil}, sample{7, 8, nil, nil}},
|
|
{},
|
|
},
|
|
},
|
|
{
|
|
name: "histogram",
|
|
valType: chunkenc.ValHistogram,
|
|
chks: [][]chunks.Sample{
|
|
{},
|
|
{sample{1, 0, tsdbutil.GenerateTestHistogram(2), nil}, sample{3, 0, tsdbutil.GenerateTestHistogram(4), nil}, sample{5, 0, tsdbutil.GenerateTestHistogram(6), nil}, sample{7, 0, tsdbutil.GenerateTestHistogram(8), nil}},
|
|
{},
|
|
},
|
|
},
|
|
{
|
|
name: "float histogram",
|
|
valType: chunkenc.ValFloatHistogram,
|
|
chks: [][]chunks.Sample{
|
|
{},
|
|
{sample{1, 0, nil, tsdbutil.GenerateTestFloatHistogram(2)}, sample{3, 0, nil, tsdbutil.GenerateTestFloatHistogram(4)}, sample{5, 0, nil, tsdbutil.GenerateTestFloatHistogram(6)}, sample{7, 0, nil, tsdbutil.GenerateTestFloatHistogram(8)}},
|
|
{},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
f, chkMetas := createFakeReaderAndNotPopulatedChunks(tc.chks...)
|
|
it := &populateWithDelSeriesIterator{}
|
|
it.reset(ulid.ULID{}, f, chkMetas, nil)
|
|
require.Equal(t, tc.valType, it.Next())
|
|
checkCurrVal(t, tc.valType, it, 1, 2)
|
|
require.Equal(t, tc.valType, it.Seek(4))
|
|
checkCurrVal(t, tc.valType, it, 5, 6)
|
|
require.Equal(t, int64(0), chkMetas[0].MinTime)
|
|
require.Equal(t, int64(1), chkMetas[1].MinTime)
|
|
require.Equal(t, int64(0), chkMetas[2].MinTime)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestPopulateWithDelSeriesIterator_SeekWithMinTime(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
valType chunkenc.ValueType
|
|
chks [][]chunks.Sample
|
|
}{
|
|
{
|
|
name: "float",
|
|
valType: chunkenc.ValFloat,
|
|
chks: [][]chunks.Sample{
|
|
{sample{1, 6, nil, nil}, sample{5, 6, nil, nil}, sample{6, 8, nil, nil}},
|
|
},
|
|
},
|
|
{
|
|
name: "histogram",
|
|
valType: chunkenc.ValHistogram,
|
|
chks: [][]chunks.Sample{
|
|
{sample{1, 0, tsdbutil.GenerateTestHistogram(6), nil}, sample{5, 0, tsdbutil.GenerateTestHistogram(6), nil}, sample{6, 0, tsdbutil.GenerateTestHistogram(8), nil}},
|
|
},
|
|
},
|
|
{
|
|
name: "float histogram",
|
|
valType: chunkenc.ValFloatHistogram,
|
|
chks: [][]chunks.Sample{
|
|
{sample{1, 0, nil, tsdbutil.GenerateTestFloatHistogram(6)}, sample{5, 0, nil, tsdbutil.GenerateTestFloatHistogram(6)}, sample{6, 0, nil, tsdbutil.GenerateTestFloatHistogram(8)}},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
f, chkMetas := createFakeReaderAndNotPopulatedChunks(tc.chks...)
|
|
it := &populateWithDelSeriesIterator{}
|
|
it.reset(ulid.ULID{}, f, chkMetas, nil)
|
|
require.Equal(t, chunkenc.ValNone, it.Seek(7))
|
|
require.Equal(t, tc.valType, it.Seek(3))
|
|
require.Equal(t, int64(1), chkMetas[0].MinTime)
|
|
})
|
|
}
|
|
}
|
|
|
|
// Regression when calling Next() with a time bounded to fit within two samples.
|
|
// Seek gets called and advances beyond the max time, which was just accepted as a valid sample.
|
|
func TestPopulateWithDelSeriesIterator_NextWithMinTime(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
valType chunkenc.ValueType
|
|
chks [][]chunks.Sample
|
|
}{
|
|
{
|
|
name: "float",
|
|
valType: chunkenc.ValFloat,
|
|
chks: [][]chunks.Sample{
|
|
{sample{1, 6, nil, nil}, sample{5, 6, nil, nil}, sample{7, 8, nil, nil}},
|
|
},
|
|
},
|
|
{
|
|
name: "histogram",
|
|
valType: chunkenc.ValHistogram,
|
|
chks: [][]chunks.Sample{
|
|
{sample{1, 0, tsdbutil.GenerateTestHistogram(6), nil}, sample{5, 0, tsdbutil.GenerateTestHistogram(6), nil}, sample{7, 0, tsdbutil.GenerateTestHistogram(8), nil}},
|
|
},
|
|
},
|
|
{
|
|
name: "float histogram",
|
|
valType: chunkenc.ValFloatHistogram,
|
|
chks: [][]chunks.Sample{
|
|
{sample{1, 0, nil, tsdbutil.GenerateTestFloatHistogram(6)}, sample{5, 0, nil, tsdbutil.GenerateTestFloatHistogram(6)}, sample{7, 0, nil, tsdbutil.GenerateTestFloatHistogram(8)}},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
f, chkMetas := createFakeReaderAndNotPopulatedChunks(tc.chks...)
|
|
it := &populateWithDelSeriesIterator{}
|
|
it.reset(ulid.ULID{}, f, chkMetas, tombstones.Intervals{{Mint: math.MinInt64, Maxt: 2}}.Add(tombstones.Interval{Mint: 4, Maxt: math.MaxInt64}))
|
|
require.Equal(t, chunkenc.ValNone, it.Next())
|
|
require.Equal(t, int64(1), chkMetas[0].MinTime)
|
|
})
|
|
}
|
|
}
|
|
|
|
// Test the cost of merging series sets for different number of merged sets and their size.
|
|
// The subset are all equivalent so this does not capture merging of partial or non-overlapping sets well.
|
|
// TODO(bwplotka): Merge with storage merged series set benchmark.
|
|
func BenchmarkMergedSeriesSet(b *testing.B) {
|
|
sel := func(sets []storage.SeriesSet) storage.SeriesSet {
|
|
return storage.NewMergeSeriesSet(sets, storage.ChainedSeriesMerge)
|
|
}
|
|
|
|
for _, k := range []int{
|
|
100,
|
|
1000,
|
|
10000,
|
|
20000,
|
|
} {
|
|
for _, j := range []int{1, 2, 4, 8, 16, 32} {
|
|
b.Run(fmt.Sprintf("series=%d,blocks=%d", k, j), func(b *testing.B) {
|
|
lbls, err := labels.ReadLabels(filepath.Join("testdata", "20kseries.json"), k)
|
|
require.NoError(b, err)
|
|
|
|
sort.Sort(labels.Slice(lbls))
|
|
|
|
in := make([][]storage.Series, j)
|
|
|
|
for _, l := range lbls {
|
|
l2 := l
|
|
for j := range in {
|
|
in[j] = append(in[j], storage.NewListSeries(l2, nil))
|
|
}
|
|
}
|
|
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
var sets []storage.SeriesSet
|
|
for _, s := range in {
|
|
sets = append(sets, newMockSeriesSet(s))
|
|
}
|
|
ms := sel(sets)
|
|
|
|
i := 0
|
|
for ms.Next() {
|
|
i++
|
|
}
|
|
require.NoError(b, ms.Err())
|
|
require.Len(b, lbls, i)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
type mockChunkReader map[chunks.ChunkRef]chunkenc.Chunk
|
|
|
|
func (cr mockChunkReader) ChunkOrIterable(meta chunks.Meta) (chunkenc.Chunk, chunkenc.Iterable, error) {
|
|
chk, ok := cr[meta.Ref]
|
|
if ok {
|
|
return chk, nil, nil
|
|
}
|
|
|
|
return nil, nil, errors.New("Chunk with ref not found")
|
|
}
|
|
|
|
func (cr mockChunkReader) Close() error {
|
|
return nil
|
|
}
|
|
|
|
func TestDeletedIterator(t *testing.T) {
|
|
chk := chunkenc.NewXORChunk()
|
|
app, err := chk.Appender()
|
|
require.NoError(t, err)
|
|
// Insert random stuff from (0, 1000).
|
|
act := make([]sample, 1000)
|
|
for i := 0; i < 1000; i++ {
|
|
act[i].t = int64(i)
|
|
act[i].f = rand.Float64()
|
|
app.Append(act[i].t, act[i].f)
|
|
}
|
|
|
|
cases := []struct {
|
|
r tombstones.Intervals
|
|
}{
|
|
{r: tombstones.Intervals{{Mint: 1, Maxt: 20}}},
|
|
{r: tombstones.Intervals{{Mint: 1, Maxt: 10}, {Mint: 12, Maxt: 20}, {Mint: 21, Maxt: 23}, {Mint: 25, Maxt: 30}}},
|
|
{r: tombstones.Intervals{{Mint: 1, Maxt: 10}, {Mint: 12, Maxt: 20}, {Mint: 20, Maxt: 30}}},
|
|
{r: tombstones.Intervals{{Mint: 1, Maxt: 10}, {Mint: 12, Maxt: 23}, {Mint: 25, Maxt: 30}}},
|
|
{r: tombstones.Intervals{{Mint: 1, Maxt: 23}, {Mint: 12, Maxt: 20}, {Mint: 25, Maxt: 30}}},
|
|
{r: tombstones.Intervals{{Mint: 1, Maxt: 23}, {Mint: 12, Maxt: 20}, {Mint: 25, Maxt: 3000}}},
|
|
{r: tombstones.Intervals{{Mint: 0, Maxt: 2000}}},
|
|
{r: tombstones.Intervals{{Mint: 500, Maxt: 2000}}},
|
|
{r: tombstones.Intervals{{Mint: 0, Maxt: 200}}},
|
|
{r: tombstones.Intervals{{Mint: 1000, Maxt: 20000}}},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
i := int64(-1)
|
|
it := &DeletedIterator{Iter: chk.Iterator(nil), Intervals: c.r[:]}
|
|
ranges := c.r[:]
|
|
for it.Next() == chunkenc.ValFloat {
|
|
i++
|
|
for _, tr := range ranges {
|
|
if tr.InBounds(i) {
|
|
i = tr.Maxt + 1
|
|
ranges = ranges[1:]
|
|
}
|
|
}
|
|
|
|
require.Less(t, i, int64(1000))
|
|
|
|
ts, v := it.At()
|
|
require.Equal(t, act[i].t, ts)
|
|
require.Equal(t, act[i].f, v)
|
|
}
|
|
// There has been an extra call to Next().
|
|
i++
|
|
for _, tr := range ranges {
|
|
if tr.InBounds(i) {
|
|
i = tr.Maxt + 1
|
|
ranges = ranges[1:]
|
|
}
|
|
}
|
|
|
|
require.GreaterOrEqual(t, i, int64(1000))
|
|
require.NoError(t, it.Err())
|
|
}
|
|
}
|
|
|
|
func TestDeletedIterator_WithSeek(t *testing.T) {
|
|
chk := chunkenc.NewXORChunk()
|
|
app, err := chk.Appender()
|
|
require.NoError(t, err)
|
|
// Insert random stuff from (0, 1000).
|
|
act := make([]sample, 1000)
|
|
for i := 0; i < 1000; i++ {
|
|
act[i].t = int64(i)
|
|
act[i].f = float64(i)
|
|
app.Append(act[i].t, act[i].f)
|
|
}
|
|
|
|
cases := []struct {
|
|
r tombstones.Intervals
|
|
seek int64
|
|
ok bool
|
|
seekedTs int64
|
|
}{
|
|
{r: tombstones.Intervals{{Mint: 1, Maxt: 20}}, seek: 1, ok: true, seekedTs: 21},
|
|
{r: tombstones.Intervals{{Mint: 1, Maxt: 20}}, seek: 20, ok: true, seekedTs: 21},
|
|
{r: tombstones.Intervals{{Mint: 1, Maxt: 20}}, seek: 10, ok: true, seekedTs: 21},
|
|
{r: tombstones.Intervals{{Mint: 1, Maxt: 20}}, seek: 999, ok: true, seekedTs: 999},
|
|
{r: tombstones.Intervals{{Mint: 1, Maxt: 20}}, seek: 1000, ok: false},
|
|
{r: tombstones.Intervals{{Mint: 1, Maxt: 23}, {Mint: 24, Maxt: 40}, {Mint: 45, Maxt: 3000}}, seek: 1, ok: true, seekedTs: 41},
|
|
{r: tombstones.Intervals{{Mint: 5, Maxt: 23}, {Mint: 24, Maxt: 40}, {Mint: 41, Maxt: 3000}}, seek: 5, ok: false},
|
|
{r: tombstones.Intervals{{Mint: 0, Maxt: 2000}}, seek: 10, ok: false},
|
|
{r: tombstones.Intervals{{Mint: 500, Maxt: 2000}}, seek: 10, ok: true, seekedTs: 10},
|
|
{r: tombstones.Intervals{{Mint: 500, Maxt: 2000}}, seek: 501, ok: false},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
it := &DeletedIterator{Iter: chk.Iterator(nil), Intervals: c.r[:]}
|
|
|
|
require.Equal(t, c.ok, it.Seek(c.seek) == chunkenc.ValFloat)
|
|
if c.ok {
|
|
ts := it.AtT()
|
|
require.Equal(t, c.seekedTs, ts)
|
|
}
|
|
}
|
|
}
|
|
|
|
type series struct {
|
|
l labels.Labels
|
|
chunks []chunks.Meta
|
|
}
|
|
|
|
type mockIndex struct {
|
|
series map[storage.SeriesRef]series
|
|
postings map[labels.Label][]storage.SeriesRef
|
|
symbols map[string]struct{}
|
|
}
|
|
|
|
func newMockIndex() mockIndex {
|
|
ix := mockIndex{
|
|
series: make(map[storage.SeriesRef]series),
|
|
postings: make(map[labels.Label][]storage.SeriesRef),
|
|
symbols: make(map[string]struct{}),
|
|
}
|
|
return ix
|
|
}
|
|
|
|
func (m mockIndex) Symbols() index.StringIter {
|
|
l := []string{}
|
|
for s := range m.symbols {
|
|
l = append(l, s)
|
|
}
|
|
sort.Strings(l)
|
|
return index.NewStringListIter(l)
|
|
}
|
|
|
|
func (m *mockIndex) AddSeries(ref storage.SeriesRef, l labels.Labels, chunks ...chunks.Meta) error {
|
|
if _, ok := m.series[ref]; ok {
|
|
return fmt.Errorf("series with reference %d already added", ref)
|
|
}
|
|
l.Range(func(lbl labels.Label) {
|
|
m.symbols[lbl.Name] = struct{}{}
|
|
m.symbols[lbl.Value] = struct{}{}
|
|
})
|
|
|
|
s := series{l: l}
|
|
// Actual chunk data is not stored in the index.
|
|
for _, c := range chunks {
|
|
c.Chunk = nil
|
|
s.chunks = append(s.chunks, c)
|
|
}
|
|
m.series[ref] = s
|
|
|
|
return nil
|
|
}
|
|
|
|
func (m mockIndex) WritePostings(name, value string, it index.Postings) error {
|
|
l := labels.Label{Name: name, Value: value}
|
|
if _, ok := m.postings[l]; ok {
|
|
return fmt.Errorf("postings for %s already added", l)
|
|
}
|
|
ep, err := index.ExpandPostings(it)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
m.postings[l] = ep
|
|
return nil
|
|
}
|
|
|
|
func (m mockIndex) Close() error {
|
|
return nil
|
|
}
|
|
|
|
func (m mockIndex) SortedLabelValues(ctx context.Context, name string, matchers ...*labels.Matcher) ([]string, error) {
|
|
values, _ := m.LabelValues(ctx, name, matchers...)
|
|
sort.Strings(values)
|
|
return values, nil
|
|
}
|
|
|
|
func (m mockIndex) LabelValues(_ context.Context, name string, matchers ...*labels.Matcher) ([]string, error) {
|
|
var values []string
|
|
|
|
if len(matchers) == 0 {
|
|
for l := range m.postings {
|
|
if l.Name == name {
|
|
values = append(values, l.Value)
|
|
}
|
|
}
|
|
return values, nil
|
|
}
|
|
|
|
for _, series := range m.series {
|
|
for _, matcher := range matchers {
|
|
if matcher.Matches(series.l.Get(matcher.Name)) {
|
|
// TODO(colega): shouldn't we check all the matchers before adding this to the values?
|
|
values = append(values, series.l.Get(name))
|
|
}
|
|
}
|
|
}
|
|
|
|
return values, nil
|
|
}
|
|
|
|
func (m mockIndex) LabelValueFor(_ context.Context, id storage.SeriesRef, label string) (string, error) {
|
|
return m.series[id].l.Get(label), nil
|
|
}
|
|
|
|
func (m mockIndex) LabelNamesFor(ctx context.Context, ids ...storage.SeriesRef) ([]string, error) {
|
|
namesMap := make(map[string]bool)
|
|
for _, id := range ids {
|
|
m.series[id].l.Range(func(lbl labels.Label) {
|
|
namesMap[lbl.Name] = true
|
|
})
|
|
}
|
|
names := make([]string, 0, len(namesMap))
|
|
for name := range namesMap {
|
|
names = append(names, name)
|
|
}
|
|
return names, nil
|
|
}
|
|
|
|
func (m mockIndex) Postings(ctx context.Context, name string, values ...string) (index.Postings, error) {
|
|
res := make([]index.Postings, 0, len(values))
|
|
for _, value := range values {
|
|
l := labels.Label{Name: name, Value: value}
|
|
res = append(res, index.NewListPostings(m.postings[l]))
|
|
}
|
|
return index.Merge(ctx, res...), nil
|
|
}
|
|
|
|
func (m mockIndex) SortedPostings(p index.Postings) index.Postings {
|
|
ep, err := index.ExpandPostings(p)
|
|
if err != nil {
|
|
return index.ErrPostings(fmt.Errorf("expand postings: %w", err))
|
|
}
|
|
|
|
sort.Slice(ep, func(i, j int) bool {
|
|
return labels.Compare(m.series[ep[i]].l, m.series[ep[j]].l) < 0
|
|
})
|
|
return index.NewListPostings(ep)
|
|
}
|
|
|
|
func (m mockIndex) ShardedPostings(p index.Postings, shardIndex, shardCount uint64) index.Postings {
|
|
out := make([]storage.SeriesRef, 0, 128)
|
|
|
|
for p.Next() {
|
|
ref := p.At()
|
|
s, ok := m.series[ref]
|
|
if !ok {
|
|
continue
|
|
}
|
|
|
|
// Check if the series belong to the shard.
|
|
if s.l.Hash()%shardCount != shardIndex {
|
|
continue
|
|
}
|
|
|
|
out = append(out, ref)
|
|
}
|
|
|
|
return index.NewListPostings(out)
|
|
}
|
|
|
|
func (m mockIndex) Series(ref storage.SeriesRef, builder *labels.ScratchBuilder, chks *[]chunks.Meta) error {
|
|
s, ok := m.series[ref]
|
|
if !ok {
|
|
return storage.ErrNotFound
|
|
}
|
|
builder.Assign(s.l)
|
|
*chks = append((*chks)[:0], s.chunks...)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (m mockIndex) LabelNames(_ context.Context, matchers ...*labels.Matcher) ([]string, error) {
|
|
names := map[string]struct{}{}
|
|
if len(matchers) == 0 {
|
|
for l := range m.postings {
|
|
names[l.Name] = struct{}{}
|
|
}
|
|
} else {
|
|
for _, series := range m.series {
|
|
matches := true
|
|
for _, matcher := range matchers {
|
|
matches = matches || matcher.Matches(series.l.Get(matcher.Name))
|
|
if !matches {
|
|
break
|
|
}
|
|
}
|
|
if matches {
|
|
series.l.Range(func(lbl labels.Label) {
|
|
names[lbl.Name] = struct{}{}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
l := make([]string, 0, len(names))
|
|
for name := range names {
|
|
l = append(l, name)
|
|
}
|
|
sort.Strings(l)
|
|
return l, nil
|
|
}
|
|
|
|
func BenchmarkQueryIterator(b *testing.B) {
|
|
cases := []struct {
|
|
numBlocks int
|
|
numSeries int
|
|
numSamplesPerSeriesPerBlock int
|
|
overlapPercentages []int // >=0, <=100, this is w.r.t. the previous block.
|
|
}{
|
|
{
|
|
numBlocks: 20,
|
|
numSeries: 1000,
|
|
numSamplesPerSeriesPerBlock: 20000,
|
|
overlapPercentages: []int{0, 10, 30},
|
|
},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
for _, overlapPercentage := range c.overlapPercentages {
|
|
benchMsg := fmt.Sprintf("nBlocks=%d,nSeries=%d,numSamplesPerSeriesPerBlock=%d,overlap=%d%%",
|
|
c.numBlocks, c.numSeries, c.numSamplesPerSeriesPerBlock, overlapPercentage)
|
|
|
|
b.Run(benchMsg, func(b *testing.B) {
|
|
dir := b.TempDir()
|
|
|
|
var (
|
|
blocks []*Block
|
|
overlapDelta = int64(overlapPercentage * c.numSamplesPerSeriesPerBlock / 100)
|
|
prefilledLabels []map[string]string
|
|
generatedSeries []storage.Series
|
|
)
|
|
for i := int64(0); i < int64(c.numBlocks); i++ {
|
|
offset := i * overlapDelta
|
|
mint := i*int64(c.numSamplesPerSeriesPerBlock) - offset
|
|
maxt := mint + int64(c.numSamplesPerSeriesPerBlock) - 1
|
|
if len(prefilledLabels) == 0 {
|
|
generatedSeries = genSeries(c.numSeries, 10, mint, maxt)
|
|
for _, s := range generatedSeries {
|
|
prefilledLabels = append(prefilledLabels, s.Labels().Map())
|
|
}
|
|
} else {
|
|
generatedSeries = populateSeries(prefilledLabels, mint, maxt)
|
|
}
|
|
block, err := OpenBlock(nil, createBlock(b, dir, generatedSeries), nil)
|
|
require.NoError(b, err)
|
|
blocks = append(blocks, block)
|
|
defer block.Close()
|
|
}
|
|
|
|
qblocks := make([]storage.Querier, 0, len(blocks))
|
|
for _, blk := range blocks {
|
|
q, err := NewBlockQuerier(blk, math.MinInt64, math.MaxInt64)
|
|
require.NoError(b, err)
|
|
qblocks = append(qblocks, q)
|
|
}
|
|
|
|
sq := storage.NewMergeQuerier(qblocks, nil, storage.ChainedSeriesMerge)
|
|
defer sq.Close()
|
|
|
|
benchQuery(b, c.numSeries, sq, labels.Selector{labels.MustNewMatcher(labels.MatchRegexp, "__name__", ".*")})
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
func BenchmarkQuerySeek(b *testing.B) {
|
|
cases := []struct {
|
|
numBlocks int
|
|
numSeries int
|
|
numSamplesPerSeriesPerBlock int
|
|
overlapPercentages []int // >=0, <=100, this is w.r.t. the previous block.
|
|
}{
|
|
{
|
|
numBlocks: 20,
|
|
numSeries: 100,
|
|
numSamplesPerSeriesPerBlock: 2000,
|
|
overlapPercentages: []int{0, 10, 30, 50},
|
|
},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
for _, overlapPercentage := range c.overlapPercentages {
|
|
benchMsg := fmt.Sprintf("nBlocks=%d,nSeries=%d,numSamplesPerSeriesPerBlock=%d,overlap=%d%%",
|
|
c.numBlocks, c.numSeries, c.numSamplesPerSeriesPerBlock, overlapPercentage)
|
|
|
|
b.Run(benchMsg, func(b *testing.B) {
|
|
dir := b.TempDir()
|
|
|
|
var (
|
|
blocks []*Block
|
|
overlapDelta = int64(overlapPercentage * c.numSamplesPerSeriesPerBlock / 100)
|
|
prefilledLabels []map[string]string
|
|
generatedSeries []storage.Series
|
|
)
|
|
for i := int64(0); i < int64(c.numBlocks); i++ {
|
|
offset := i * overlapDelta
|
|
mint := i*int64(c.numSamplesPerSeriesPerBlock) - offset
|
|
maxt := mint + int64(c.numSamplesPerSeriesPerBlock) - 1
|
|
if len(prefilledLabels) == 0 {
|
|
generatedSeries = genSeries(c.numSeries, 10, mint, maxt)
|
|
for _, s := range generatedSeries {
|
|
prefilledLabels = append(prefilledLabels, s.Labels().Map())
|
|
}
|
|
} else {
|
|
generatedSeries = populateSeries(prefilledLabels, mint, maxt)
|
|
}
|
|
block, err := OpenBlock(nil, createBlock(b, dir, generatedSeries), nil)
|
|
require.NoError(b, err)
|
|
blocks = append(blocks, block)
|
|
defer block.Close()
|
|
}
|
|
|
|
qblocks := make([]storage.Querier, 0, len(blocks))
|
|
for _, blk := range blocks {
|
|
q, err := NewBlockQuerier(blk, math.MinInt64, math.MaxInt64)
|
|
require.NoError(b, err)
|
|
qblocks = append(qblocks, q)
|
|
}
|
|
|
|
sq := storage.NewMergeQuerier(qblocks, nil, storage.ChainedSeriesMerge)
|
|
defer sq.Close()
|
|
|
|
mint := blocks[0].meta.MinTime
|
|
maxt := blocks[len(blocks)-1].meta.MaxTime
|
|
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
|
|
var it chunkenc.Iterator
|
|
ss := sq.Select(context.Background(), false, nil, labels.MustNewMatcher(labels.MatchRegexp, "__name__", ".*"))
|
|
for ss.Next() {
|
|
it = ss.At().Iterator(it)
|
|
for t := mint; t <= maxt; t++ {
|
|
it.Seek(t)
|
|
}
|
|
require.NoError(b, it.Err())
|
|
}
|
|
require.NoError(b, ss.Err())
|
|
require.Empty(b, ss.Warnings())
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
// Refer to https://github.com/prometheus/prometheus/issues/2651.
|
|
func BenchmarkSetMatcher(b *testing.B) {
|
|
cases := []struct {
|
|
numBlocks int
|
|
numSeries int
|
|
numSamplesPerSeriesPerBlock int
|
|
cardinality int
|
|
pattern string
|
|
}{
|
|
// The first three cases are to find out whether the set
|
|
// matcher is always faster than regex matcher.
|
|
{
|
|
numBlocks: 1,
|
|
numSeries: 1,
|
|
numSamplesPerSeriesPerBlock: 10,
|
|
cardinality: 100,
|
|
pattern: "1|2|3|4|5|6|7|8|9|10",
|
|
},
|
|
{
|
|
numBlocks: 1,
|
|
numSeries: 15,
|
|
numSamplesPerSeriesPerBlock: 10,
|
|
cardinality: 100,
|
|
pattern: "1|2|3|4|5|6|7|8|9|10",
|
|
},
|
|
{
|
|
numBlocks: 1,
|
|
numSeries: 15,
|
|
numSamplesPerSeriesPerBlock: 10,
|
|
cardinality: 100,
|
|
pattern: "1|2|3",
|
|
},
|
|
// Big data sizes benchmarks.
|
|
{
|
|
numBlocks: 20,
|
|
numSeries: 1000,
|
|
numSamplesPerSeriesPerBlock: 10,
|
|
cardinality: 100,
|
|
pattern: "1|2|3",
|
|
},
|
|
{
|
|
numBlocks: 20,
|
|
numSeries: 1000,
|
|
numSamplesPerSeriesPerBlock: 10,
|
|
cardinality: 100,
|
|
pattern: "1|2|3|4|5|6|7|8|9|10",
|
|
},
|
|
// Increase cardinality.
|
|
{
|
|
numBlocks: 1,
|
|
numSeries: 100000,
|
|
numSamplesPerSeriesPerBlock: 10,
|
|
cardinality: 100000,
|
|
pattern: "1|2|3|4|5|6|7|8|9|10",
|
|
},
|
|
{
|
|
numBlocks: 1,
|
|
numSeries: 500000,
|
|
numSamplesPerSeriesPerBlock: 10,
|
|
cardinality: 500000,
|
|
pattern: "1|2|3|4|5|6|7|8|9|10",
|
|
},
|
|
{
|
|
numBlocks: 10,
|
|
numSeries: 500000,
|
|
numSamplesPerSeriesPerBlock: 10,
|
|
cardinality: 500000,
|
|
pattern: "1|2|3|4|5|6|7|8|9|10",
|
|
},
|
|
{
|
|
numBlocks: 1,
|
|
numSeries: 1000000,
|
|
numSamplesPerSeriesPerBlock: 10,
|
|
cardinality: 1000000,
|
|
pattern: "1|2|3|4|5|6|7|8|9|10",
|
|
},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
dir := b.TempDir()
|
|
|
|
var (
|
|
blocks []*Block
|
|
prefilledLabels []map[string]string
|
|
generatedSeries []storage.Series
|
|
)
|
|
for i := int64(0); i < int64(c.numBlocks); i++ {
|
|
mint := i * int64(c.numSamplesPerSeriesPerBlock)
|
|
maxt := mint + int64(c.numSamplesPerSeriesPerBlock) - 1
|
|
if len(prefilledLabels) == 0 {
|
|
generatedSeries = genSeries(c.numSeries, 10, mint, maxt)
|
|
for _, s := range generatedSeries {
|
|
prefilledLabels = append(prefilledLabels, s.Labels().Map())
|
|
}
|
|
} else {
|
|
generatedSeries = populateSeries(prefilledLabels, mint, maxt)
|
|
}
|
|
block, err := OpenBlock(nil, createBlock(b, dir, generatedSeries), nil)
|
|
require.NoError(b, err)
|
|
blocks = append(blocks, block)
|
|
defer block.Close()
|
|
}
|
|
|
|
qblocks := make([]storage.Querier, 0, len(blocks))
|
|
for _, blk := range blocks {
|
|
q, err := NewBlockQuerier(blk, math.MinInt64, math.MaxInt64)
|
|
require.NoError(b, err)
|
|
qblocks = append(qblocks, q)
|
|
}
|
|
|
|
sq := storage.NewMergeQuerier(qblocks, nil, storage.ChainedSeriesMerge)
|
|
defer sq.Close()
|
|
|
|
benchMsg := fmt.Sprintf("nSeries=%d,nBlocks=%d,cardinality=%d,pattern=\"%s\"", c.numSeries, c.numBlocks, c.cardinality, c.pattern)
|
|
b.Run(benchMsg, func(b *testing.B) {
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
for n := 0; n < b.N; n++ {
|
|
ss := sq.Select(context.Background(), false, nil, labels.MustNewMatcher(labels.MatchRegexp, "test", c.pattern))
|
|
for ss.Next() {
|
|
}
|
|
require.NoError(b, ss.Err())
|
|
require.Empty(b, ss.Warnings())
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// Refer to https://github.com/prometheus/prometheus/issues/2651.
|
|
func TestFindSetMatches(t *testing.T) {
|
|
cases := []struct {
|
|
pattern string
|
|
exp []string
|
|
}{
|
|
// Single value, coming from a `bar=~"foo"` selector.
|
|
{
|
|
pattern: "^(?:foo)$",
|
|
exp: []string{
|
|
"foo",
|
|
},
|
|
},
|
|
// Simple sets.
|
|
{
|
|
pattern: "^(?:foo|bar|baz)$",
|
|
exp: []string{
|
|
"foo",
|
|
"bar",
|
|
"baz",
|
|
},
|
|
},
|
|
// Simple sets containing escaped characters.
|
|
{
|
|
pattern: "^(?:fo\\.o|bar\\?|\\^baz)$",
|
|
exp: []string{
|
|
"fo.o",
|
|
"bar?",
|
|
"^baz",
|
|
},
|
|
},
|
|
// Simple sets containing special characters without escaping.
|
|
{
|
|
pattern: "^(?:fo.o|bar?|^baz)$",
|
|
exp: nil,
|
|
},
|
|
// Missing wrapper.
|
|
{
|
|
pattern: "foo|bar|baz",
|
|
exp: nil,
|
|
},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
require.Equal(t, c.exp, findSetMatches(c.pattern), "Evaluating %s, unexpected result.", c.pattern)
|
|
}
|
|
}
|
|
|
|
func TestPostingsForMatchers(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
chunkDir := t.TempDir()
|
|
opts := DefaultHeadOptions()
|
|
opts.ChunkRange = 1000
|
|
opts.ChunkDirRoot = chunkDir
|
|
h, err := NewHead(nil, nil, nil, nil, opts, nil)
|
|
require.NoError(t, err)
|
|
defer func() {
|
|
require.NoError(t, h.Close())
|
|
}()
|
|
|
|
app := h.Appender(context.Background())
|
|
app.Append(0, labels.FromStrings("n", "1"), 0, 0)
|
|
app.Append(0, labels.FromStrings("n", "1", "i", "a"), 0, 0)
|
|
app.Append(0, labels.FromStrings("n", "1", "i", "b"), 0, 0)
|
|
app.Append(0, labels.FromStrings("n", "2"), 0, 0)
|
|
app.Append(0, labels.FromStrings("n", "2.5"), 0, 0)
|
|
require.NoError(t, app.Commit())
|
|
|
|
cases := []struct {
|
|
matchers []*labels.Matcher
|
|
exp []labels.Labels
|
|
}{
|
|
// Simple equals.
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "n", "1")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1"),
|
|
labels.FromStrings("n", "1", "i", "a"),
|
|
labels.FromStrings("n", "1", "i", "b"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "n", "1"), labels.MustNewMatcher(labels.MatchEqual, "i", "a")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1", "i", "a"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "n", "1"), labels.MustNewMatcher(labels.MatchEqual, "i", "missing")},
|
|
exp: []labels.Labels{},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "missing", "")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1"),
|
|
labels.FromStrings("n", "1", "i", "a"),
|
|
labels.FromStrings("n", "1", "i", "b"),
|
|
labels.FromStrings("n", "2"),
|
|
labels.FromStrings("n", "2.5"),
|
|
},
|
|
},
|
|
// Not equals.
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchNotEqual, "n", "1")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "2"),
|
|
labels.FromStrings("n", "2.5"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchNotEqual, "i", "")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1", "i", "a"),
|
|
labels.FromStrings("n", "1", "i", "b"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchNotEqual, "missing", "")},
|
|
exp: []labels.Labels{},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "n", "1"), labels.MustNewMatcher(labels.MatchNotEqual, "i", "a")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1"),
|
|
labels.FromStrings("n", "1", "i", "b"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "n", "1"), labels.MustNewMatcher(labels.MatchNotEqual, "i", "")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1", "i", "a"),
|
|
labels.FromStrings("n", "1", "i", "b"),
|
|
},
|
|
},
|
|
// Regex.
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "n", "^1$")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1"),
|
|
labels.FromStrings("n", "1", "i", "a"),
|
|
labels.FromStrings("n", "1", "i", "b"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "n", "1"), labels.MustNewMatcher(labels.MatchRegexp, "i", "^a$")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1", "i", "a"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "n", "1"), labels.MustNewMatcher(labels.MatchRegexp, "i", "^a?$")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1"),
|
|
labels.FromStrings("n", "1", "i", "a"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "i", "^$")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1"),
|
|
labels.FromStrings("n", "2"),
|
|
labels.FromStrings("n", "2.5"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "n", "1"), labels.MustNewMatcher(labels.MatchRegexp, "i", "^$")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "n", "1"), labels.MustNewMatcher(labels.MatchRegexp, "i", "^.*$")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1"),
|
|
labels.FromStrings("n", "1", "i", "a"),
|
|
labels.FromStrings("n", "1", "i", "b"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "n", "1"), labels.MustNewMatcher(labels.MatchRegexp, "i", "^.+$")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1", "i", "a"),
|
|
labels.FromStrings("n", "1", "i", "b"),
|
|
},
|
|
},
|
|
// Not regex.
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchNotRegexp, "n", "^1$")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "2"),
|
|
labels.FromStrings("n", "2.5"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchNotRegexp, "n", "1")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "2"),
|
|
labels.FromStrings("n", "2.5"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchNotRegexp, "n", "1|2.5")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "2"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchNotRegexp, "n", "(1|2.5)")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "2"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "n", "1"), labels.MustNewMatcher(labels.MatchNotRegexp, "i", "^a$")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1"),
|
|
labels.FromStrings("n", "1", "i", "b"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "n", "1"), labels.MustNewMatcher(labels.MatchNotRegexp, "i", "^a?$")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1", "i", "b"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "n", "1"), labels.MustNewMatcher(labels.MatchNotRegexp, "i", "^$")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1", "i", "a"),
|
|
labels.FromStrings("n", "1", "i", "b"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "n", "1"), labels.MustNewMatcher(labels.MatchNotRegexp, "i", "^.*$")},
|
|
exp: []labels.Labels{},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "n", "1"), labels.MustNewMatcher(labels.MatchNotRegexp, "i", "^.+$")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1"),
|
|
},
|
|
},
|
|
// Combinations.
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "n", "1"), labels.MustNewMatcher(labels.MatchNotEqual, "i", ""), labels.MustNewMatcher(labels.MatchEqual, "i", "a")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1", "i", "a"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "n", "1"), labels.MustNewMatcher(labels.MatchNotEqual, "i", "b"), labels.MustNewMatcher(labels.MatchRegexp, "i", "^(b|a).*$")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1", "i", "a"),
|
|
},
|
|
},
|
|
// Set optimization for Regex.
|
|
// Refer to https://github.com/prometheus/prometheus/issues/2651.
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "n", "1|2")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1"),
|
|
labels.FromStrings("n", "1", "i", "a"),
|
|
labels.FromStrings("n", "1", "i", "b"),
|
|
labels.FromStrings("n", "2"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "i", "a|b")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1", "i", "a"),
|
|
labels.FromStrings("n", "1", "i", "b"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "i", "(a|b)")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1", "i", "a"),
|
|
labels.FromStrings("n", "1", "i", "b"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "n", "x1|2")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "2"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "n", "2|2\\.5")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "2"),
|
|
labels.FromStrings("n", "2.5"),
|
|
},
|
|
},
|
|
// Empty value.
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "i", "c||d")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1"),
|
|
labels.FromStrings("n", "2"),
|
|
labels.FromStrings("n", "2.5"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "i", "(c||d)")},
|
|
exp: []labels.Labels{
|
|
labels.FromStrings("n", "1"),
|
|
labels.FromStrings("n", "2"),
|
|
labels.FromStrings("n", "2.5"),
|
|
},
|
|
},
|
|
}
|
|
|
|
ir, err := h.Index()
|
|
require.NoError(t, err)
|
|
|
|
for _, c := range cases {
|
|
name := ""
|
|
for i, matcher := range c.matchers {
|
|
if i > 0 {
|
|
name += ","
|
|
}
|
|
name += matcher.String()
|
|
}
|
|
t.Run(name, func(t *testing.T) {
|
|
exp := map[string]struct{}{}
|
|
for _, l := range c.exp {
|
|
exp[l.String()] = struct{}{}
|
|
}
|
|
p, err := PostingsForMatchers(ctx, ir, c.matchers...)
|
|
require.NoError(t, err)
|
|
|
|
var builder labels.ScratchBuilder
|
|
for p.Next() {
|
|
require.NoError(t, ir.Series(p.At(), &builder, &[]chunks.Meta{}))
|
|
lbls := builder.Labels()
|
|
if _, ok := exp[lbls.String()]; !ok {
|
|
t.Errorf("Evaluating %v, unexpected result %s", c.matchers, lbls.String())
|
|
} else {
|
|
delete(exp, lbls.String())
|
|
}
|
|
}
|
|
require.NoError(t, p.Err())
|
|
require.Empty(t, exp, "Evaluating %v", c.matchers)
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestQuerierIndexQueriesRace tests the index queries with racing appends.
|
|
func TestQuerierIndexQueriesRace(t *testing.T) {
|
|
const testRepeats = 1000
|
|
|
|
testCases := []struct {
|
|
matchers []*labels.Matcher
|
|
}{
|
|
{
|
|
matchers: []*labels.Matcher{
|
|
// This matcher should involve the AllPostings posting list in calculating the posting lists.
|
|
labels.MustNewMatcher(labels.MatchNotEqual, labels.MetricName, "metric"),
|
|
},
|
|
},
|
|
{
|
|
matchers: []*labels.Matcher{
|
|
// The first matcher should be effectively the same as AllPostings, because all series have always_0=0
|
|
// If it is evaluated first, then __name__=metric will contain more series than always_0=0.
|
|
labels.MustNewMatcher(labels.MatchNotEqual, "always_0", "0"),
|
|
labels.MustNewMatcher(labels.MatchEqual, labels.MetricName, "metric"),
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, c := range testCases {
|
|
c := c
|
|
t.Run(fmt.Sprintf("%v", c.matchers), func(t *testing.T) {
|
|
t.Parallel()
|
|
db := openTestDB(t, DefaultOptions(), nil)
|
|
h := db.Head()
|
|
t.Cleanup(func() {
|
|
require.NoError(t, db.Close())
|
|
})
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
wg := &sync.WaitGroup{}
|
|
wg.Add(1)
|
|
go appendSeries(t, ctx, wg, h)
|
|
t.Cleanup(wg.Wait)
|
|
t.Cleanup(cancel)
|
|
|
|
for i := 0; i < testRepeats; i++ {
|
|
q, err := db.Querier(math.MinInt64, math.MaxInt64)
|
|
require.NoError(t, err)
|
|
|
|
values, _, err := q.LabelValues(ctx, "seq", c.matchers...)
|
|
require.NoError(t, err)
|
|
require.Emptyf(t, values, `label values for label "seq" should be empty`)
|
|
|
|
// Sleep to give the appends some change to run.
|
|
time.Sleep(time.Millisecond)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func appendSeries(t *testing.T, ctx context.Context, wg *sync.WaitGroup, h *Head) {
|
|
defer wg.Done()
|
|
|
|
for i := 0; ctx.Err() == nil; i++ {
|
|
app := h.Appender(context.Background())
|
|
_, err := app.Append(0, labels.FromStrings(labels.MetricName, "metric", "seq", strconv.Itoa(i), "always_0", "0"), 0, 0)
|
|
require.NoError(t, err)
|
|
err = app.Commit()
|
|
require.NoError(t, err)
|
|
|
|
// Throttle down the appends to keep the test somewhat nimble.
|
|
// Otherwise, we end up appending thousands or millions of samples.
|
|
time.Sleep(time.Millisecond)
|
|
}
|
|
}
|
|
|
|
// TestClose ensures that calling Close more than once doesn't block and doesn't panic.
|
|
func TestClose(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
createBlock(t, dir, genSeries(1, 1, 0, 10))
|
|
createBlock(t, dir, genSeries(1, 1, 10, 20))
|
|
|
|
db, err := Open(dir, nil, nil, DefaultOptions(), nil)
|
|
require.NoError(t, err, "Opening test storage failed: %s")
|
|
defer func() {
|
|
require.NoError(t, db.Close())
|
|
}()
|
|
|
|
q, err := db.Querier(0, 20)
|
|
require.NoError(t, err)
|
|
require.NoError(t, q.Close())
|
|
require.Error(t, q.Close())
|
|
}
|
|
|
|
func BenchmarkQueries(b *testing.B) {
|
|
cases := map[string]labels.Selector{
|
|
"Eq Matcher: Expansion - 1": {
|
|
labels.MustNewMatcher(labels.MatchEqual, "la", "va"),
|
|
},
|
|
"Eq Matcher: Expansion - 2": {
|
|
labels.MustNewMatcher(labels.MatchEqual, "la", "va"),
|
|
labels.MustNewMatcher(labels.MatchEqual, "lb", "vb"),
|
|
},
|
|
|
|
"Eq Matcher: Expansion - 3": {
|
|
labels.MustNewMatcher(labels.MatchEqual, "la", "va"),
|
|
labels.MustNewMatcher(labels.MatchEqual, "lb", "vb"),
|
|
labels.MustNewMatcher(labels.MatchEqual, "lc", "vc"),
|
|
},
|
|
"Regex Matcher: Expansion - 1": {
|
|
labels.MustNewMatcher(labels.MatchRegexp, "la", ".*va"),
|
|
},
|
|
"Regex Matcher: Expansion - 2": {
|
|
labels.MustNewMatcher(labels.MatchRegexp, "la", ".*va"),
|
|
labels.MustNewMatcher(labels.MatchRegexp, "lb", ".*vb"),
|
|
},
|
|
"Regex Matcher: Expansion - 3": {
|
|
labels.MustNewMatcher(labels.MatchRegexp, "la", ".*va"),
|
|
labels.MustNewMatcher(labels.MatchRegexp, "lb", ".*vb"),
|
|
labels.MustNewMatcher(labels.MatchRegexp, "lc", ".*vc"),
|
|
},
|
|
}
|
|
|
|
type qt struct {
|
|
typ string
|
|
querier storage.Querier
|
|
}
|
|
var queryTypes []qt // We use a slice instead of map to keep the order of test cases consistent.
|
|
defer func() {
|
|
for _, q := range queryTypes {
|
|
// Can't run a check for error here as some of these will fail as
|
|
// queryTypes is using the same slice for the different block queriers
|
|
// and would have been closed in the previous iteration.
|
|
q.querier.Close()
|
|
}
|
|
}()
|
|
|
|
for title, selectors := range cases {
|
|
for _, nSeries := range []int{10} {
|
|
for _, nSamples := range []int64{1000, 10000, 100000} {
|
|
dir := b.TempDir()
|
|
|
|
series := genSeries(nSeries, 5, 1, nSamples)
|
|
|
|
// Add some common labels to make the matchers select these series.
|
|
{
|
|
var commonLbls []labels.Label
|
|
for _, selector := range selectors {
|
|
switch selector.Type {
|
|
case labels.MatchEqual:
|
|
commonLbls = append(commonLbls, labels.Label{Name: selector.Name, Value: selector.Value})
|
|
case labels.MatchRegexp:
|
|
commonLbls = append(commonLbls, labels.Label{Name: selector.Name, Value: selector.Value})
|
|
}
|
|
}
|
|
for i := range commonLbls {
|
|
s := series[i].(*storage.SeriesEntry)
|
|
allLabels := commonLbls
|
|
s.Labels().Range(func(l labels.Label) {
|
|
allLabels = append(allLabels, l)
|
|
})
|
|
newS := storage.NewListSeries(labels.New(allLabels...), nil)
|
|
newS.SampleIteratorFn = s.SampleIteratorFn
|
|
|
|
series[i] = newS
|
|
}
|
|
}
|
|
|
|
qs := make([]storage.Querier, 0, 10)
|
|
for x := 0; x <= 10; x++ {
|
|
block, err := OpenBlock(nil, createBlock(b, dir, series), nil)
|
|
require.NoError(b, err)
|
|
q, err := NewBlockQuerier(block, 1, nSamples)
|
|
require.NoError(b, err)
|
|
qs = append(qs, q)
|
|
}
|
|
|
|
queryTypes = append(queryTypes, qt{"_1-Block", storage.NewMergeQuerier(qs[:1], nil, storage.ChainedSeriesMerge)})
|
|
queryTypes = append(queryTypes, qt{"_3-Blocks", storage.NewMergeQuerier(qs[0:3], nil, storage.ChainedSeriesMerge)})
|
|
queryTypes = append(queryTypes, qt{"_10-Blocks", storage.NewMergeQuerier(qs, nil, storage.ChainedSeriesMerge)})
|
|
|
|
chunkDir := b.TempDir()
|
|
head := createHead(b, nil, series, chunkDir)
|
|
qHead, err := NewBlockQuerier(NewRangeHead(head, 1, nSamples), 1, nSamples)
|
|
require.NoError(b, err)
|
|
queryTypes = append(queryTypes, qt{"_Head", qHead})
|
|
|
|
for _, oooPercentage := range []int{1, 3, 5, 10} {
|
|
chunkDir := b.TempDir()
|
|
totalOOOSamples := oooPercentage * int(nSamples) / 100
|
|
oooSampleFrequency := int(nSamples) / totalOOOSamples
|
|
head := createHeadWithOOOSamples(b, nil, series, chunkDir, oooSampleFrequency)
|
|
|
|
qHead, err := NewBlockQuerier(NewRangeHead(head, 1, nSamples), 1, nSamples)
|
|
require.NoError(b, err)
|
|
qOOOHead, err := NewBlockQuerier(NewOOORangeHead(head, 1, nSamples, 0), 1, nSamples)
|
|
require.NoError(b, err)
|
|
|
|
queryTypes = append(queryTypes, qt{
|
|
fmt.Sprintf("_Head_oooPercent:%d", oooPercentage),
|
|
storage.NewMergeQuerier([]storage.Querier{qHead, qOOOHead}, nil, storage.ChainedSeriesMerge),
|
|
})
|
|
}
|
|
|
|
for _, q := range queryTypes {
|
|
b.Run(title+q.typ+"_nSeries:"+strconv.Itoa(nSeries)+"_nSamples:"+strconv.Itoa(int(nSamples)), func(b *testing.B) {
|
|
expExpansions, err := strconv.Atoi(string(title[len(title)-1]))
|
|
require.NoError(b, err)
|
|
benchQuery(b, expExpansions, q.querier, selectors)
|
|
})
|
|
}
|
|
require.NoError(b, head.Close())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func benchQuery(b *testing.B, expExpansions int, q storage.Querier, selectors labels.Selector) {
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
for i := 0; i < b.N; i++ {
|
|
ss := q.Select(context.Background(), false, nil, selectors...)
|
|
var actualExpansions int
|
|
var it chunkenc.Iterator
|
|
for ss.Next() {
|
|
s := ss.At()
|
|
s.Labels()
|
|
it = s.Iterator(it)
|
|
for it.Next() != chunkenc.ValNone {
|
|
_, _ = it.At()
|
|
}
|
|
actualExpansions++
|
|
}
|
|
require.NoError(b, ss.Err())
|
|
require.Empty(b, ss.Warnings())
|
|
require.Equal(b, expExpansions, actualExpansions)
|
|
require.NoError(b, ss.Err())
|
|
}
|
|
}
|
|
|
|
// mockMatcherIndex is used to check if the regex matcher works as expected.
|
|
type mockMatcherIndex struct{}
|
|
|
|
func (m mockMatcherIndex) Symbols() index.StringIter { return nil }
|
|
|
|
func (m mockMatcherIndex) Close() error { return nil }
|
|
|
|
// SortedLabelValues will return error if it is called.
|
|
func (m mockMatcherIndex) SortedLabelValues(context.Context, string, ...*labels.Matcher) ([]string, error) {
|
|
return []string{}, errors.New("sorted label values called")
|
|
}
|
|
|
|
// LabelValues will return error if it is called.
|
|
func (m mockMatcherIndex) LabelValues(context.Context, string, ...*labels.Matcher) ([]string, error) {
|
|
return []string{}, errors.New("label values called")
|
|
}
|
|
|
|
func (m mockMatcherIndex) LabelValueFor(context.Context, storage.SeriesRef, string) (string, error) {
|
|
return "", errors.New("label value for called")
|
|
}
|
|
|
|
func (m mockMatcherIndex) LabelNamesFor(ctx context.Context, ids ...storage.SeriesRef) ([]string, error) {
|
|
return nil, errors.New("label names for for called")
|
|
}
|
|
|
|
func (m mockMatcherIndex) Postings(context.Context, string, ...string) (index.Postings, error) {
|
|
return index.EmptyPostings(), nil
|
|
}
|
|
|
|
func (m mockMatcherIndex) SortedPostings(p index.Postings) index.Postings {
|
|
return index.EmptyPostings()
|
|
}
|
|
|
|
func (m mockMatcherIndex) ShardedPostings(ps index.Postings, shardIndex, shardCount uint64) index.Postings {
|
|
return ps
|
|
}
|
|
|
|
func (m mockMatcherIndex) Series(ref storage.SeriesRef, builder *labels.ScratchBuilder, chks *[]chunks.Meta) error {
|
|
return nil
|
|
}
|
|
|
|
func (m mockMatcherIndex) LabelNames(context.Context, ...*labels.Matcher) ([]string, error) {
|
|
return []string{}, nil
|
|
}
|
|
|
|
func TestPostingsForMatcher(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
cases := []struct {
|
|
matcher *labels.Matcher
|
|
hasError bool
|
|
}{
|
|
{
|
|
// Equal label matcher will just return.
|
|
matcher: labels.MustNewMatcher(labels.MatchEqual, "test", "test"),
|
|
hasError: false,
|
|
},
|
|
{
|
|
// Regex matcher which doesn't have '|' will call Labelvalues()
|
|
matcher: labels.MustNewMatcher(labels.MatchRegexp, "test", ".*"),
|
|
hasError: true,
|
|
},
|
|
{
|
|
matcher: labels.MustNewMatcher(labels.MatchRegexp, "test", "a|b"),
|
|
hasError: false,
|
|
},
|
|
{
|
|
// Test case for double quoted regex matcher
|
|
matcher: labels.MustNewMatcher(labels.MatchRegexp, "test", "^(?:a|b)$"),
|
|
hasError: true,
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.matcher.String(), func(t *testing.T) {
|
|
ir := &mockMatcherIndex{}
|
|
_, err := postingsForMatcher(ctx, ir, tc.matcher)
|
|
if tc.hasError {
|
|
require.Error(t, err)
|
|
} else {
|
|
require.NoError(t, err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestBlockBaseSeriesSet(t *testing.T) {
|
|
type refdSeries struct {
|
|
lset labels.Labels
|
|
chunks []chunks.Meta
|
|
|
|
ref storage.SeriesRef
|
|
}
|
|
|
|
cases := []struct {
|
|
series []refdSeries
|
|
// Postings should be in the sorted order of the series
|
|
postings []storage.SeriesRef
|
|
|
|
expIdxs []int
|
|
}{
|
|
{
|
|
series: []refdSeries{
|
|
{
|
|
lset: labels.FromStrings("a", "a"),
|
|
chunks: []chunks.Meta{
|
|
{Ref: 29},
|
|
{Ref: 45},
|
|
{Ref: 245},
|
|
{Ref: 123},
|
|
{Ref: 4232},
|
|
{Ref: 5344},
|
|
{Ref: 121},
|
|
},
|
|
ref: 12,
|
|
},
|
|
{
|
|
lset: labels.FromStrings("a", "a", "b", "b"),
|
|
chunks: []chunks.Meta{
|
|
{Ref: 82}, {Ref: 23}, {Ref: 234}, {Ref: 65}, {Ref: 26},
|
|
},
|
|
ref: 10,
|
|
},
|
|
{
|
|
lset: labels.FromStrings("b", "c"),
|
|
chunks: []chunks.Meta{{Ref: 8282}},
|
|
ref: 1,
|
|
},
|
|
{
|
|
lset: labels.FromStrings("b", "b"),
|
|
chunks: []chunks.Meta{
|
|
{Ref: 829}, {Ref: 239}, {Ref: 2349}, {Ref: 659}, {Ref: 269},
|
|
},
|
|
ref: 108,
|
|
},
|
|
},
|
|
postings: []storage.SeriesRef{12, 13, 10, 108}, // 13 doesn't exist and should just be skipped over.
|
|
expIdxs: []int{0, 1, 3},
|
|
},
|
|
{
|
|
series: []refdSeries{
|
|
{
|
|
lset: labels.FromStrings("a", "a", "b", "b"),
|
|
chunks: []chunks.Meta{
|
|
{Ref: 82}, {Ref: 23}, {Ref: 234}, {Ref: 65}, {Ref: 26},
|
|
},
|
|
ref: 10,
|
|
},
|
|
{
|
|
lset: labels.FromStrings("b", "c"),
|
|
chunks: []chunks.Meta{{Ref: 8282}},
|
|
ref: 3,
|
|
},
|
|
},
|
|
postings: []storage.SeriesRef{},
|
|
expIdxs: []int{},
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
mi := newMockIndex()
|
|
for _, s := range tc.series {
|
|
require.NoError(t, mi.AddSeries(s.ref, s.lset, s.chunks...))
|
|
}
|
|
|
|
bcs := &blockBaseSeriesSet{
|
|
p: index.NewListPostings(tc.postings),
|
|
index: mi,
|
|
tombstones: tombstones.NewMemTombstones(),
|
|
}
|
|
|
|
i := 0
|
|
for bcs.Next() {
|
|
si := populateWithDelGenericSeriesIterator{}
|
|
si.reset(bcs.blockID, bcs.chunks, bcs.curr.chks, bcs.curr.intervals)
|
|
idx := tc.expIdxs[i]
|
|
|
|
require.Equal(t, tc.series[idx].lset, bcs.curr.labels)
|
|
require.Equal(t, tc.series[idx].chunks, si.metas)
|
|
|
|
i++
|
|
}
|
|
require.Len(t, tc.expIdxs, i)
|
|
require.NoError(t, bcs.Err())
|
|
}
|
|
}
|
|
|
|
func BenchmarkHeadChunkQuerier(b *testing.B) {
|
|
db := openTestDB(b, nil, nil)
|
|
defer func() {
|
|
require.NoError(b, db.Close())
|
|
}()
|
|
|
|
// 3h of data.
|
|
numTimeseries := 100
|
|
app := db.Appender(context.Background())
|
|
for i := 0; i < 120*6; i++ {
|
|
for j := 0; j < numTimeseries; j++ {
|
|
lbls := labels.FromStrings("foo", fmt.Sprintf("bar%d", j))
|
|
if i%10 == 0 {
|
|
require.NoError(b, app.Commit())
|
|
app = db.Appender(context.Background())
|
|
}
|
|
_, err := app.Append(0, lbls, int64(i*15)*time.Second.Milliseconds(), float64(i*100))
|
|
require.NoError(b, err)
|
|
}
|
|
}
|
|
require.NoError(b, app.Commit())
|
|
|
|
querier, err := db.ChunkQuerier(math.MinInt64, math.MaxInt64)
|
|
require.NoError(b, err)
|
|
defer func(q storage.ChunkQuerier) {
|
|
require.NoError(b, q.Close())
|
|
}(querier)
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
ss := querier.Select(context.Background(), false, nil, labels.MustNewMatcher(labels.MatchRegexp, "foo", "bar.*"))
|
|
total := 0
|
|
for ss.Next() {
|
|
cs := ss.At()
|
|
it := cs.Iterator(nil)
|
|
for it.Next() {
|
|
m := it.At()
|
|
total += m.Chunk.NumSamples()
|
|
}
|
|
}
|
|
_ = total
|
|
require.NoError(b, ss.Err())
|
|
}
|
|
}
|
|
|
|
func BenchmarkHeadQuerier(b *testing.B) {
|
|
db := openTestDB(b, nil, nil)
|
|
defer func() {
|
|
require.NoError(b, db.Close())
|
|
}()
|
|
|
|
// 3h of data.
|
|
numTimeseries := 100
|
|
app := db.Appender(context.Background())
|
|
for i := 0; i < 120*6; i++ {
|
|
for j := 0; j < numTimeseries; j++ {
|
|
lbls := labels.FromStrings("foo", fmt.Sprintf("bar%d", j))
|
|
if i%10 == 0 {
|
|
require.NoError(b, app.Commit())
|
|
app = db.Appender(context.Background())
|
|
}
|
|
_, err := app.Append(0, lbls, int64(i*15)*time.Second.Milliseconds(), float64(i*100))
|
|
require.NoError(b, err)
|
|
}
|
|
}
|
|
require.NoError(b, app.Commit())
|
|
|
|
querier, err := db.Querier(math.MinInt64, math.MaxInt64)
|
|
require.NoError(b, err)
|
|
defer func(q storage.Querier) {
|
|
require.NoError(b, q.Close())
|
|
}(querier)
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
ss := querier.Select(context.Background(), false, nil, labels.MustNewMatcher(labels.MatchRegexp, "foo", "bar.*"))
|
|
total := int64(0)
|
|
for ss.Next() {
|
|
cs := ss.At()
|
|
it := cs.Iterator(nil)
|
|
for it.Next() != chunkenc.ValNone {
|
|
ts, _ := it.At()
|
|
total += ts
|
|
}
|
|
}
|
|
_ = total
|
|
require.NoError(b, ss.Err())
|
|
}
|
|
}
|
|
|
|
// This is a regression test for the case where gauge histograms were not handled by
|
|
// populateWithDelChunkSeriesIterator correctly.
|
|
func TestQueryWithDeletedHistograms(t *testing.T) {
|
|
ctx := context.Background()
|
|
testcases := map[string]func(int) (*histogram.Histogram, *histogram.FloatHistogram){
|
|
"intCounter": func(i int) (*histogram.Histogram, *histogram.FloatHistogram) {
|
|
return tsdbutil.GenerateTestHistogram(i), nil
|
|
},
|
|
"intgauge": func(i int) (*histogram.Histogram, *histogram.FloatHistogram) {
|
|
return tsdbutil.GenerateTestGaugeHistogram(rand.Int() % 1000), nil
|
|
},
|
|
"floatCounter": func(i int) (*histogram.Histogram, *histogram.FloatHistogram) {
|
|
return nil, tsdbutil.GenerateTestFloatHistogram(i)
|
|
},
|
|
"floatGauge": func(i int) (*histogram.Histogram, *histogram.FloatHistogram) {
|
|
return nil, tsdbutil.GenerateTestGaugeFloatHistogram(rand.Int() % 1000)
|
|
},
|
|
}
|
|
|
|
for name, tc := range testcases {
|
|
t.Run(name, func(t *testing.T) {
|
|
db := openTestDB(t, nil, nil)
|
|
defer func() {
|
|
require.NoError(t, db.Close())
|
|
}()
|
|
|
|
db.EnableNativeHistograms()
|
|
appender := db.Appender(context.Background())
|
|
|
|
var (
|
|
err error
|
|
seriesRef storage.SeriesRef
|
|
)
|
|
lbs := labels.FromStrings("__name__", "test", "type", name)
|
|
|
|
for i := 0; i < 100; i++ {
|
|
h, fh := tc(i)
|
|
seriesRef, err = appender.AppendHistogram(seriesRef, lbs, int64(i), h, fh)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
err = appender.Commit()
|
|
require.NoError(t, err)
|
|
|
|
matcher, err := labels.NewMatcher(labels.MatchEqual, "__name__", "test")
|
|
require.NoError(t, err)
|
|
|
|
// Delete the last 20.
|
|
err = db.Delete(ctx, 80, 100, matcher)
|
|
require.NoError(t, err)
|
|
|
|
chunkQuerier, err := db.ChunkQuerier(0, 100)
|
|
require.NoError(t, err)
|
|
|
|
css := chunkQuerier.Select(context.Background(), false, nil, matcher)
|
|
|
|
seriesCount := 0
|
|
for css.Next() {
|
|
seriesCount++
|
|
series := css.At()
|
|
|
|
sampleCount := 0
|
|
it := series.Iterator(nil)
|
|
for it.Next() {
|
|
chk := it.At()
|
|
for cit := chk.Chunk.Iterator(nil); cit.Next() != chunkenc.ValNone; {
|
|
sampleCount++
|
|
}
|
|
}
|
|
require.NoError(t, it.Err())
|
|
require.Equal(t, 80, sampleCount)
|
|
}
|
|
require.NoError(t, css.Err())
|
|
require.Equal(t, 1, seriesCount)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestQueryWithOneChunkCompletelyDeleted(t *testing.T) {
|
|
ctx := context.Background()
|
|
db := openTestDB(t, nil, nil)
|
|
defer func() {
|
|
require.NoError(t, db.Close())
|
|
}()
|
|
|
|
db.EnableNativeHistograms()
|
|
appender := db.Appender(context.Background())
|
|
|
|
var (
|
|
err error
|
|
seriesRef storage.SeriesRef
|
|
)
|
|
lbs := labels.FromStrings("__name__", "test")
|
|
|
|
// Create an int histogram chunk with samples between 0 - 20 and 30 - 40.
|
|
for i := 0; i < 20; i++ {
|
|
h := tsdbutil.GenerateTestHistogram(1)
|
|
seriesRef, err = appender.AppendHistogram(seriesRef, lbs, int64(i), h, nil)
|
|
require.NoError(t, err)
|
|
}
|
|
for i := 30; i < 40; i++ {
|
|
h := tsdbutil.GenerateTestHistogram(1)
|
|
seriesRef, err = appender.AppendHistogram(seriesRef, lbs, int64(i), h, nil)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
// Append some float histograms - float histograms are a different encoding
|
|
// type from int histograms so a new chunk is created.
|
|
for i := 60; i < 100; i++ {
|
|
fh := tsdbutil.GenerateTestFloatHistogram(1)
|
|
seriesRef, err = appender.AppendHistogram(seriesRef, lbs, int64(i), nil, fh)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
err = appender.Commit()
|
|
require.NoError(t, err)
|
|
|
|
matcher, err := labels.NewMatcher(labels.MatchEqual, "__name__", "test")
|
|
require.NoError(t, err)
|
|
|
|
// Delete all samples from the int histogram chunk. The deletion intervals
|
|
// doesn't cover the entire histogram chunk, but does cover all the samples
|
|
// in the chunk. This case was previously not handled properly.
|
|
err = db.Delete(ctx, 0, 20, matcher)
|
|
require.NoError(t, err)
|
|
err = db.Delete(ctx, 30, 40, matcher)
|
|
require.NoError(t, err)
|
|
|
|
chunkQuerier, err := db.ChunkQuerier(0, 100)
|
|
require.NoError(t, err)
|
|
|
|
css := chunkQuerier.Select(context.Background(), false, nil, matcher)
|
|
|
|
seriesCount := 0
|
|
for css.Next() {
|
|
seriesCount++
|
|
series := css.At()
|
|
|
|
sampleCount := 0
|
|
it := series.Iterator(nil)
|
|
for it.Next() {
|
|
chk := it.At()
|
|
cit := chk.Chunk.Iterator(nil)
|
|
for vt := cit.Next(); vt != chunkenc.ValNone; vt = cit.Next() {
|
|
require.Equal(t, chunkenc.ValFloatHistogram, vt, "Only float histograms expected, other sample types should have been deleted.")
|
|
sampleCount++
|
|
}
|
|
}
|
|
require.NoError(t, it.Err())
|
|
require.Equal(t, 40, sampleCount)
|
|
}
|
|
require.NoError(t, css.Err())
|
|
require.Equal(t, 1, seriesCount)
|
|
}
|