Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add CreateJobCount and CreateJobSuccessCount metrics #3588

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading