forked from grafana/loki
-
Notifications
You must be signed in to change notification settings - Fork 1
/
logqlmodel.go
48 lines (37 loc) · 1.23 KB
/
logqlmodel.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
package logqlmodel
import (
"github.com/prometheus/prometheus/promql/parser"
"github.com/grafana/loki/pkg/querier/queryrange/queryrangebase/definitions"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/logqlmodel/stats"
)
// ValueTypeStreams promql.ValueType for log streams
const ValueTypeStreams = "streams"
// PackedEntryKey is a special JSON key used by the pack promtail stage and unpack parser
const PackedEntryKey = "_entry"
// Result is the result of a query execution.
type Result struct {
Data parser.Value
Statistics stats.Result
Headers []*definitions.PrometheusResponseHeader
}
// Streams is promql.Value
type Streams []logproto.Stream
func (streams Streams) Len() int { return len(streams) }
func (streams Streams) Swap(i, j int) { streams[i], streams[j] = streams[j], streams[i] }
func (streams Streams) Less(i, j int) bool {
return streams[i].Labels <= streams[j].Labels
}
// Type implements `promql.Value`
func (Streams) Type() parser.ValueType { return ValueTypeStreams }
// String implements `promql.Value`
func (Streams) String() string {
return ""
}
func (streams Streams) Lines() int64 {
var res int64
for _, s := range streams {
res += int64(len(s.Entries))
}
return res
}