Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/backend/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (s *Reporter) GetRange(ctx context.Context, startKey []byte, endKey []byte,

start := s.Clock().Now()
res, err := s.Backend.GetRange(ctx, startKey, endKey, limit)
batchReadLatencies.WithLabelValues(s.Component).Observe(time.Since(start).Seconds())
batchReadLatencies.WithLabelValues(s.Component).Observe(s.Clock().Since(start).Seconds())
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a time.Now/time.Since pair is also fine, but I expect the clock will raise less eyebrows.

batchReadRequests.WithLabelValues(s.Component).Inc()
if err != nil {
batchReadRequestsFailed.WithLabelValues(s.Component).Inc()
Expand All @@ -146,7 +146,7 @@ func (s *Reporter) Create(ctx context.Context, i Item) (*Lease, error) {

start := s.Clock().Now()
lease, err := s.Backend.Create(ctx, i)
writeLatencies.WithLabelValues(s.Component).Observe(time.Since(start).Seconds())
writeLatencies.WithLabelValues(s.Component).Observe(s.Clock().Since(start).Seconds())
writeRequests.WithLabelValues(s.Component).Inc()
if err != nil {
writeRequestsFailed.WithLabelValues(s.Component).Inc()
Expand All @@ -169,7 +169,7 @@ func (s *Reporter) Put(ctx context.Context, i Item) (*Lease, error) {

start := s.Clock().Now()
lease, err := s.Backend.Put(ctx, i)
writeLatencies.WithLabelValues(s.Component).Observe(time.Since(start).Seconds())
writeLatencies.WithLabelValues(s.Component).Observe(s.Clock().Since(start).Seconds())
writeRequests.WithLabelValues(s.Component).Inc()
if err != nil {
writeRequestsFailed.WithLabelValues(s.Component).Inc()
Expand All @@ -191,7 +191,7 @@ func (s *Reporter) Update(ctx context.Context, i Item) (*Lease, error) {

start := s.Clock().Now()
lease, err := s.Backend.Update(ctx, i)
writeLatencies.WithLabelValues(s.Component).Observe(time.Since(start).Seconds())
writeLatencies.WithLabelValues(s.Component).Observe(s.Clock().Since(start).Seconds())
writeRequests.WithLabelValues(s.Component).Inc()
if err != nil {
writeRequestsFailed.WithLabelValues(s.Component).Inc()
Expand All @@ -212,9 +212,9 @@ func (s *Reporter) Get(ctx context.Context, key []byte) (*Item, error) {
defer span.End()

start := s.Clock().Now()
readLatencies.WithLabelValues(s.Component).Observe(time.Since(start).Seconds())
readRequests.WithLabelValues(s.Component).Inc()
item, err := s.Backend.Get(ctx, key)
readLatencies.WithLabelValues(s.Component).Observe(s.Clock().Since(start).Seconds())
readRequests.WithLabelValues(s.Component).Inc()
if err != nil && !trace.IsNotFound(err) {
readRequestsFailed.WithLabelValues(s.Component).Inc()
}
Expand All @@ -236,7 +236,7 @@ func (s *Reporter) CompareAndSwap(ctx context.Context, expected Item, replaceWit

start := s.Clock().Now()
lease, err := s.Backend.CompareAndSwap(ctx, expected, replaceWith)
writeLatencies.WithLabelValues(s.Component).Observe(time.Since(start).Seconds())
writeLatencies.WithLabelValues(s.Component).Observe(s.Clock().Since(start).Seconds())
writeRequests.WithLabelValues(s.Component).Inc()
if err != nil && !trace.IsNotFound(err) && !trace.IsCompareFailed(err) {
writeRequestsFailed.WithLabelValues(s.Component).Inc()
Expand All @@ -258,7 +258,7 @@ func (s *Reporter) Delete(ctx context.Context, key []byte) error {

start := s.Clock().Now()
err := s.Backend.Delete(ctx, key)
writeLatencies.WithLabelValues(s.Component).Observe(time.Since(start).Seconds())
writeLatencies.WithLabelValues(s.Component).Observe(s.Clock().Since(start).Seconds())
writeRequests.WithLabelValues(s.Component).Inc()
if err != nil && !trace.IsNotFound(err) {
writeRequestsFailed.WithLabelValues(s.Component).Inc()
Expand All @@ -281,7 +281,7 @@ func (s *Reporter) DeleteRange(ctx context.Context, startKey []byte, endKey []by

start := s.Clock().Now()
err := s.Backend.DeleteRange(ctx, startKey, endKey)
batchWriteLatencies.WithLabelValues(s.Component).Observe(time.Since(start).Seconds())
batchWriteLatencies.WithLabelValues(s.Component).Observe(s.Clock().Since(start).Seconds())
batchWriteRequests.WithLabelValues(s.Component).Inc()
if err != nil && !trace.IsNotFound(err) {
batchWriteRequestsFailed.WithLabelValues(s.Component).Inc()
Expand All @@ -307,7 +307,7 @@ func (s *Reporter) KeepAlive(ctx context.Context, lease Lease, expires time.Time

start := s.Clock().Now()
err := s.Backend.KeepAlive(ctx, lease, expires)
writeLatencies.WithLabelValues(s.Component).Observe(time.Since(start).Seconds())
writeLatencies.WithLabelValues(s.Component).Observe(s.Clock().Since(start).Seconds())
writeRequests.WithLabelValues(s.Component).Inc()
if err != nil && !trace.IsNotFound(err) {
writeRequestsFailed.WithLabelValues(s.Component).Inc()
Expand Down