From e6a4441246fb650e244fc52807e418dd819c75f5 Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Wed, 21 Feb 2024 15:57:56 -0800 Subject: [PATCH] Add metrics for index insertion Add new summary vector metric `rekor_index_storage_latency_summary` to enable tracking latency of entry insertion in the mysql or redis index storage backend. Since the index insertion is non-blocking, the existing API metrics are unable to measure its latency. However, the speed of insertion affects how fast the index is available to query, so it is relevant to rekor's overall performance. This new metric along with the existing API metrics will help give an clearer picture of rekor's index storage performance. Signed-off-by: Colleen Murphy --- pkg/api/entries.go | 10 ++++++++++ pkg/api/metrics.go | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/pkg/api/entries.go b/pkg/api/entries.go index 4efba7ba3..c04df49cc 100644 --- a/pkg/api/entries.go +++ b/pkg/api/entries.go @@ -23,6 +23,8 @@ import ( "fmt" "net/http" "net/url" + "strconv" + "time" "github.com/cyberphone/json-canonicalization/go/src/webpki.org/jsoncanonicalizer" "github.com/go-openapi/runtime" @@ -246,6 +248,14 @@ func createLogEntry(params entries.CreateLogEntryParams) (models.LogEntry, middl if indexStorageClient != nil { go func() { + start := time.Now() + var err error + defer func() { + labels := map[string]string{ + "success": strconv.FormatBool(err == nil), + } + metricIndexStorageLatency.With(labels).Observe(float64(time.Since(start))) + }() keys, err := entry.IndexKeys() if err != nil { log.ContextLogger(ctx).Errorf("getting entry index keys: %v", err) diff --git a/pkg/api/metrics.go b/pkg/api/metrics.go index 64c91b493..56b97788b 100644 --- a/pkg/api/metrics.go +++ b/pkg/api/metrics.go @@ -34,6 +34,11 @@ var ( Help: "The status of publishing events to Pub/Sub", }, []string{"event", "content_type", "status"}) + metricIndexStorageLatency = promauto.NewSummaryVec(prometheus.SummaryOpts{ + Name: "rekor_index_storage_latency_summary", + Help: "Latency of backend index insertion by success/failure", + }, []string{"success"}) + MetricLatency = promauto.NewHistogramVec(prometheus.HistogramOpts{ Name: "rekor_api_latency", Help: "Api Latency on calls",