mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 10:49:03 +08:00
fix: add legacy unit types and fix floating point issue (#4047)
This commit is contained in:
parent
40090aaf12
commit
92e2f1c467
1
.github/CODEOWNERS
vendored
1
.github/CODEOWNERS
vendored
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
/frontend/ @palashgdev @YounixM
|
/frontend/ @palashgdev @YounixM
|
||||||
/frontend/src/container/MetricsApplication @srikanthccv
|
/frontend/src/container/MetricsApplication @srikanthccv
|
||||||
|
/frontend/src/container/NewWidget/RightContainer/types.ts @srikanthccv
|
||||||
/deploy/ @prashant-shahi
|
/deploy/ @prashant-shahi
|
||||||
/sample-apps/ @prashant-shahi
|
/sample-apps/ @prashant-shahi
|
||||||
**/query-service/ @srikanthccv
|
**/query-service/ @srikanthccv
|
||||||
|
@ -43,9 +43,9 @@ var (
|
|||||||
// FromUnit returns a converter for the given unit
|
// FromUnit returns a converter for the given unit
|
||||||
func FromUnit(u Unit) Converter {
|
func FromUnit(u Unit) Converter {
|
||||||
switch u {
|
switch u {
|
||||||
case "ns", "us", "ms", "s", "m", "h", "d":
|
case "ns", "us", "µs", "ms", "s", "m", "h", "d":
|
||||||
return DurationConverter
|
return DurationConverter
|
||||||
case "bytes", "decbytes", "bits", "decbits", "kbytes", "decKbytes", "mbytes", "decMbytes", "gbytes", "decGbytes", "tbytes", "decTbytes", "pbytes", "decPbytes":
|
case "bytes", "decbytes", "bits", "decbits", "kbytes", "decKbytes", "deckbytes", "mbytes", "decMbytes", "decmbytes", "gbytes", "decGbytes", "decgbytes", "tbytes", "decTbytes", "dectbytes", "pbytes", "decPbytes", "decpbytes":
|
||||||
return DataConverter
|
return DataConverter
|
||||||
case "binBps", "Bps", "binbps", "bps", "KiBs", "Kibits", "KBs", "Kbits", "MiBs", "Mibits", "MBs", "Mbits", "GiBs", "Gibits", "GBs", "Gbits", "TiBs", "Tibits", "TBs", "Tbits", "PiBs", "Pibits", "PBs", "Pbits":
|
case "binBps", "Bps", "binbps", "bps", "KiBs", "Kibits", "KBs", "Kbits", "MiBs", "Mibits", "MBs", "Mbits", "GiBs", "Gibits", "GBs", "Gbits", "TiBs", "Tibits", "TBs", "Tbits", "PiBs", "Pibits", "PBs", "Pbits":
|
||||||
return DataRateConverter
|
return DataRateConverter
|
||||||
@ -64,7 +64,7 @@ func UnitToName(u string) string {
|
|||||||
switch u {
|
switch u {
|
||||||
case "ns":
|
case "ns":
|
||||||
return " ns"
|
return " ns"
|
||||||
case "us":
|
case "us", "µs":
|
||||||
return " us"
|
return " us"
|
||||||
case "ms":
|
case "ms":
|
||||||
return " ms"
|
return " ms"
|
||||||
@ -86,23 +86,23 @@ func UnitToName(u string) string {
|
|||||||
return " bits"
|
return " bits"
|
||||||
case "kbytes":
|
case "kbytes":
|
||||||
return " KiB"
|
return " KiB"
|
||||||
case "decKbytes":
|
case "decKbytes", "deckbytes":
|
||||||
return " kB"
|
return " kB"
|
||||||
case "mbytes":
|
case "mbytes":
|
||||||
return " MiB"
|
return " MiB"
|
||||||
case "decMbytes":
|
case "decMbytes", "decmbytes":
|
||||||
return " MB"
|
return " MB"
|
||||||
case "gbytes":
|
case "gbytes":
|
||||||
return " GiB"
|
return " GiB"
|
||||||
case "decGbytes":
|
case "decGbytes", "decgbytes":
|
||||||
return " GB"
|
return " GB"
|
||||||
case "tbytes":
|
case "tbytes":
|
||||||
return " TiB"
|
return " TiB"
|
||||||
case "decTbytes":
|
case "decTbytes", "decybytes":
|
||||||
return " TB"
|
return " TB"
|
||||||
case "pbytes":
|
case "pbytes":
|
||||||
return " PiB"
|
return " PiB"
|
||||||
case "decPbytes":
|
case "decPbytes", "decpbytes":
|
||||||
return " PB"
|
return " PB"
|
||||||
case "binBps":
|
case "binBps":
|
||||||
return " bytes/sec(IEC)"
|
return " bytes/sec(IEC)"
|
||||||
|
@ -70,23 +70,23 @@ func FromDataUnit(u Unit) float64 {
|
|||||||
return Bit
|
return Bit
|
||||||
case "kbytes": // base 2
|
case "kbytes": // base 2
|
||||||
return Kibibyte
|
return Kibibyte
|
||||||
case "deckbytes": // base 10
|
case "decKbytes", "deckbytes": // base 10
|
||||||
return Kilobyte
|
return Kilobyte
|
||||||
case "mbytes": // base 2
|
case "mbytes": // base 2
|
||||||
return Mebibyte
|
return Mebibyte
|
||||||
case "decmbytes": // base 10
|
case "decMbytes", "decmbytes": // base 10
|
||||||
return Megabyte
|
return Megabyte
|
||||||
case "gbytes": // base 2
|
case "gbytes": // base 2
|
||||||
return Gibibyte
|
return Gibibyte
|
||||||
case "decgbytes": // base 10
|
case "decGbytes", "decgbytes": // base 10
|
||||||
return Gigabyte
|
return Gigabyte
|
||||||
case "tbytes": // base 2
|
case "tbytes": // base 2
|
||||||
return Tebibyte
|
return Tebibyte
|
||||||
case "dectbytes": // base 10
|
case "decTbytes", "dectbytes": // base 10
|
||||||
return Terabyte
|
return Terabyte
|
||||||
case "pbytes": // base 2
|
case "pbytes": // base 2
|
||||||
return Pebibyte
|
return Pebibyte
|
||||||
case "decpbytes": // base 10
|
case "decPbytes", "decpbytes": // base 10
|
||||||
return Petabyte
|
return Petabyte
|
||||||
default:
|
default:
|
||||||
return 1
|
return 1
|
||||||
|
@ -31,7 +31,7 @@ func FromTimeUnit(u Unit) Duration {
|
|||||||
switch u {
|
switch u {
|
||||||
case "ns":
|
case "ns":
|
||||||
return Nanosecond
|
return Nanosecond
|
||||||
case "us":
|
case "us", "µs":
|
||||||
return Microsecond
|
return Microsecond
|
||||||
case "ms":
|
case "ms":
|
||||||
return Millisecond
|
return Millisecond
|
||||||
|
@ -30,23 +30,23 @@ func (f *dataFormatter) Format(value float64, unit string) string {
|
|||||||
return humanize.Bytes(uint64(value * converter.Bit))
|
return humanize.Bytes(uint64(value * converter.Bit))
|
||||||
case "kbytes":
|
case "kbytes":
|
||||||
return humanize.IBytes(uint64(value * converter.Kibibit))
|
return humanize.IBytes(uint64(value * converter.Kibibit))
|
||||||
case "deckbytes":
|
case "decKbytes", "deckbytes":
|
||||||
return humanize.IBytes(uint64(value * converter.Kilobit))
|
return humanize.IBytes(uint64(value * converter.Kilobit))
|
||||||
case "mbytes":
|
case "mbytes":
|
||||||
return humanize.IBytes(uint64(value * converter.Mebibit))
|
return humanize.IBytes(uint64(value * converter.Mebibit))
|
||||||
case "decmbytes":
|
case "decMbytes", "decmbytes":
|
||||||
return humanize.Bytes(uint64(value * converter.Megabit))
|
return humanize.Bytes(uint64(value * converter.Megabit))
|
||||||
case "gbytes":
|
case "gbytes":
|
||||||
return humanize.IBytes(uint64(value * converter.Gibibit))
|
return humanize.IBytes(uint64(value * converter.Gibibit))
|
||||||
case "decgbytes":
|
case "decGbytes", "decgbytes":
|
||||||
return humanize.Bytes(uint64(value * converter.Gigabit))
|
return humanize.Bytes(uint64(value * converter.Gigabit))
|
||||||
case "tbytes":
|
case "tbytes":
|
||||||
return humanize.IBytes(uint64(value * converter.Tebibit))
|
return humanize.IBytes(uint64(value * converter.Tebibit))
|
||||||
case "dectbytes":
|
case "decTbytes", "dectbytes":
|
||||||
return humanize.Bytes(uint64(value * converter.Terabit))
|
return humanize.Bytes(uint64(value * converter.Terabit))
|
||||||
case "pbytes":
|
case "pbytes":
|
||||||
return humanize.IBytes(uint64(value * converter.Pebibit))
|
return humanize.IBytes(uint64(value * converter.Pebibit))
|
||||||
case "decpbytes":
|
case "decPbytes", "decpbytes":
|
||||||
return humanize.Bytes(uint64(value * converter.Petabit))
|
return humanize.Bytes(uint64(value * converter.Petabit))
|
||||||
}
|
}
|
||||||
// When unit is not matched, return the value as it is.
|
// When unit is not matched, return the value as it is.
|
||||||
|
@ -18,9 +18,9 @@ var (
|
|||||||
|
|
||||||
func FromUnit(u string) Formatter {
|
func FromUnit(u string) Formatter {
|
||||||
switch u {
|
switch u {
|
||||||
case "ns", "us", "ms", "s", "m", "h", "d":
|
case "ns", "us", "µs", "ms", "s", "m", "h", "d":
|
||||||
return DurationFormatter
|
return DurationFormatter
|
||||||
case "bytes", "decbytes", "bits", "decbits", "kbytes", "decKbytes", "mbytes", "decMbytes", "gbytes", "decGbytes", "tbytes", "decTbytes", "pbytes", "decPbytes":
|
case "bytes", "decbytes", "bits", "decbits", "kbytes", "decKbytes", "deckbytes", "mbytes", "decMbytes", "decmbytes", "gbytes", "decGbytes", "decgbytes", "tbytes", "decTbytes", "dectbytes", "pbytes", "decPbytes", "decpbytes":
|
||||||
return DataFormatter
|
return DataFormatter
|
||||||
case "binBps", "Bps", "binbps", "bps", "KiBs", "Kibits", "KBs", "Kbits", "MiBs", "Mibits", "MBs", "Mbits", "GiBs", "Gibits", "GBs", "Gbits", "TiBs", "Tibits", "TBs", "Tbits", "PiBs", "Pibits", "PBs", "Pbits":
|
case "binBps", "Bps", "binbps", "bps", "KiBs", "Kibits", "KBs", "Kbits", "MiBs", "Mibits", "MBs", "Mbits", "GiBs", "Gibits", "GBs", "Gbits", "TiBs", "Tibits", "TBs", "Tbits", "PiBs", "Pibits", "PBs", "Pbits":
|
||||||
return DataRateFormatter
|
return DataRateFormatter
|
||||||
|
@ -81,11 +81,10 @@ func toFixed(value float64, decimals DecimalCount) string {
|
|||||||
precision := 0
|
precision := 0
|
||||||
if decimalPos != -1 {
|
if decimalPos != -1 {
|
||||||
precision = len(formatted) - decimalPos - 1
|
precision = len(formatted) - decimalPos - 1
|
||||||
}
|
|
||||||
|
|
||||||
if precision < *decimals {
|
if precision < *decimals {
|
||||||
return formatted + strings.Repeat("0", *decimals-precision)
|
return formatted + strings.Repeat("0", *decimals-precision)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return formatted
|
return formatted
|
||||||
}
|
}
|
||||||
|
15
pkg/query-service/formatter/scale_test.go
Normal file
15
pkg/query-service/formatter/scale_test.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package formatter
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestToFixed(t *testing.T) {
|
||||||
|
twoDecimals := 2
|
||||||
|
require.Equal(t, "0", toFixed(0, nil))
|
||||||
|
require.Equal(t, "61", toFixed(60.99, nil))
|
||||||
|
require.Equal(t, "51.4", toFixed(51.42, nil))
|
||||||
|
require.Equal(t, "51.42", toFixed(51.42, &twoDecimals))
|
||||||
|
}
|
@ -20,7 +20,7 @@ func (f *durationFormatter) Format(value float64, unit string) string {
|
|||||||
switch unit {
|
switch unit {
|
||||||
case "ns":
|
case "ns":
|
||||||
return toNanoSeconds(value)
|
return toNanoSeconds(value)
|
||||||
case "µs":
|
case "µs", "us":
|
||||||
return toMicroSeconds(value)
|
return toMicroSeconds(value)
|
||||||
case "ms":
|
case "ms":
|
||||||
return toMilliSeconds(value)
|
return toMilliSeconds(value)
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
|
||||||
"sync"
|
"sync"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
@ -780,7 +779,8 @@ func (r *ThresholdRule) Eval(ctx context.Context, ts time.Time, queriers *Querie
|
|||||||
}
|
}
|
||||||
|
|
||||||
value := valueFormatter.Format(smpl.V, r.Unit())
|
value := valueFormatter.Format(smpl.V, r.Unit())
|
||||||
threshold := strconv.FormatFloat(r.targetVal(), 'f', 2, 64) + converter.UnitToName(r.ruleCondition.TargetUnit)
|
thresholdFormatter := formatter.FromUnit(r.ruleCondition.TargetUnit)
|
||||||
|
threshold := thresholdFormatter.Format(r.targetVal(), r.ruleCondition.TargetUnit)
|
||||||
zap.S().Debugf("Alert template data for rule %s: Formatter=%s, Value=%s, Threshold=%s", r.Name(), valueFormatter.Name(), value, threshold)
|
zap.S().Debugf("Alert template data for rule %s: Formatter=%s, Value=%s, Threshold=%s", r.Name(), valueFormatter.Name(), value, threshold)
|
||||||
|
|
||||||
tmplData := AlertTemplateData(l, value, threshold)
|
tmplData := AlertTemplateData(l, value, threshold)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user