Skip to content

Commit

Permalink
metrics: add fetchTicketLatency
Browse files Browse the repository at this point in the history
  • Loading branch information
castaneai committed Dec 25, 2023
1 parent 8a53ee3 commit df0698a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@ func (b *Backend) Tick(ctx context.Context) error {
}

func (b *Backend) fetchActiveTickets(ctx context.Context) ([]*pb.Ticket, error) {
start := time.Now()
tickets, err := b.store.GetActiveTickets(ctx, b.options.fetchTicketsLimit)
if err != nil {
return nil, fmt.Errorf("failed to fetch active tickets: %w", err)
}
b.metrics.recordFetchTicketsLatency(ctx, time.Since(start))
b.metrics.recordTicketsFetched(ctx, int64(len(tickets)))
return tickets, nil
}
Expand Down
12 changes: 12 additions & 0 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type backendMetrics struct {
meter metric.Meter
ticketsFetched metric.Int64Counter
ticketsAssigned metric.Int64Counter
fetchTicketsLatency metric.Float64Histogram
matchFunctionLatency metric.Float64Histogram
assignerLatency metric.Float64Histogram
}
Expand All @@ -38,6 +39,12 @@ func newBackendMetrics(provider metric.MeterProvider) (*backendMetrics, error) {
if err != nil {
return nil, err
}
fetchTicketsLatency, err := meter.Float64Histogram("minimatch.backend.fetch_tickets_latency",
metric.WithUnit("s"),
metric.WithExplicitBucketBoundaries(defaultHistogramBuckets...))
if err != nil {
return nil, err
}
matchFunctionLatency, err := meter.Float64Histogram("minimatch.backend.match_function_latency",
metric.WithUnit("s"),
metric.WithExplicitBucketBoundaries(defaultHistogramBuckets...))
Expand All @@ -54,6 +61,7 @@ func newBackendMetrics(provider metric.MeterProvider) (*backendMetrics, error) {
meter: meter,
ticketsFetched: ticketsFetched,
ticketsAssigned: ticketsAssigned,
fetchTicketsLatency: fetchTicketsLatency,
matchFunctionLatency: matchFunctionLatency,
assignerLatency: assignerLatency,
}, nil
Expand All @@ -75,6 +83,10 @@ func (m *backendMetrics) recordTicketsAssigned(ctx context.Context, asgs []*pb.A
m.ticketsAssigned.Add(ctx, ticketsAssigned)
}

func (m *backendMetrics) recordFetchTicketsLatency(ctx context.Context, latency time.Duration) {
m.fetchTicketsLatency.Record(ctx, latency.Seconds())
}

type matchFunctionWithMetrics struct {
mmf MatchFunction
metrics *backendMetrics
Expand Down

0 comments on commit df0698a

Please sign in to comment.