Commit 89078305 authored by Tomasz Maczukin's avatar Tomasz Maczukin

Label ci_runner_builds metric with runner short token

parent 1abf0c67
Pipeline #13670461 passed with stages
in 21 minutes and 47 seconds
......@@ -11,9 +11,15 @@ import (
"github.com/prometheus/client_golang/prometheus"
)
var numBuildsDesc = prometheus.NewDesc("ci_runner_builds", "The current number of running builds.", []string{"state", "stage", "executor_stage"}, nil)
var numBuildsDesc = prometheus.NewDesc(
"ci_runner_builds",
"The current number of running builds.",
[]string{"runner", "state", "stage", "executor_stage"},
nil,
)
type statePermutation struct {
runner string
buildState common.BuildRuntimeState
buildStage common.BuildStage
executorStage common.ExecutorStage
......@@ -21,6 +27,7 @@ type statePermutation struct {
func newStatePermutationFromBuild(build *common.Build) statePermutation {
return statePermutation{
runner: build.Runner.ShortDescription(),
buildState: build.CurrentState,
buildStage: build.CurrentStage,
executorStage: build.CurrentExecutorStage(),
......@@ -191,6 +198,7 @@ func (b *buildsHelper) Collect(ch chan<- prometheus.Metric) {
numBuildsDesc,
prometheus.GaugeValue,
float64(count),
state.runner,
string(state.buildState),
string(state.buildStage),
string(state.executorStage),
......
......@@ -12,12 +12,19 @@ import (
"gitlab.com/gitlab-org/gitlab-runner/common"
)
var fakeRunner = &common.RunnerConfig{
RunnerCredentials: common.RunnerCredentials{
Token: "a1b2c3d4e5f6",
},
}
func TestBuildsHelperCollect(t *testing.T) {
ch := make(chan prometheus.Metric, 50)
b := &buildsHelper{}
b.builds = append(b.builds, &common.Build{
CurrentState: common.BuildRunStatePending,
CurrentStage: common.BuildStagePrepare,
Runner: fakeRunner,
})
b.Collect(ch)
assert.Len(t, ch, 1)
......
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