Skip to content

Commit

Permalink
Export a metric of total number of leaves fetched (#2023)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCutter authored Jan 9, 2020
1 parent 1c5fd2f commit e07600f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ tolerate 2 nodes being unavailable, instead of just 1).
A potential deadlock condition in the log sequencer when the process is
attempting to exit has been addressed.

#### Monitoring & Metrics
A count of the total number of individual leaves the logserver attempts to
fetch via the GetEntries.\* API methods has been added.

### Map Changes

The verifiable map is still experimental. APIs, such as SetLeaves, have been
Expand Down
8 changes: 8 additions & 0 deletions server/log_rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type TrillianLogRPCServer struct {
timeSource clock.TimeSource
leafCounter monitoring.Counter
proofIndexPercentiles monitoring.Histogram
fetchedLeaves monitoring.Counter
}

// NewTrillianLogRPCServer creates a new RPC server backed by a LogStorageProvider.
Expand All @@ -71,6 +72,10 @@ func NewTrillianLogRPCServer(registry extension.Registry, timeSource clock.TimeS
"Count of inclusion proof request index using percentage of current log size at the time",
monitoring.PercentileBuckets(1),
),
fetchedLeaves: mf.NewCounter(
"fetched_leaves",
"Count of individual leaves fetched through get-entries calls",
),
}
}

Expand Down Expand Up @@ -500,6 +505,7 @@ func (t *TrillianLogRPCServer) GetLeavesByIndex(ctx context.Context, req *trilli
}
defer t.closeAndLog(ctx, tree.TreeId, tx, "GetLeavesByIndex")

t.fetchedLeaves.Add(float64(len(req.LeafIndex)))
leaves, err := tx.GetLeavesByIndex(ctx, req.LeafIndex)
if err != nil {
return nil, err
Expand Down Expand Up @@ -553,6 +559,7 @@ func (t *TrillianLogRPCServer) GetLeavesByRange(ctx context.Context, req *trilli
r := &trillian.GetLeavesByRangeResponse{SignedLogRoot: slr}

if req.StartIndex < int64(root.TreeSize) {
t.fetchedLeaves.Add(float64(req.Count))
leaves, err := tx.GetLeavesByRange(ctx, req.StartIndex, req.Count)
if err != nil {
return nil, err
Expand Down Expand Up @@ -589,6 +596,7 @@ func (t *TrillianLogRPCServer) GetLeavesByHash(ctx context.Context, req *trillia
}
defer t.closeAndLog(ctx, tree.TreeId, tx, "GetLeavesByHash")

t.fetchedLeaves.Add(float64(len(req.LeafHash)))
leaves, err := tx.GetLeavesByHash(ctx, req.LeafHash, req.OrderBySequence)
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions server/log_rpc_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,10 @@ func TestGetLeavesByRange(t *testing.T) {
if got := rsp.Leaves; !cmp.Equal(got, test.want, cmp.Comparer(proto.Equal)) {
t.Errorf("GetLeavesByRange(%d, %+d)=%+v; want %+v", req.StartIndex, req.Count, got, test.want)
}

if gotCount, wantCount := server.fetchedLeaves.Value(), float64(test.count); gotCount != wantCount {
t.Errorf("GetLeavesByRange() incremented fetched count by %f, want %f", gotCount, wantCount)
}
}
}

Expand Down

0 comments on commit e07600f

Please sign in to comment.