Skip to content

[usage] Add metrics for number of usage records #11797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions components/usage/pkg/controller/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (r *UsageAndBillingReconciler) Reconcile() (err error) {
}

sessions := usageResp.GetSessions()
reportSessionsRetrievedTotal(len(sessions))

_, err = r.billingClient.UpdateInvoices(ctx, &v1.UpdateInvoicesRequest{
StartTime: timestamppb.New(startOfCurrentMonth),
Expand Down
28 changes: 21 additions & 7 deletions components/usage/pkg/controller/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package controller

import (
"fmt"
"github.com/prometheus/client_golang/prometheus"
"time"
)
Expand All @@ -29,17 +30,26 @@ var (
Help: "Histogram of reconcile duration",
Buckets: prometheus.LinearBuckets(30, 30, 10), // every 30 secs, starting at 30secs
}, []string{"outcome"})

sessionsRetrievedTotal = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "usage_records_retrieved_total",
Help: "Number of usage records retrieved during usage collection run",
})
)

func RegisterMetrics(reg *prometheus.Registry) error {
err := reg.Register(reconcileStartedTotal)
if err != nil {
return err
metrics := []prometheus.Collector{
reconcileStartedTotal,
reconcileStartedDurationSeconds,
sessionsRetrievedTotal,
}

err = reg.Register(reconcileStartedDurationSeconds)
if err != nil {
return err
for _, metric := range metrics {
err := reg.Register(metric)
if err != nil {
return fmt.Errorf("failed to register metric: %w", err)
}
}

return nil
Expand All @@ -56,3 +66,7 @@ func reportUsageReconcileFinished(duration time.Duration, err error) {
}
reconcileStartedDurationSeconds.WithLabelValues(outcome).Observe(duration.Seconds())
}

func reportSessionsRetrievedTotal(count int) {
sessionsRetrievedTotal.Set(float64(count))
}