From 05d5523a157ae7a6707a77d267cc63040c37eed2 Mon Sep 17 00:00:00 2001 From: Andrei Burd Date: Thu, 7 Jun 2018 16:53:08 +0300 Subject: [PATCH] Parametrized/periodic jobs per child tagged metric emmision --- client/allocrunner/taskrunner/task_runner.go | 20 +++++++++++++ nomad/leader.go | 31 +++++++++++++++++--- 2 files changed, 47 insertions(+), 4 deletions(-) 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..aee63a192aab 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" @@ -616,15 +618,36 @@ func (s *Server) publishJobSummaryMetrics(stopCh chan struct{}) { for name, tgSummary := range summary.Summary { if !s.config.DisableTaggedMetrics { labels := []metrics.Label{ - { - Name: "job", - Value: summary.JobID, - }, { Name: "task_group", Value: name, }, } + + var metricJobId string + switch { + case strings.Contains(summary.JobID, "/dispatch-"): + jobInfo := strings.Split(summary.JobID, "/dispatch-") + labels = append(labels, metrics.Label{ + Name: "dispatch_id", + Value: jobInfo[1], + }) + metricJobId = jobInfo[0] + case strings.Contains(summary.JobID, "/periodic-"): + jobInfo := strings.Split(summary.JobID, "/periodic-") + labels = append(labels, metrics.Label{ + Name: "periodic_id", + Value: jobInfo[1], + }) + metricJobId = jobInfo[0] + default: + metricJobId = summary.JobID + } + labels = append(labels, metrics.Label{ + Name: "job", + Value: metricJobId, + }) + metrics.SetGaugeWithLabels([]string{"nomad", "job_summary", "queued"}, float32(tgSummary.Queued), labels) metrics.SetGaugeWithLabels([]string{"nomad", "job_summary", "complete"},