Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only register lost sectors alert if the percentage of sectors lost exceeds a certain threshold. #1187

Merged
merged 1 commit into from
Apr 23, 2024
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
11 changes: 11 additions & 0 deletions autopilot/contractor/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import (
"go.sia.tech/renterd/api"
)

const (
// alertLostSectorsThresholdPct defines the the threshold at which we
// register the lost sectors alert. A value of 0.01 means that we register
// the alert if the host lost 1% (or more) of its stored data.
alertLostSectorsThresholdPct = 0.01
)

var (
alertChurnID = alerts.RandomAlertID() // constant until restarted
alertLostSectorsID = alerts.RandomAlertID() // constant until restarted
Expand Down Expand Up @@ -47,3 +54,7 @@ func newLostSectorsAlert(hk types.PublicKey, lostSectors uint64) alerts.Alert {
Timestamp: time.Now(),
}
}

func registerLostSectorsAlert(dataLost, dataStored uint64) bool {
return dataLost > 0 && float64(dataLost) >= float64(dataStored)*alertLostSectorsThresholdPct
}
26 changes: 26 additions & 0 deletions autopilot/contractor/alerts_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package contractor

import (
"testing"

rhpv2 "go.sia.tech/core/rhp/v2"
)

func TestRegisterLostSectorsAlert(t *testing.T) {
for _, tc := range []struct {
dataLost uint64
dataStored uint64
expected bool
}{
{0, 0, false},
{0, rhpv2.SectorSize, false},
{rhpv2.SectorSize, 0, true},
{rhpv2.SectorSize, 99 * rhpv2.SectorSize, true},
{rhpv2.SectorSize, 100 * rhpv2.SectorSize, true}, // exactly 1%
{rhpv2.SectorSize, 101 * rhpv2.SectorSize, false}, // just short of 1%
} {
if result := registerLostSectorsAlert(tc.dataLost, tc.dataStored); result != tc.expected {
t.Fatalf("unexpected result for dataLost=%d, dataStored=%d: %v", tc.dataLost, tc.dataStored, result)
}
}
}
2 changes: 1 addition & 1 deletion autopilot/contractor/contractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (c *Contractor) performContractMaintenance(ctx *mCtx, w Worker) (bool, erro
// check if any used hosts have lost data to warn the user
var toDismiss []types.Hash256
for _, h := range hosts {
if h.Interactions.LostSectors > 0 {
if registerLostSectorsAlert(h.Interactions.LostSectors*rhpv2.SectorSize, h.StoredData) {
c.alerter.RegisterAlert(ctx, newLostSectorsAlert(h.PublicKey, h.Interactions.LostSectors))
} else {
toDismiss = append(toDismiss, alerts.IDForHost(alertLostSectorsID, h.PublicKey))
Expand Down
Loading