metrics: move metrics to worker server

For simplicity, the collection of the job metrics
was carried out in the job queue. This was only
being done in the dbqueue and not in the fsqueue.
This pr refactors the metric collection and moves
the job metrics to the worker server, by adding a
wrapper function to enqueueing jobs so that the
metrics only have to be recorded in one place when
queueing a job.
This commit is contained in:
Gianluca Zuccarelli 2022-01-31 11:20:53 +00:00 committed by Tom Gundersen
parent bce12b7bea
commit 6c4caec022
2 changed files with 35 additions and 15 deletions

View file

@ -21,7 +21,6 @@ import (
logrus "github.com/sirupsen/logrus"
"github.com/osbuild/osbuild-composer/internal/jobqueue"
"github.com/osbuild/osbuild-composer/internal/prometheus"
)
const (
@ -183,7 +182,6 @@ func (q *DBJobQueue) Enqueue(jobType string, args interface{}, dependencies []uu
return uuid.Nil, fmt.Errorf("unable to commit database transaction: %v", err)
}
prometheus.EnqueueJobMetrics(jobType)
logrus.Infof("Enqueued job of type %s with ID %s(dependencies %v)", jobType, id, dependencies)
return id, nil
@ -234,8 +232,6 @@ func (q *DBJobQueue) Dequeue(ctx context.Context, jobTypes []string) (uuid.UUID,
}
}
prometheus.DequeueJobMetrics(*queued, *started, jobType)
// insert heartbeat
_, err = conn.Exec(ctx, sqlInsertHeartbeat, token, id)
if err != nil {
@ -287,7 +283,6 @@ func (q *DBJobQueue) DequeueByID(ctx context.Context, id uuid.UUID) (uuid.UUID,
}
logrus.Infof("Dequeued job of type %v with ID %s", jobType, id)
prometheus.DequeueJobMetrics(*queued, *started, jobType)
return token, dependencies, jobType, args, nil
}
@ -356,7 +351,6 @@ func (q *DBJobQueue) FinishJob(id uuid.UUID, result interface{}) error {
}
logrus.Infof("Finished job with ID %s", id)
prometheus.FinishJobMetrics(*started, *finished, canceled, jobType)
return nil
}
@ -379,7 +373,6 @@ func (q *DBJobQueue) CancelJob(id uuid.UUID) error {
}
logrus.Infof("Cancelled job with ID %s", id)
prometheus.CancelJobMetrics(*started, jobType)
return nil
}