Skip to content

Commit bd24a86

Browse files
authored
Add metric tracking queued/skipped leaves (#3751)
1 parent f21fdad commit bd24a86

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

server/log_rpc_server.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ func (t *TrillianLogRPCServer) QueueLeaf(ctx context.Context, req *trillian.Queu
118118
if len(ret) != 1 {
119119
return nil, status.Errorf(codes.Internal, "unexpected count of leaves %d", len(ret))
120120
}
121+
122+
// Mirror the use of this counter in AddSequencedLeaves below.
123+
label := strconv.FormatInt(req.LogId, 10)
124+
if s := ret[0].Status; s == nil || s.Code == int32(codes.OK) {
125+
t.leafCounter.Inc(label, "inserted")
126+
} else {
127+
t.leafCounter.Inc(label, "skipped")
128+
}
129+
121130
return &trillian.QueueLeafResponse{QueuedLeaf: ret[0]}, nil
122131
}
123132

server/log_rpc_server_test.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import (
2727
"github.com/google/go-cmp/cmp"
2828
"github.com/google/trillian"
2929
"github.com/google/trillian/extension"
30+
"github.com/google/trillian/monitoring"
31+
"github.com/google/trillian/monitoring/testonly"
3032
"github.com/google/trillian/storage"
3133
stestonly "github.com/google/trillian/storage/testonly"
3234
"github.com/google/trillian/storage/tree"
@@ -322,11 +324,16 @@ func TestQueueLeaf(t *testing.T) {
322324
mockStorage.EXPECT().QueueLeaves(gomock.Any(), cmpMatcher{tree1}, cmpMatcher{[]*trillian.LogLeaf{leaf1}}, fakeTime).After(c1).Return([]*trillian.QueuedLogLeaf{dupeQueuedLeaf(leaf1)}, nil)
323325

324326
registry := extension.Registry{
325-
AdminStorage: fakeAdminStorage(ctrl, storageParams{treeID: queueRequest0.LogId, numSnapshots: 2}),
326-
LogStorage: mockStorage,
327+
AdminStorage: fakeAdminStorage(ctrl, storageParams{treeID: queueRequest0.LogId, numSnapshots: 2}),
328+
LogStorage: mockStorage,
329+
MetricFactory: &monitoring.InertMetricFactory{},
327330
}
328331
server := NewTrillianLogRPCServer(registry, fakeTimeSource)
329332

333+
logIDLabel := strconv.FormatInt(queueRequest0.LogId, 10)
334+
leafCounterInsertedBase := testonly.NewCounterSnapshot(server.leafCounter, logIDLabel, "inserted")
335+
leafCounterSkippedBase := testonly.NewCounterSnapshot(server.leafCounter, logIDLabel, "skipped")
336+
330337
rsp, err := server.QueueLeaf(ctx, &queueRequest0)
331338
if err != nil {
332339
t.Fatalf("Failed to queue leaf: %v", err)
@@ -341,6 +348,12 @@ func TestQueueLeaf(t *testing.T) {
341348
diff := cmp.Diff(queueRequest0.Leaf, rsp.QueuedLeaf.Leaf)
342349
t.Errorf("post-QueueLeaf() diff:\n%v", diff)
343350
}
351+
if d := leafCounterInsertedBase.Delta(); d != 1.0 {
352+
t.Errorf("%f leaves added, want 1 leaf added", d)
353+
}
354+
if d := leafCounterSkippedBase.Delta(); d != 0.0 {
355+
t.Errorf("%f leaves skipped, want 0 leaves added", d)
356+
}
344357

345358
// Repeating the operation gives ALREADY_EXISTS.
346359
rsp, err = server.QueueLeaf(ctx, &queueRequest0)
@@ -361,6 +374,13 @@ func TestQueueLeaf(t *testing.T) {
361374
diff := cmp.Diff(queueRequest0.Leaf, rsp.QueuedLeaf.Leaf)
362375
t.Errorf("post-QueueLeaf() diff:\n%v", diff)
363376
}
377+
if d := leafCounterInsertedBase.Delta(); d != 1.0 {
378+
t.Errorf("%f leaves added, want 1 leaf added", d)
379+
}
380+
if d := leafCounterSkippedBase.Delta(); d != 1.0 {
381+
t.Errorf("%f leaves skipped, want 1 leaves added", d)
382+
}
383+
364384
}
365385

366386
func TestAddSequencedLeavesStorageError(t *testing.T) {

0 commit comments

Comments
 (0)