Skip to content
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

monitoring: tweak search request duration metric to record success / failure #507

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
23 changes: 17 additions & 6 deletions shards/shards.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ var (
Name: "zoekt_search_failed_total",
Help: "The total number of search requests that failed",
})
metricSearchDuration = promauto.NewHistogram(prometheus.HistogramOpts{
Name: "zoekt_search_duration_seconds",
Help: "The duration a search request took in seconds",
Buckets: prometheus.DefBuckets, // DefBuckets good for service timings
})
metricSearchDuration = promauto.NewHistogramVec(
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious how prometheus handles changes to metric types. Maybe because they're both histograms, it's not really a change and now there will just be labels?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jtibshirani

In Prometheus' data model, time series are uniquely identified by their name (zoekt_search_duration_seconds) and any attached labels (success). In my interpretation, this means that adding a new label creates a new time series. When we write Grafana dasbhoards that query on zoekt_search_duration_seconds{success=true}, the old data points (from zoekt_search_duration_seconds observations that occurred before we added the success label ) won't be returned from the Prometheus server.

Does this answer your question?

Copy link
Member

Choose a reason for hiding this comment

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

Yep, thanks for the reference.

prometheus.HistogramOpts{
Name: "zoekt_search_duration_seconds",
Help: "The duration a search request took in seconds",
Buckets: prometheus.DefBuckets, // DefBuckets good for service timings
},
[]string{"success"}, // "true" or "false" depending on whether the search succeeded
)

// A Counter per Stat. Name should match field in zoekt.Stats.
metricSearchContentBytesLoadedTotal = promauto.NewCounter(prometheus.CounterOpts{
Expand Down Expand Up @@ -600,14 +603,22 @@ func streamSearch(ctx context.Context, proc *process, q query.Q, opts *zoekt.Sea
overallStart := time.Now()
metricSearchRunning.Inc()
defer func() {
duration := time.Since(overallStart).Seconds()

metricSearchRunning.Dec()
metricSearchDuration.Observe(time.Since(overallStart).Seconds())

successful := true
if err != nil {
successful = false

metricSearchFailedTotal.Inc()

tr.LazyPrintf("error: %v", err)
tr.SetError(err)
}

metricSearchDuration.WithLabelValues(strconv.FormatBool(successful)).Observe(duration)

tr.Finish()
}()

Expand Down