-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
Copy pathiterator.go
50 lines (39 loc) · 1.72 KB
/
iterator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package iter
import (
"errors"
v2 "github.com/grafana/loki/v3/pkg/iter/v2"
"github.com/grafana/loki/v3/pkg/logproto"
)
type logprotoType interface {
logproto.Entry | logproto.Sample
}
type StreamIterator[T logprotoType] interface {
v2.CloseIterator[T]
// Labels returns the labels for the current entry.
// The labels can be mutated by the query engine and not reflect the original stream.
Labels() string
// StreamHash returns the hash of the original stream for the current entry.
StreamHash() uint64
}
type EntryIterator StreamIterator[logproto.Entry]
type SampleIterator StreamIterator[logproto.Sample]
// noOpIterator implements StreamIterator
type noOpIterator[T logprotoType] struct{}
func (noOpIterator[T]) Next() bool { return false }
func (noOpIterator[T]) Err() error { return nil }
func (noOpIterator[T]) At() (zero T) { return zero }
func (noOpIterator[T]) Labels() string { return "" }
func (noOpIterator[T]) StreamHash() uint64 { return 0 }
func (noOpIterator[T]) Close() error { return nil }
var NoopEntryIterator = noOpIterator[logproto.Entry]{}
var NoopSampleIterator = noOpIterator[logproto.Sample]{}
// errorIterator implements StreamIterator
type errorIterator[T logprotoType] struct{}
func (errorIterator[T]) Next() bool { return false }
func (errorIterator[T]) Err() error { return errors.New("error") }
func (errorIterator[T]) At() (zero T) { return zero }
func (errorIterator[T]) Labels() string { return "" }
func (errorIterator[T]) StreamHash() uint64 { return 0 }
func (errorIterator[T]) Close() error { return errors.New("close") }
var ErrorEntryIterator = errorIterator[logproto.Entry]{}
var ErrorSampleIterator = errorIterator[logproto.Sample]{}