forked from grafana/loki
/
interface.go
66 lines (57 loc) · 1.39 KB
/
interface.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package chunkenc
import (
"errors"
"io"
"time"
"github.com/grafana/loki/pkg/iter"
"github.com/grafana/loki/pkg/logproto"
)
// Errors returned by the chunk interface.
var (
ErrChunkFull = errors.New("chunk full")
ErrOutOfOrder = errors.New("entry out of order")
ErrInvalidSize = errors.New("invalid size")
ErrInvalidFlag = errors.New("invalid flag")
ErrInvalidChecksum = errors.New("invalid checksum")
)
// Encoding is the identifier for a chunk encoding.
type Encoding uint8
// The different available encodings.
const (
EncNone Encoding = iota
EncGZIP
EncDumb
)
func (e Encoding) String() string {
switch e {
case EncGZIP:
return "gzip"
case EncNone:
return "none"
case EncDumb:
return "dumb"
default:
return "unknown"
}
}
// Chunk is the interface for the compressed logs chunk format.
type Chunk interface {
Bounds() (time.Time, time.Time)
SpaceFor(*logproto.Entry) bool
Append(*logproto.Entry) error
Iterator(from, through time.Time, direction logproto.Direction) (iter.EntryIterator, error)
Size() int
Bytes() ([]byte, error)
}
// CompressionWriter is the writer that compresses the data passed to it.
type CompressionWriter interface {
Write(p []byte) (int, error)
Close() error
Flush() error
Reset(w io.Writer)
}
// CompressionReader reads the compressed data.
type CompressionReader interface {
Read(p []byte) (int, error)
Reset(r io.Reader) error
}