Skip to content

Commit

Permalink
Rename minRecentScanFailures to maxConsecutiveScanFailures (#1482)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl authored Aug 28, 2024
2 parents b9ec530 + 131527f commit fc6e786
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ formed.
"hosts": {
"allowRedundantIPs": false,
"maxDowntimeHours": 1440,
"minRecentScanFailures": 20,
"maxConsecutiveScanFailures": 20,
"scoreOverrides": {}
},
"contracts": {
Expand Down
10 changes: 5 additions & 5 deletions api/autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ type (

// HostsConfig contains all hosts settings used in the autopilot.
HostsConfig struct {
AllowRedundantIPs bool `json:"allowRedundantIPs"`
MaxDowntimeHours uint64 `json:"maxDowntimeHours"`
MinProtocolVersion string `json:"minProtocolVersion"`
MinRecentScanFailures uint64 `json:"minRecentScanFailures"`
ScoreOverrides map[types.PublicKey]float64 `json:"scoreOverrides"`
AllowRedundantIPs bool `json:"allowRedundantIPs"`
MaxDowntimeHours uint64 `json:"maxDowntimeHours"`
MinProtocolVersion string `json:"minProtocolVersion"`
MaxConsecutiveScanFailures uint64 `json:"maxConsecutiveScanFailures"`
ScoreOverrides map[types.PublicKey]float64 `json:"scoreOverrides"`
}
)

Expand Down
4 changes: 2 additions & 2 deletions api/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ type (

// HostsRemoveRequest is the request type for the /hosts/remove endpoint.
HostsRemoveRequest struct {
MaxDowntimeHours DurationH `json:"maxDowntimeHours"`
MinRecentScanFailures uint64 `json:"minRecentScanFailures"`
MaxDowntimeHours DurationH `json:"maxDowntimeHours"`
MaxConsecutiveScanFailures uint64 `json:"maxConsecutiveScanFailures"`
}

// SearchHostsRequest is the request type for the /api/bus/search/hosts
Expand Down
2 changes: 1 addition & 1 deletion autopilot/autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Bus interface {
// hostdb
Host(ctx context.Context, hostKey types.PublicKey) (api.Host, error)
HostsForScanning(ctx context.Context, opts api.HostsForScanningOptions) ([]api.HostAddress, error)
RemoveOfflineHosts(ctx context.Context, minRecentScanFailures uint64, maxDowntime time.Duration) (uint64, error)
RemoveOfflineHosts(ctx context.Context, maxConsecutiveScanFailures uint64, maxDowntime time.Duration) (uint64, error)
SearchHosts(ctx context.Context, opts api.SearchHostOptions) ([]api.Host, error)
UpdateHostCheck(ctx context.Context, autopilotID string, hostKey types.PublicKey, hostCheck api.HostCheck) error

Expand Down
4 changes: 2 additions & 2 deletions autopilot/contractor/hostscore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ var cfg = api.AutopilotConfig{
Set: api.DefaultAutopilotID,
},
Hosts: api.HostsConfig{
MaxDowntimeHours: 24 * 7 * 2,
MinRecentScanFailures: 10,
MaxDowntimeHours: 24 * 7 * 2,
MaxConsecutiveScanFailures: 10,
},
}

Expand Down
8 changes: 4 additions & 4 deletions autopilot/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
type (
HostStore interface {
HostsForScanning(ctx context.Context, opts api.HostsForScanningOptions) ([]api.HostAddress, error)
RemoveOfflineHosts(ctx context.Context, minRecentScanFailures uint64, maxDowntime time.Duration) (uint64, error)
RemoveOfflineHosts(ctx context.Context, maxConsecutiveScanFailures uint64, maxDowntime time.Duration) (uint64, error)
}

Scanner interface {
Expand Down Expand Up @@ -268,12 +268,12 @@ func (s *scanner) removeOfflineHosts(ctx context.Context) (removed uint64) {

s.logger.Infow("removing offline hosts",
"maxDowntime", maxDowntime,
"minRecentScanFailures", s.hostsCfg.MinRecentScanFailures)
"maxConsecutiveScanFailures", s.hostsCfg.MaxConsecutiveScanFailures)

var err error
removed, err = s.hs.RemoveOfflineHosts(ctx, s.hostsCfg.MinRecentScanFailures, maxDowntime)
removed, err = s.hs.RemoveOfflineHosts(ctx, s.hostsCfg.MaxConsecutiveScanFailures, maxDowntime)
if err != nil {
s.logger.Errorw("removing offline hosts failed", zap.Error(err), "maxDowntime", maxDowntime, "minRecentScanFailures", s.hostsCfg.MinRecentScanFailures)
s.logger.Errorw("removing offline hosts failed", zap.Error(err), "maxDowntime", maxDowntime, "maxConsecutiveScanFailures", s.hostsCfg.MaxConsecutiveScanFailures)
return
}

Expand Down
8 changes: 4 additions & 4 deletions autopilot/scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ func (hs *mockHostStore) HostsForScanning(ctx context.Context, opts api.HostsFor
return hostAddresses, nil
}

func (hs *mockHostStore) RemoveOfflineHosts(ctx context.Context, minRecentScanFailures uint64, maxDowntime time.Duration) (uint64, error) {
func (hs *mockHostStore) RemoveOfflineHosts(ctx context.Context, maxConsecutiveScanFailures uint64, maxDowntime time.Duration) (uint64, error) {
hs.mu.Lock()
defer hs.mu.Unlock()
hs.removals = append(hs.removals, fmt.Sprintf("%d-%d", minRecentScanFailures, maxDowntime))
hs.removals = append(hs.removals, fmt.Sprintf("%d-%d", maxConsecutiveScanFailures, maxDowntime))
return 0, nil
}

Expand Down Expand Up @@ -146,8 +146,8 @@ func TestScanner(t *testing.T) {

// update the hosts config
s.UpdateHostsConfig(api.HostsConfig{
MinRecentScanFailures: 10,
MaxDowntimeHours: 1,
MaxConsecutiveScanFailures: 10,
MaxDowntimeHours: 1,
})

s.Scan(context.Background(), w, true)
Expand Down
2 changes: 1 addition & 1 deletion bus/bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ type (
HostsForScanning(ctx context.Context, maxLastScan time.Time, offset, limit int) ([]api.HostAddress, error)
RecordHostScans(ctx context.Context, scans []api.HostScan) error
RecordPriceTables(ctx context.Context, priceTableUpdate []api.HostPriceTableUpdate) error
RemoveOfflineHosts(ctx context.Context, minRecentScanFailures uint64, maxDowntime time.Duration) (uint64, error)
RemoveOfflineHosts(ctx context.Context, maxConsecutiveScanFailures uint64, maxDowntime time.Duration) (uint64, error)
ResetLostSectors(ctx context.Context, hk types.PublicKey) error
SearchHosts(ctx context.Context, autopilotID, filterMode, usabilityMode, addressContains string, keyIn []types.PublicKey, offset, limit int) ([]api.Host, error)
UpdateHostAllowlistEntries(ctx context.Context, add, remove []types.PublicKey, clear bool) error
Expand Down
6 changes: 3 additions & 3 deletions bus/client/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ func (c *Client) RecordPriceTables(ctx context.Context, priceTableUpdates []api.
}

// RemoveOfflineHosts removes all hosts that have been offline for longer than the given max downtime.
func (c *Client) RemoveOfflineHosts(ctx context.Context, minRecentScanFailures uint64, maxDowntime time.Duration) (removed uint64, err error) {
func (c *Client) RemoveOfflineHosts(ctx context.Context, maxConsecutiveScanFailures uint64, maxDowntime time.Duration) (removed uint64, err error) {
err = c.c.WithContext(ctx).POST("/hosts/remove", api.HostsRemoveRequest{
MaxDowntimeHours: api.DurationH(maxDowntime),
MinRecentScanFailures: minRecentScanFailures,
MaxDowntimeHours: api.DurationH(maxDowntime),
MaxConsecutiveScanFailures: maxConsecutiveScanFailures,
}, &removed)
return
}
Expand Down
6 changes: 3 additions & 3 deletions bus/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,11 @@ func (b *Bus) hostsRemoveHandlerPOST(jc jape.Context) {
jc.Error(errors.New("maxDowntime must be non-zero"), http.StatusBadRequest)
return
}
if hrr.MinRecentScanFailures == 0 {
jc.Error(errors.New("minRecentScanFailures must be non-zero"), http.StatusBadRequest)
if hrr.MaxConsecutiveScanFailures == 0 {
jc.Error(errors.New("maxConsecutiveScanFailures must be non-zero"), http.StatusBadRequest)
return
}
removed, err := b.hs.RemoveOfflineHosts(jc.Request.Context(), hrr.MinRecentScanFailures, time.Duration(hrr.MaxDowntimeHours))
removed, err := b.hs.RemoveOfflineHosts(jc.Request.Context(), hrr.MaxConsecutiveScanFailures, time.Duration(hrr.MaxDowntimeHours))
if jc.Check("couldn't remove offline hosts", err) != nil {
return
}
Expand Down
6 changes: 3 additions & 3 deletions internal/test/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ var (
Prune: false,
},
Hosts: api.HostsConfig{
MaxDowntimeHours: 10,
MinRecentScanFailures: 10,
AllowRedundantIPs: true, // allow for integration tests by default
MaxDowntimeHours: 10,
MaxConsecutiveScanFailures: 10,
AllowRedundantIPs: true, // allow for integration tests by default
},
}

Expand Down
6 changes: 3 additions & 3 deletions stores/autopilot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func TestAutopilotStore(t *testing.T) {
Set: testContractSet,
},
Hosts: api.HostsConfig{
MaxDowntimeHours: 10,
MinRecentScanFailures: 10,
AllowRedundantIPs: true, // allow for integration tests by default
MaxDowntimeHours: 10,
MaxConsecutiveScanFailures: 10,
AllowRedundantIPs: true, // allow for integration tests by default
},
}

Expand Down

0 comments on commit fc6e786

Please sign in to comment.