Add use_int_samples option for backwards compatibility (#5563)

This commit is contained in:
Pontus Rydin
2019-03-11 14:16:32 -04:00
committed by Daniel Nelson
parent 1752619e35
commit 19988a94de
2 changed files with 23 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"log"
"math"
"math/rand"
"net/url"
"regexp"
@@ -948,7 +949,7 @@ func (e *Endpoint) collectChunk(ctx context.Context, pqs []types.PerfQuerySpec,
e.populateTags(&objectRef, resourceType, res, t, &v)
nValues := 0
alignedInfo, alignedValues := alignSamples(em.SampleInfo, v.Value, interval) // TODO: Estimate interval
alignedInfo, alignedValues := alignSamples(em.SampleInfo, v.Value, interval)
for idx, sample := range alignedInfo {
// According to the docs, SampleInfo and Value should have the same length, but we've seen corrupted
@@ -981,7 +982,11 @@ func (e *Endpoint) collectChunk(ctx context.Context, pqs []types.PerfQuerySpec,
if info.UnitInfo.GetElementDescription().Key == "percent" {
bucket.fields[fn] = float64(v) / 100.0
} else {
bucket.fields[fn] = v
if e.Parent.UseIntSamples {
bucket.fields[fn] = int64(round(v))
} else {
bucket.fields[fn] = v
}
}
count++
@@ -1082,3 +1087,11 @@ func cleanDiskTag(disk string) string {
// Remove enclosing "<>"
return strings.TrimSuffix(strings.TrimPrefix(disk, "<"), ">")
}
func round(x float64) float64 {
t := math.Trunc(x)
if math.Abs(x-t) >= 0.5 {
return t + math.Copysign(1, x)
}
return t
}