Skip to content

Commit

Permalink
feat: add CreateJobCount and CreateJobSuccessCount metrics (#3588)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <gaius.qi@gmail.com>
  • Loading branch information
gaius-qi authored Oct 18, 2024
1 parent 030f337 commit 2793851
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions manager/handlers/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/gin-gonic/gin/binding"

"d7y.io/dragonfly/v2/internal/job"
"d7y.io/dragonfly/v2/manager/metrics"
_ "d7y.io/dragonfly/v2/manager/models" // nolint
"d7y.io/dragonfly/v2/manager/types"
)
Expand All @@ -45,6 +46,8 @@ func (h *Handlers) CreateJob(ctx *gin.Context) {
return
}

// Collect CreateJobCount metrics.
metrics.CreateJobCount.WithLabelValues(json.Type).Inc()
switch json.Type {
case job.PreheatJob:
var json types.CreatePreheatJobRequest
Expand Down
14 changes: 14 additions & 0 deletions manager/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ var (
Help: "Counter of the number of failed of searching scheduler cluster.",
}, []string{"version", "commit"})

CreateJobCount = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: types.MetricsNamespace,
Subsystem: types.ManagerMetricsName,
Name: "create_job_total",
Help: "Counter of the number of creating job.",
}, []string{"name"})

CreateJobSuccessCount = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: types.MetricsNamespace,
Subsystem: types.ManagerMetricsName,
Name: "create_job_success_total",
Help: "Counter of the number of succeeded of creating job.",
}, []string{"name"})

VersionGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: types.MetricsNamespace,
Subsystem: types.ManagerMetricsName,
Expand Down
4 changes: 4 additions & 0 deletions manager/service/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

logger "d7y.io/dragonfly/v2/internal/dflog"
internaljob "d7y.io/dragonfly/v2/internal/job"
"d7y.io/dragonfly/v2/manager/metrics"
"d7y.io/dragonfly/v2/manager/models"
"d7y.io/dragonfly/v2/manager/types"
"d7y.io/dragonfly/v2/pkg/retry"
Expand Down Expand Up @@ -311,6 +312,9 @@ func (s *service) pollingJob(ctx context.Context, name string, id uint, groupID

switch job.State {
case machineryv1tasks.StateSuccess:
// Collect CreateJobSuccessCount. metrics.
metrics.CreateJobSuccessCount.WithLabelValues(name).Inc()

log.Info("polling group succeeded")
return nil, true, nil
case machineryv1tasks.StateFailure:
Expand Down

0 comments on commit 2793851

Please sign in to comment.