Skip to content

Commit

Permalink
autopilot: tweak severity
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjan committed Oct 19, 2023
1 parent 84b7210 commit f3b762b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
18 changes: 15 additions & 3 deletions autopilot/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ func (ap *Autopilot) DismissAlert(ctx context.Context, id types.Hash256) {
}
}

func newAccountLowBalanceAlert(address types.Address, balance types.Currency, severity alerts.Severity) alerts.Alert {
func newAccountLowBalanceAlert(address types.Address, balance types.Currency, bh, renewWindow, endHeight uint64) alerts.Alert {
severity := alerts.SeverityInfo
if bh+renewWindow/2 >= endHeight {
severity = alerts.SeverityCritical
} else if bh+renewWindow >= endHeight {
severity = alerts.SeverityWarning
}

return alerts.Alert{
ID: alertLowBalanceID,
Severity: severity,
Expand Down Expand Up @@ -82,9 +89,14 @@ func newAccountRefillAlert(id rhpv3.Account, contract api.ContractMetadata, err
}

func newContractRenewalFailedAlert(contract api.ContractMetadata, interrupted bool, err error) alerts.Alert {
severity := alerts.SeverityWarning
if interrupted {
severity = alerts.SeverityCritical
}

return alerts.Alert{
ID: alertIDForContract(alertRenewalFailedID, contract),
Severity: alerts.SeverityCritical,
Severity: severity,
Message: "Contract renewal failed",
Data: map[string]interface{}{
"error": err,
Expand Down Expand Up @@ -141,7 +153,7 @@ func newSlabMigrationFailedAlert(slab object.Slab, health float64, err error) al

func newRefreshHealthFailedAlert(err error) alerts.Alert {
return alerts.Alert{
ID: randomAlertID(), // TODO: could be constant between runs
ID: randomAlertID(),
Severity: alerts.SeverityCritical,
Message: "Health refresh failed",
Data: map[string]interface{}{
Expand Down
11 changes: 1 addition & 10 deletions autopilot/contractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
rhpv2 "go.sia.tech/core/rhp/v2"
rhpv3 "go.sia.tech/core/rhp/v3"
"go.sia.tech/core/types"
"go.sia.tech/renterd/alerts"
"go.sia.tech/renterd/api"
"go.sia.tech/renterd/hostdb"
"go.sia.tech/renterd/tracing"
Expand Down Expand Up @@ -499,7 +498,6 @@ func (c *contractor) performWalletMaintenance(ctx context.Context) error {
l.Warnf("wallet maintenance skipped, fetching consensus state failed with err: %v", err)
return err
}
bh := cs.BlockHeight

// fetch wallet balance
wallet, err := b.Wallet(ctx)
Expand All @@ -511,14 +509,7 @@ func (c *contractor) performWalletMaintenance(ctx context.Context) error {

// register an alert if balance is low
if balance.Cmp(cfg.Contracts.Allowance) < 0 {
// increase severity as we progress through renew window
severity := alerts.SeverityInfo
if bh+renewWindow/2 >= endHeight(cfg, period) {
severity = alerts.SeverityCritical
} else if bh+renewWindow >= endHeight(cfg, period) {
severity = alerts.SeverityWarning
}
c.ap.RegisterAlert(ctx, newAccountLowBalanceAlert(state.address, balance, severity))
c.ap.RegisterAlert(ctx, newAccountLowBalanceAlert(state.address, balance, cs.BlockHeight, renewWindow, endHeight(cfg, period)))
} else {
c.ap.DismissAlert(ctx, alertLowBalanceID)
}
Expand Down

0 comments on commit f3b762b

Please sign in to comment.