Skip to content

Commit

Permalink
storagenode/{console, reputation}: Add audit history to storagenode API
Browse files Browse the repository at this point in the history
Change-Id: Id680b07feea380824e56496d545f46a94fdcc5d5
  • Loading branch information
mobyvb committed Jan 4, 2021
1 parent a90d6fc commit 710b868
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions storagenode/console/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ type Satellite struct {
Audit reputation.Metric `json:"audit"`
Uptime reputation.Metric `json:"uptime"`
OnlineScore float64 `json:"onlineScore"`
AuditHistory reputation.AuditHistory `json:"auditHistory"`
PriceModel PriceModel `json:"priceModel"`
NodeJoinedAt time.Time `json:"nodeJoinedAt"`
}
Expand Down Expand Up @@ -317,6 +318,7 @@ func (s *Service) GetSatelliteData(ctx context.Context, satelliteID storj.NodeID
Audit: rep.Audit,
Uptime: rep.Uptime,
OnlineScore: rep.OnlineScore,
AuditHistory: reputation.GetAuditHistoryFromPB(rep.AuditHistory),
PriceModel: satellitePricing,
NodeJoinedAt: rep.JoinedAt,
}, nil
Expand Down
30 changes: 30 additions & 0 deletions storagenode/reputation/reputation.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,33 @@ type Metric struct {
Score float64 `json:"score"`
UnknownScore float64 `json:"unknownScore"`
}

// AuditHistory encapsulates storagenode audit history.
type AuditHistory struct {
Score float64 `json:"score"`
Windows []AuditHistoryWindow `json:"windows"`
}

// AuditHistoryWindow encapsulates storagenode audit history window.
type AuditHistoryWindow struct {
WindowStart time.Time `json:"windowStart"`
TotalCount int32 `json:"totalCount"`
OnlineCount int32 `json:"onlineCount"`
}

// GetAuditHistoryFromPB creates the AuditHistory json struct from a protobuf.
func GetAuditHistoryFromPB(auditHistoryPB *pb.AuditHistory) AuditHistory {
ah := AuditHistory{}
if auditHistoryPB == nil {
return ah
}
ah.Score = auditHistoryPB.Score
for _, window := range auditHistoryPB.Windows {
ah.Windows = append(ah.Windows, AuditHistoryWindow{
WindowStart: window.WindowStart,
TotalCount: window.TotalCount,
OnlineCount: window.OnlineCount,
})
}
return ah
}

0 comments on commit 710b868

Please sign in to comment.