-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Parametrized/periodic jobs per child tagged metric emmision #4392
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First check the length after splitting the string to ensure the length is as expected before assigning the second element. |
||
}) | ||
} | ||
return tc | ||
} | ||
|
||
return tc | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't assume that this array will have two elements, first check for safety. |
||
}) | ||
} | ||
|
||
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], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that the length of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this specific case, the contains check in line 642 guards against that. If the string ends with |
||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two points overall:
|
||
} | ||
|
||
metrics.SetGaugeWithLabels([]string{"nomad", "job_summary", "queued"}, | ||
float32(tgSummary.Queued), labels) | ||
metrics.SetGaugeWithLabels([]string{"nomad", "job_summary", "complete"}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See below comment. Consider pulling this into a helper function to reduce code duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the input, I wrote helper function hour ago and now I'm trying to figure where to place it =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, its probably fine to not introduce a helper method. This and the other place we do this, are in two different packages and we would have to put one helper method in a util package that both can import. Doesn't seem worth it this time..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That what's stopped me - 2 different packages without imports intersection.
Thanks @preetapan, and thanks @chelseakomlo for really usefull code review tips!