From 47f893db71b88bd6aa16ee51eaf1d66fda010196 Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Mon, 26 Aug 2024 16:11:41 +0200 Subject: [PATCH] all: rename minRecentScanFailures to maxConsecutiveScanFailures --- README.md | 2 +- api/autopilot.go | 10 +++++----- api/host.go | 4 ++-- autopilot/autopilot.go | 2 +- autopilot/contractor/hostscore_test.go | 4 ++-- autopilot/scanner/scanner.go | 8 ++++---- autopilot/scanner/scanner_test.go | 8 ++++---- bus/bus.go | 2 +- bus/client/hosts.go | 6 +++--- bus/routes.go | 6 +++--- internal/test/config.go | 6 +++--- stores/autopilot_test.go | 6 +++--- 12 files changed, 32 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index bc01922e1..c20749935 100644 --- a/README.md +++ b/README.md @@ -542,7 +542,7 @@ formed. "hosts": { "allowRedundantIPs": false, "maxDowntimeHours": 1440, - "minRecentScanFailures": 20, + "maxConsecutiveScanFailures": 20, "scoreOverrides": {} }, "contracts": { diff --git a/api/autopilot.go b/api/autopilot.go index e81328d88..7f2ee7b08 100644 --- a/api/autopilot.go +++ b/api/autopilot.go @@ -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"` } ) diff --git a/api/host.go b/api/host.go index d932229d6..0a6b506ff 100644 --- a/api/host.go +++ b/api/host.go @@ -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 diff --git a/autopilot/autopilot.go b/autopilot/autopilot.go index 58fb0a9ec..6ac95bec7 100644 --- a/autopilot/autopilot.go +++ b/autopilot/autopilot.go @@ -55,7 +55,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 diff --git a/autopilot/contractor/hostscore_test.go b/autopilot/contractor/hostscore_test.go index 9b2cdea47..6acc309ec 100644 --- a/autopilot/contractor/hostscore_test.go +++ b/autopilot/contractor/hostscore_test.go @@ -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, }, } diff --git a/autopilot/scanner/scanner.go b/autopilot/scanner/scanner.go index 6c34274ad..f79147a17 100644 --- a/autopilot/scanner/scanner.go +++ b/autopilot/scanner/scanner.go @@ -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 { @@ -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 } diff --git a/autopilot/scanner/scanner_test.go b/autopilot/scanner/scanner_test.go index ee847395b..665913ab0 100644 --- a/autopilot/scanner/scanner_test.go +++ b/autopilot/scanner/scanner_test.go @@ -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 } @@ -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) diff --git a/bus/bus.go b/bus/bus.go index 431d5abd5..ba0aadb27 100644 --- a/bus/bus.go +++ b/bus/bus.go @@ -200,7 +200,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 diff --git a/bus/client/hosts.go b/bus/client/hosts.go index 709cb899c..1e09ab3ea 100644 --- a/bus/client/hosts.go +++ b/bus/client/hosts.go @@ -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 } diff --git a/bus/routes.go b/bus/routes.go index 9feb747e4..3c9d8078c 100644 --- a/bus/routes.go +++ b/bus/routes.go @@ -637,11 +637,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 } diff --git a/internal/test/config.go b/internal/test/config.go index 1b5d926a0..64dc98c7f 100644 --- a/internal/test/config.go +++ b/internal/test/config.go @@ -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 }, } diff --git a/stores/autopilot_test.go b/stores/autopilot_test.go index 1ed78370c..9559b2dbe 100644 --- a/stores/autopilot_test.go +++ b/stores/autopilot_test.go @@ -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 }, }