Skip to content

Commit

Permalink
satellite,storagenode: Pass audit history over GetStats endpoint
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mobyvb committed Dec 30, 2020
1 parent 8b2e4bf commit edbee53
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
7 changes: 7 additions & 0 deletions satellite/nodestats/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down
20 changes: 20 additions & 0 deletions satellite/overlay/audithistory.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"time"

"storj.io/common/pb"
"storj.io/common/storj"
)

Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions storagenode/nodestats/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions storagenode/reputation/reputation.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"time"

"storj.io/common/pb"
"storj.io/common/storj"
)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit edbee53

Please sign in to comment.