satellite/reputation: move Config fields into a Config struct

This has been a cause of some confusion, even though the fields are
labeled as being copies of config values.

Having them be under a field explicitly named "Config" makes this
clearer, plus, allows the values to be passed in simply as a copy
of the Config struct from the satellite, rather than copying the fields
individually (which can be error-prone, particularly as the AuditCount
field in UpdateRequest is apparently not the same thing as the
AuditCount field in reputation.Config).

Refs: https://github.com/storj/storj/issues/4601

Change-Id: I386953347b71068596618616934aa28e3245cdc1
This commit is contained in:
paul cannon 2022-05-06 20:34:56 -05:00 committed by Jeff Wendling
parent fcb39b4a0f
commit 5bc4c254d4
6 changed files with 82 additions and 79 deletions

View File

@ -39,7 +39,9 @@ func BenchmarkReputation(b *testing.B) {
_, err := reputationdb.Update(ctx, reputation.UpdateRequest{ _, err := reputationdb.Update(ctx, reputation.UpdateRequest{
NodeID: id, NodeID: id,
AuditOutcome: reputation.AuditSuccess, AuditOutcome: reputation.AuditSuccess,
Config: reputation.Config{
AuditHistory: testAuditHistoryConfig(), AuditHistory: testAuditHistoryConfig(),
},
}, time.Now()) }, time.Now())
require.NoError(b, err) require.NoError(b, err)
} }
@ -51,7 +53,9 @@ func BenchmarkReputation(b *testing.B) {
_, err := reputationdb.Update(ctx, reputation.UpdateRequest{ _, err := reputationdb.Update(ctx, reputation.UpdateRequest{
NodeID: id, NodeID: id,
AuditOutcome: reputation.AuditFailure, AuditOutcome: reputation.AuditFailure,
Config: reputation.Config{
AuditHistory: testAuditHistoryConfig(), AuditHistory: testAuditHistoryConfig(),
},
}, time.Now()) }, time.Now())
require.NoError(b, err) require.NoError(b, err)
} }
@ -63,7 +67,9 @@ func BenchmarkReputation(b *testing.B) {
_, err := reputationdb.Update(ctx, reputation.UpdateRequest{ _, err := reputationdb.Update(ctx, reputation.UpdateRequest{
NodeID: id, NodeID: id,
AuditOutcome: reputation.AuditUnknown, AuditOutcome: reputation.AuditUnknown,
Config: reputation.Config{
AuditHistory: testAuditHistoryConfig(), AuditHistory: testAuditHistoryConfig(),
},
}, time.Now()) }, time.Now())
require.NoError(b, err) require.NoError(b, err)
} }
@ -75,7 +81,9 @@ func BenchmarkReputation(b *testing.B) {
_, err := reputationdb.Update(ctx, reputation.UpdateRequest{ _, err := reputationdb.Update(ctx, reputation.UpdateRequest{
NodeID: id, NodeID: id,
AuditOutcome: reputation.AuditOffline, AuditOutcome: reputation.AuditOffline,
Config: reputation.Config{
AuditHistory: testAuditHistoryConfig(), AuditHistory: testAuditHistoryConfig(),
},
}, time.Now()) }, time.Now())
require.NoError(b, err) require.NoError(b, err)
} }

View File

@ -38,17 +38,10 @@ type Config struct {
type UpdateRequest struct { type UpdateRequest struct {
NodeID storj.NodeID NodeID storj.NodeID
AuditOutcome AuditType AuditOutcome AuditType
// n.b. these are set values from the satellite. // Config is a copy of the Config struct from the satellite.
// They are part of the UpdateRequest struct in order to be // It is part of the UpdateRequest struct in order to be more easily
// more easily accessible in satellite/satellitedb/reputation.go. // accessible from satellitedb code.
AuditCount int64 Config
AuditLambda float64
AuditWeight float64
AuditDQ float64
SuspensionGracePeriod time.Duration
SuspensionDQEnabled bool
AuditsRequiredForVetting int64
AuditHistory AuditHistoryConfig
} }
// AuditHistoryConfig is a configuration struct defining time periods and thresholds for penalizing nodes for being offline. // AuditHistoryConfig is a configuration struct defining time periods and thresholds for penalizing nodes for being offline.

View File

@ -38,8 +38,10 @@ func TestUpdate(t *testing.T) {
updateReq := reputation.UpdateRequest{ updateReq := reputation.UpdateRequest{
NodeID: node.ID(), NodeID: node.ID(),
AuditOutcome: reputation.AuditOffline, AuditOutcome: reputation.AuditOffline,
AuditsRequiredForVetting: planet.Satellites[0].Config.Reputation.AuditCount, Config: reputation.Config{
AuditCount: planet.Satellites[0].Config.Reputation.AuditCount,
AuditHistory: testAuditHistoryConfig(), AuditHistory: testAuditHistoryConfig(),
},
} }
nodeStats, err := db.Update(ctx, updateReq, time.Now()) nodeStats, err := db.Update(ctx, updateReq, time.Now())
require.NoError(t, err) require.NoError(t, err)
@ -89,14 +91,15 @@ func TestDBDisqualificationAuditFailure(t *testing.T) {
updateReq := reputation.UpdateRequest{ updateReq := reputation.UpdateRequest{
NodeID: nodeID, NodeID: nodeID,
AuditOutcome: reputation.AuditFailure, AuditOutcome: reputation.AuditFailure,
AuditCount: 0, Config: reputation.Config{
AuditLambda: 1, AuditLambda: 1,
AuditWeight: 1, AuditWeight: 1,
AuditDQ: 0.99, AuditDQ: 0.99,
SuspensionGracePeriod: 0, SuspensionGracePeriod: 0,
SuspensionDQEnabled: false, SuspensionDQEnabled: false,
AuditsRequiredForVetting: 0, AuditCount: 0,
AuditHistory: reputation.AuditHistoryConfig{}, AuditHistory: reputation.AuditHistoryConfig{},
},
} }
status, err := reputationDB.Update(ctx, updateReq, now) status, err := reputationDB.Update(ctx, updateReq, now)
@ -116,14 +119,15 @@ func TestDBDisqualificationSuspension(t *testing.T) {
updateReq := reputation.UpdateRequest{ updateReq := reputation.UpdateRequest{
NodeID: nodeID, NodeID: nodeID,
AuditOutcome: reputation.AuditUnknown, AuditOutcome: reputation.AuditUnknown,
AuditCount: 0, Config: reputation.Config{
AuditLambda: 1, AuditLambda: 1,
AuditWeight: 1, AuditWeight: 1,
AuditDQ: 0.99, AuditDQ: 0.99,
SuspensionGracePeriod: 0, SuspensionGracePeriod: 0,
SuspensionDQEnabled: true, SuspensionDQEnabled: true,
AuditsRequiredForVetting: 0, AuditCount: 0,
AuditHistory: reputation.AuditHistoryConfig{}, AuditHistory: reputation.AuditHistoryConfig{},
},
} }
// suspend node due to failed unknown audit // suspend node due to failed unknown audit
@ -149,13 +153,13 @@ func TestDBDisqualificationNodeOffline(t *testing.T) {
updateReq := reputation.UpdateRequest{ updateReq := reputation.UpdateRequest{
NodeID: nodeID, NodeID: nodeID,
AuditOutcome: reputation.AuditOffline, AuditOutcome: reputation.AuditOffline,
AuditCount: 0, Config: reputation.Config{
AuditLambda: 0, AuditLambda: 0,
AuditWeight: 0, AuditWeight: 0,
AuditDQ: 0, AuditDQ: 0,
SuspensionGracePeriod: 0, SuspensionGracePeriod: 0,
SuspensionDQEnabled: false, SuspensionDQEnabled: false,
AuditsRequiredForVetting: 0, AuditCount: 0,
AuditHistory: reputation.AuditHistoryConfig{ AuditHistory: reputation.AuditHistoryConfig{
WindowSize: 0, WindowSize: 0,
TrackingPeriod: 1 * time.Second, TrackingPeriod: 1 * time.Second,
@ -164,6 +168,7 @@ func TestDBDisqualificationNodeOffline(t *testing.T) {
OfflineDQEnabled: true, OfflineDQEnabled: true,
OfflineSuspensionEnabled: true, OfflineSuspensionEnabled: true,
}, },
},
} }
// first window always returns perfect score // first window always returns perfect score

View File

@ -72,14 +72,7 @@ func (service *Service) ApplyAudit(ctx context.Context, nodeID storj.NodeID, rep
statusUpdate, err := service.db.Update(ctx, UpdateRequest{ statusUpdate, err := service.db.Update(ctx, UpdateRequest{
NodeID: nodeID, NodeID: nodeID,
AuditOutcome: result, AuditOutcome: result,
Config: service.config,
AuditLambda: service.config.AuditLambda,
AuditWeight: service.config.AuditWeight,
AuditDQ: service.config.AuditDQ,
SuspensionGracePeriod: service.config.SuspensionGracePeriod,
SuspensionDQEnabled: service.config.SuspensionDQEnabled,
AuditsRequiredForVetting: service.config.AuditCount,
AuditHistory: service.config.AuditHistory,
}, now) }, now)
if err != nil { if err != nil {
return err return err

View File

@ -302,7 +302,9 @@ func TestOfflineAuditSuspensionDisabled(t *testing.T) {
req := reputation.UpdateRequest{ req := reputation.UpdateRequest{
NodeID: nodeID, NodeID: nodeID,
AuditOutcome: reputation.AuditOffline, AuditOutcome: reputation.AuditOffline,
Config: reputation.Config{
AuditHistory: config, AuditHistory: config,
},
} }
// check that unsuspended node does not get suspended // check that unsuspended node does not get suspended
@ -369,6 +371,7 @@ func TestOfflineSuspend(t *testing.T) {
updateReq := reputation.UpdateRequest{ updateReq := reputation.UpdateRequest{
NodeID: nodeID, NodeID: nodeID,
AuditOutcome: reputation.AuditOffline, AuditOutcome: reputation.AuditOffline,
Config: reputation.Config{
AuditHistory: reputation.AuditHistoryConfig{ AuditHistory: reputation.AuditHistoryConfig{
WindowSize: time.Hour, WindowSize: time.Hour,
TrackingPeriod: 2 * time.Hour, TrackingPeriod: 2 * time.Hour,
@ -383,7 +386,8 @@ func TestOfflineSuspend(t *testing.T) {
AuditDQ: 0.6, AuditDQ: 0.6,
SuspensionGracePeriod: time.Hour, SuspensionGracePeriod: time.Hour,
SuspensionDQEnabled: true, SuspensionDQEnabled: true,
AuditsRequiredForVetting: 0, AuditCount: 0,
},
} }
// give node an offline audit // give node an offline audit

View File

@ -467,7 +467,7 @@ func (reputations *reputations) populateUpdateNodeStats(dbNode *dbx.Reputation,
OnlineScore: float64Field{set: true, value: auditHistoryResponse.NewScore}, OnlineScore: float64Field{set: true, value: auditHistoryResponse.NewScore},
} }
if vettedAt == nil && updatedTotalAuditCount >= updateReq.AuditsRequiredForVetting { if vettedAt == nil && updatedTotalAuditCount >= updateReq.AuditCount {
updateFields.VettedAt = timeField{set: true, value: now} updateFields.VettedAt = timeField{set: true, value: now}
} }