Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
TEST_CASE=.

build:
CGO_CFLAGS="-Wno-deprecated-declarations" go build -ldflags '-s -w' -trimpath -o ./tenderduty main.go

test:
CGO_CFLAGS="-Wno-deprecated-declarations" go test -v ./...
CGO_CFLAGS="-Wno-deprecated-declarations" go test -v -run "$(TEST_CASE)" ./...
2 changes: 1 addition & 1 deletion td2/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ func evaluateStakeChangeAlert(cc *ChainConfig) (bool, bool) {
} else if cc.Provider.Name == "namada" {
unit = "NAM"
}
message := fmt.Sprintf("%s's stake has %s by %.1g%% (%.1g %s now) compared to the previous check (%.1g %s)", cc.valInfo.Moniker, trend, math.Abs(stakeChangePercent)*100, stakeNow, unit, stakeBefore, unit)
message := fmt.Sprintf("%s's stake has %s by %.1f%% (%s %s now) compared to the previous check (%s %s)", cc.valInfo.Moniker, trend, math.Abs(stakeChangePercent)*100, utils.HumanSI(stakeNow), unit, utils.HumanSI(stakeBefore), unit)
if math.Abs(stakeChangePercent) >= threshold {
if !alarms.exist(cc.name, alertID) {
td.alert(cc.name, message, severity, false, &alertID)
Expand Down
31 changes: 31 additions & 0 deletions td2/utils/formatters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Package utils
package utils

import (
"math"
"strconv"
)

func HumanSI(v float64) string {
abs := math.Abs(v)
var value float64
var suffix string

switch {
case abs >= 1_000_000_000:
value = v / 1_000_000_000
suffix = "B"
case abs >= 1_000_000:
value = v / 1_000_000
suffix = "M"
case abs >= 1_000:
value = v / 1_000
suffix = "K"
default:
// No suffix: return plain float without trailing zeros
return strconv.FormatFloat(v, 'f', -1, 64)
}

// Format without trailing zeros and return uppercase suffix
return strconv.FormatFloat(value, 'f', -1, 64) + suffix
}
Loading