Skip to content

Commit

Permalink
Parametrized/periodic jobs per child tagged metric emmision
Browse files Browse the repository at this point in the history
  • Loading branch information
burdandrei committed Jun 10, 2018
1 parent c17e0fc commit ff1b0d4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
29 changes: 25 additions & 4 deletions client/task_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,6 @@ func NewTaskRunner(logger *log.Logger, config *config.Config,
}

tc.baseLabels = []metrics.Label{
{
Name: "job",
Value: tc.alloc.Job.Name,
},
{
Name: "task_group",
Value: tc.alloc.TaskGroup,
Expand All @@ -288,6 +284,31 @@ func NewTaskRunner(logger *log.Logger, config *config.Config,
},
}

if tc.alloc.Job.ParentID != "" {
tc.baseLabels = append(tc.baseLabels, metrics.Label{
Name: "job",
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
}

tc.baseLabels = append(tc.baseLabels, metrics.Label{
Name: "job",
Value: tc.alloc.Job.Name,
})

return tc
}

Expand Down
31 changes: 27 additions & 4 deletions nomad/leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"},
Expand Down

0 comments on commit ff1b0d4

Please sign in to comment.