Commit 880ec0a6 authored by Tomasz Maczukin's avatar Tomasz Maczukin

Add '/debug/jobs/list' endpoint that lists all handled jobs

parent dbda11d4
Pipeline #7852018 passed with stages
in 20 minutes and 20 seconds
package commands
import (
"fmt"
"net/http"
"strings"
"sync"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
......@@ -194,3 +197,19 @@ func (b *buildsHelper) Collect(ch chan<- prometheus.Metric) {
)
}
}
func (b *buildsHelper) ListJobsHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "text/plain")
var jobs []string
for _, job := range b.builds {
jobDescription := fmt.Sprintf(
"id=%d url=%s state=%s stage=%s executor_stage=%s",
job.ID, job.RepoCleanURL(),
job.CurrentState, job.CurrentStage, job.CurrentExecutorStage(),
)
jobs = append(jobs, jobDescription)
}
w.Write([]byte(strings.Join(jobs, "\n")))
}
......@@ -377,16 +377,31 @@ func (mr *RunCommand) serveMetrics() error {
return nil
}
func (mr *RunCommand) Run() {
if mr.metricsServerAddress() != "" {
if err := mr.serveMetrics(); err != nil {
log.Fatalln(err)
}
log.Infoln("Metrics server listening at", mr.metricsServerAddress())
} else {
func (mr *RunCommand) serveDebugData() error {
http.Handle("/debug/jobs/list", http.HandlerFunc(mr.buildsHelper.ListJobsHandler))
return nil
}
func (mr *RunCommand) setupMetricsAndDebugServer() {
if mr.metricsServerAddress() == "" {
log.Infoln("Metrics server disabled")
return
}
if err := mr.serveMetrics(); err != nil {
log.Fatalln(err)
}
if err := mr.serveDebugData(); err != nil {
log.Fatalln(err)
}
log.Infoln("Metrics server listening at", mr.metricsServerAddress())
}
func (mr *RunCommand) Run() {
mr.setupMetricsAndDebugServer()
runners := make(chan *common.RunnerConfig)
go mr.feedRunners(runners)
......
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