Skip to content

Commit

Permalink
Add witness ID label to distribute counter. (#141)
Browse files Browse the repository at this point in the history
* Add witness ID label to distribute counter.

* Address comments.

* Add label for checkpoint update success metric.
  • Loading branch information
jiggoha authored Apr 9, 2024
1 parent cdecb6f commit cdac6f1
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions cmd/internal/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,20 @@ import (
const maxSigs = 100

var (
counterCheckpointUpdateRequests = promauto.NewCounter(prometheus.CounterOpts{
Name: "distributor_update_checkpoint_request",
Help: "The total number of requests to update a checkpoint",
})
counterCheckpointUpdateSuccess = promauto.NewCounter(prometheus.CounterOpts{
Name: "distributor_update_checkpoint_success",
Help: "The total number of successful requests to update a checkpoint",
})

counterCheckpointUpdateRequests = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "distributor_update_checkpoint_request",
Help: "The total number of requests to update a checkpoint, partitioned by witness ID.",
},
[]string{"witness_id"},
)
counterCheckpointUpdateSuccess = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "distributor_update_checkpoint_success",
Help: "The total number of successful requests to update a checkpoint",
},
[]string{"witness_id"},
)
counterCheckpointGetNRequests = promauto.NewCounter(prometheus.CounterOpts{
Name: "distributor_get_checkpoint_n_request",
Help: "The total number of requests to GetCheckpointN",
Expand Down Expand Up @@ -162,8 +167,6 @@ func (d *Distributor) GetCheckpointWitness(ctx context.Context, logID, witID str
// by both the log and the witness specified, and be larger than any previous checkpoint distributed
// for this pair.
func (d *Distributor) Distribute(ctx context.Context, logID, witID string, nextRaw []byte) error {
counterCheckpointUpdateRequests.Inc()

l, ok := d.ls[logID]
if !ok {
return status.Errorf(codes.InvalidArgument, "unknown unknown log ID %q", logID)
Expand All @@ -172,6 +175,8 @@ func (d *Distributor) Distribute(ctx context.Context, logID, witID string, nextR
if !ok {
return status.Errorf(codes.InvalidArgument, "unknown witness ID %q", witID)
}
counterCheckpointUpdateRequests.WithLabelValues(witID).Inc()

newCP, _, n, err := log.ParseCheckpoint(nextRaw, l.Origin, l.Verifier, wv)
if err != nil {
return status.Errorf(codes.InvalidArgument, "failed to parse checkpoint: %v", err)
Expand Down Expand Up @@ -210,7 +215,7 @@ func (d *Distributor) Distribute(ctx context.Context, logID, witID string, nextR
return status.Errorf(codes.Internal, "old checkpoint for tree size %d had hash %x but new one has %x", newCP.Size, oldCP.Hash, newCP.Hash)
}
// Nothing to do; checkpoint is equivalent to the old one so avoid DB writes.
counterCheckpointUpdateSuccess.Inc()
counterCheckpointUpdateSuccess.WithLabelValues(witID).Inc()
return nil
}
}
Expand Down Expand Up @@ -293,7 +298,7 @@ func (d *Distributor) Distribute(ctx context.Context, logID, witID string, nextR
if err := tx.Commit(); err != nil {
return err
}
counterCheckpointUpdateSuccess.Inc()
counterCheckpointUpdateSuccess.WithLabelValues(witID).Inc()
return nil
}

Expand Down

0 comments on commit cdac6f1

Please sign in to comment.