chore: Make dedicated iterator package #13273
Merged
+1,102
−1,160
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it:
Iterators of various types are widely used throughout the Loki code base. With the recent code additions of the bloom filters, a new set of utility functions for iterators emerged in
github.com/grafana/loki/v3/pkg/storage/bloom/v1
. The package defines interfaces for various common types, but also provides implementations to create and compose new iterators that implement these interfaces. This new package uses Go Generics.pkg/storage/bloom/v1
package to thepkg/iter/v2
package.EntryIterator
andSampleIterator
iterators to "inherit"v2.CloseIterator
in order to expose the same function names.The basic iterator interface (defined in
pkg/iter/v2/interface.go
) looks like so:Discussion
I proposed to use the
Err()
function for getting the optional error, because it was used in thepkg/storage/bloom/v1
package. However, in existing iterators for entries and samples, this function was namedError()
.I don't have strong arguments for or against one or the other name.
Next steps
This PR intentionally leaves the duplicate implementation of various iterator types, such a heap sort iterators, slice iterators, or peeking iterators. These should be consolidated in a follow up PR.
Checklist
CONTRIBUTING.md
guide (required)feat
PRs are unlikely to be accepted unless a case can be made for the feature actually being a bug fix to existing behavior.docs/sources/setup/upgrade/_index.md
production/helm/loki/Chart.yaml
and updateproduction/helm/loki/CHANGELOG.md
andproduction/helm/loki/README.md
. Example PRdeprecated-config.yaml
anddeleted-config.yaml
files respectively in thetools/deprecated-config-checker
directory. Example PR