diff --git a/client/allocrunner/taskrunner/task_runner.go b/client/allocrunner/taskrunner/task_runner.go index 2cbb0100845f..1c6c7ef84f91 100644 --- a/client/allocrunner/taskrunner/task_runner.go +++ b/client/allocrunner/taskrunner/task_runner.go @@ -291,6 +291,26 @@ func NewTaskRunner(logger *log.Logger, config *config.Config, }, } + if tc.alloc.Job.ParentID != "" { + tc.baseLabels = append(tc.baseLabels, metrics.Label{ + Name: "parent_id", + Value: tc.alloc.Job.ParentID, + }) + if strings.Contains(tc.alloc.Job.Name, "/dispatch-") { + tc.baseLabels = append(tc.baseLabels, metrics.Label{ + Name: "dispatch_id", + Value: strings.Split(tc.alloc.Job.Name, "/dispatch-")[1], + }) + } + if strings.Contains(tc.alloc.Job.Name, "/periodic-") { + tc.baseLabels = append(tc.baseLabels, metrics.Label{ + Name: "periodic_id", + Value: strings.Split(tc.alloc.Job.Name, "/periodic-")[1], + }) + } + return tc + } + return tc } diff --git a/nomad/leader.go b/nomad/leader.go index 119e72ebfdd0..9f64062d47a2 100644 --- a/nomad/leader.go +++ b/nomad/leader.go @@ -12,6 +12,8 @@ import ( "golang.org/x/time/rate" + "strings" + "github.com/armon/go-metrics" memdb "github.com/hashicorp/go-memdb" "github.com/hashicorp/go-version" @@ -625,6 +627,29 @@ func (s *Server) publishJobSummaryMetrics(stopCh chan struct{}) { Value: name, }, } + + if strings.Contains(summary.JobID, "/dispatch-") { + jobInfo := strings.Split(summary.JobID, "/dispatch-") + labels = append(labels, metrics.Label{ + Name: "parent_id", + Value: jobInfo[0], + }, metrics.Label{ + Name: "dispatch_id", + Value: jobInfo[1], + }) + } + + if strings.Contains(summary.JobID, "/periodic-") { + jobInfo := strings.Split(summary.JobID, "/periodic-") + labels = append(labels, metrics.Label{ + Name: "parent_id", + Value: jobInfo[0], + }, metrics.Label{ + Name: "periodic_id", + Value: jobInfo[1], + }) + } + metrics.SetGaugeWithLabels([]string{"nomad", "job_summary", "queued"}, float32(tgSummary.Queued), labels) metrics.SetGaugeWithLabels([]string{"nomad", "job_summary", "complete"},