mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-11 15:34:56 +00:00
app/vmselect/promql: improve the accuracy of buckets_limit(k, buckets)
function
Now it properly merges the bucket with the previous bucket after deletion.
This commit is contained in:
parent
994fa2f3bf
commit
bb161497cf
1 changed files with 21 additions and 21 deletions
|
@ -333,30 +333,30 @@ func transformBucketsLimit(tfa *transformFuncArg) ([]*timeseries, error) {
|
||||||
// Remove buckets with the smallest counters.
|
// Remove buckets with the smallest counters.
|
||||||
rvs := make([]*timeseries, 0, len(tss))
|
rvs := make([]*timeseries, 0, len(tss))
|
||||||
for _, leGroup := range m {
|
for _, leGroup := range m {
|
||||||
if len(leGroup) <= limit {
|
for len(leGroup) > limit {
|
||||||
// The number of buckets in leGroup doesn't exceed the limit.
|
// Remove a single bucket with the smallest sum.
|
||||||
for _, xx := range leGroup {
|
// TODO: optimize this dumb implementation a bit, since it may be slow on big number of buckets.
|
||||||
rvs = append(rvs, xx.ts)
|
sort.Slice(leGroup, func(i, j int) bool {
|
||||||
}
|
return leGroup[i].le < leGroup[j].le
|
||||||
continue
|
})
|
||||||
}
|
|
||||||
// The number of buckets in leGroup exceeds the limit. Remove buckets with the smallest sums.
|
|
||||||
sort.Slice(leGroup, func(i, j int) bool {
|
|
||||||
return leGroup[i].le < leGroup[j].le
|
|
||||||
})
|
|
||||||
for n := range tss[0].Values {
|
|
||||||
prevValue := float64(0)
|
|
||||||
for i := range leGroup {
|
for i := range leGroup {
|
||||||
xx := &leGroup[i]
|
leGroup[i].delta = 0
|
||||||
value := xx.ts.Values[n]
|
|
||||||
xx.delta += value - prevValue
|
|
||||||
prevValue = value
|
|
||||||
}
|
}
|
||||||
|
for n := range limits {
|
||||||
|
prevValue := float64(0)
|
||||||
|
for i := range leGroup {
|
||||||
|
xx := &leGroup[i]
|
||||||
|
value := xx.ts.Values[n]
|
||||||
|
xx.delta += value - prevValue
|
||||||
|
prevValue = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort.Slice(leGroup, func(i, j int) bool {
|
||||||
|
return leGroup[i].delta < leGroup[j].delta
|
||||||
|
})
|
||||||
|
leGroup = leGroup[1:]
|
||||||
}
|
}
|
||||||
sort.Slice(leGroup, func(i, j int) bool {
|
for _, xx := range leGroup {
|
||||||
return leGroup[i].delta < leGroup[j].delta
|
|
||||||
})
|
|
||||||
for _, xx := range leGroup[len(leGroup)-limit:] {
|
|
||||||
rvs = append(rvs, xx.ts)
|
rvs = append(rvs, xx.ts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue