satellite,storagenode: Pass audit history over GetStats endpoint

Full prefix: satellite/{overlay,nodestats},storagenode/{reputation,nodestats}

Allow the storagenode to receive its audit history data from the
satellite via the satellite's GetStats endpoint.

The storagenode does not save this data for use in the API yet.

Change-Id: I9488f4d7a4ccb4ccf8336b8e4aeb3e5beee54979
This commit is contained in:
Moby von Briesen 2020-12-11 16:15:17 -05:00 committed by Maximillian von Briesen
parent 8b2e4bfa7e
commit edbee53888
6 changed files with 33 additions and 1 deletions

2
go.mod
View File

@ -42,7 +42,7 @@ require (
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
google.golang.org/api v0.20.0 // indirect
google.golang.org/protobuf v1.25.0 // indirect
storj.io/common v0.0.0-20201207172416-78f4e59925c3
storj.io/common v0.0.0-20201210184814-6206aefd1d48
storj.io/drpc v0.0.16
storj.io/monkit-jaeger v0.0.0-20200518165323-80778fc3f91b
storj.io/private v0.0.0-20201126162939-6fbb1e924f51

2
go.sum
View File

@ -785,6 +785,8 @@ storj.io/common v0.0.0-20200424175742-65ac59022f4f/go.mod h1:pZyXiIE7bGETIRXtfs0
storj.io/common v0.0.0-20201026135900-1aaeec90670b/go.mod h1:GqdmNf3fLm2UZX/7Zr0BLFCJ4gFjgm6eHrk/fnmr5jQ=
storj.io/common v0.0.0-20201207172416-78f4e59925c3 h1:D+rAQBzjl0Mw3VQ+1Sjv5/53I7JaIymMrkDW5DYBgRE=
storj.io/common v0.0.0-20201207172416-78f4e59925c3/go.mod h1:6sepaQTRLuygvA+GNPzdgRPOB1+wFfjde76KBWofbMY=
storj.io/common v0.0.0-20201210184814-6206aefd1d48 h1:bxIYHG96eFQNsEazsICfiEHjFwo1YqqbXkGfg72d2mg=
storj.io/common v0.0.0-20201210184814-6206aefd1d48/go.mod h1:6sepaQTRLuygvA+GNPzdgRPOB1+wFfjde76KBWofbMY=
storj.io/drpc v0.0.11/go.mod h1:TiFc2obNjL9/3isMW1Rpxjy8V9uE0B2HMeMFGiiI7Iw=
storj.io/drpc v0.0.14/go.mod h1:82nfl+6YwRwF6UG31cEWWUqv/FaKvP5SGqUvoqTxCMA=
storj.io/drpc v0.0.16 h1:9sxypc5lKi/0D69cR21BR0S21+IvXfON8L5nXMVNTwQ=

View File

@ -57,6 +57,12 @@ func (e *Endpoint) GetStats(ctx context.Context, req *pb.GetStatsRequest) (_ *pb
e.log.Error("overlay.Get failed", zap.Error(err))
return nil, rpcstatus.Error(rpcstatus.Internal, err.Error())
}
auditHistory, err := e.overlay.GetAuditHistory(ctx, peer.ID)
// if there is no audit history for the node, that's fine and we can continue with a nil auditHistory struct.
if err != nil && !overlay.ErrNodeNotFound.Has(err) {
e.log.Error("overlay.GetAuditHistory failed", zap.Error(err))
return nil, rpcstatus.Error(rpcstatus.Internal, err.Error())
}
auditScore := calculateReputationScore(
node.Reputation.AuditReputationAlpha,
@ -86,6 +92,7 @@ func (e *Endpoint) GetStats(ctx context.Context, req *pb.GetStatsRequest) (_ *pb
Suspended: node.UnknownAuditSuspended,
OfflineSuspended: node.OfflineSuspended,
OfflineUnderReview: node.OfflineUnderReview,
AuditHistory: overlay.AuditHistoryToPB(auditHistory),
JoinedAt: node.CreatedAt,
}, nil
}

View File

@ -7,6 +7,7 @@ import (
"context"
"time"
"storj.io/common/pb"
"storj.io/common/storj"
)
@ -52,3 +53,22 @@ func (service *Service) GetAuditHistory(ctx context.Context, nodeID storj.NodeID
return service.db.GetAuditHistory(ctx, nodeID)
}
// AuditHistoryToPB converts an overlay.AuditHistory to a pb.AuditHistory.
func AuditHistoryToPB(auditHistory *AuditHistory) (historyPB *pb.AuditHistory) {
if auditHistory == nil {
return nil
}
historyPB = &pb.AuditHistory{
Score: auditHistory.Score,
Windows: make([]*pb.AuditWindow, len(auditHistory.Windows)),
}
for i, window := range auditHistory.Windows {
historyPB.Windows[i] = &pb.AuditWindow{
TotalCount: window.TotalCount,
OnlineCount: window.OnlineCount,
WindowStart: window.WindowStart,
}
}
return historyPB
}

View File

@ -98,6 +98,7 @@ func (s *Service) GetReputationStats(ctx context.Context, satelliteID storj.Node
SuspendedAt: resp.GetSuspended(),
OfflineSuspendedAt: resp.GetOfflineSuspended(),
OfflineUnderReviewAt: resp.GetOfflineUnderReview(),
AuditHistory: resp.GetAuditHistory(),
UpdatedAt: time.Now(),
JoinedAt: resp.JoinedAt,
}, nil

View File

@ -7,6 +7,7 @@ import (
"context"
"time"
"storj.io/common/pb"
"storj.io/common/storj"
)
@ -34,6 +35,7 @@ type Stats struct {
SuspendedAt *time.Time
OfflineSuspendedAt *time.Time
OfflineUnderReviewAt *time.Time
AuditHistory *pb.AuditHistory
UpdatedAt time.Time
JoinedAt time.Time