Like Prometheus, but for logs.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
loki/pkg/logql/log/distinct.go

37 lines
758 B

package log
type distinctFilter struct {
datas map[string]map[string]int
labels []string
}
func NewDistinctFilter(labels []string) (Stage, error) {
datas := make(map[string]map[string]int, 0)
for _, label := range labels {
datas[label] = make(map[string]int, 0)
}
return &distinctFilter{
labels: labels,
datas: datas,
}, nil
}
func (r *distinctFilter) Process(_ int64, line []byte, lbs *LabelsBuilder) ([]byte, bool) {
keep := false
for _, label := range r.labels {
val, ok := lbs.Get(label)
if !ok {
return line, true
}
_, ok = r.datas[label][val]
if ok {
return line, false
}
r.datas[label][val] = 1
keep = true
}
return line, keep
}
func (r *distinctFilter) RequiredLabelNames() []string {
return []string{}
}