Commit 8a685d21 authored by Kamil Trzciński's avatar Kamil Trzciński 🔴

Merge branch 'job-duration-histogram-metric' into 'master'

Add a job duration histogram metric

See merge request gitlab-org/gitlab-runner!1025
parents 87426abe 1705ce80
Pipeline #31012928 passed with stages
in 31 minutes and 28 seconds
......@@ -63,7 +63,8 @@ type buildsHelper struct {
builds []*common.Build
lock sync.Mutex
jobsTotal *prometheus.CounterVec
jobsTotal *prometheus.CounterVec
jobDurationHistogram *prometheus.HistogramVec
}
func (b *buildsHelper) getRunnerCounter(runner *common.RunnerConfig) *runnerCounter {
......@@ -194,12 +195,16 @@ func (b *buildsHelper) removeBuild(deleteBuild *common.Build) bool {
b.lock.Lock()
defer b.lock.Unlock()
b.jobDurationHistogram.WithLabelValues(deleteBuild.Runner.ShortDescription()).Observe(deleteBuild.Duration().Seconds())
for idx, build := range b.builds {
if build == deleteBuild {
b.builds = append(b.builds[0:idx], b.builds[idx+1:]...)
return true
}
}
return false
}
......@@ -245,6 +250,7 @@ func (b *buildsHelper) Describe(ch chan<- *prometheus.Desc) {
ch <- requestConcurrencyExceededDesc
b.jobsTotal.Describe(ch)
b.jobDurationHistogram.Describe(ch)
}
// Collect implements prometheus.Collector.
......@@ -280,6 +286,7 @@ func (b *buildsHelper) Collect(ch chan<- prometheus.Metric) {
}
b.jobsTotal.Collect(ch)
b.jobDurationHistogram.Collect(ch)
}
func (b *buildsHelper) ListJobsHandler(w http.ResponseWriter, r *http.Request) {
......@@ -347,5 +354,13 @@ func newBuildsHelper() buildsHelper {
},
[]string{"runner"},
),
jobDurationHistogram: prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "gitlab_runner_job_duration_seconds",
Help: "Histogram of job durations",
Buckets: []float64{30, 60, 300, 600, 1800, 3600, 7200, 10800, 18000, 36000},
},
[]string{"runner"},
),
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment