Merge pull request #5847 from hashicorp/f-5554-metrics-namespace-label
metrics: add namespace label to allocation metrics
This commit is contained in:
commit
3b8315f381
|
@ -2,6 +2,7 @@
|
|||
|
||||
IMPROVEMENTS:
|
||||
* api: use region from job hcl when not provided as query parameter in job registration and plan endpoints [[GH-5664](https://github.com/hashicorp/nomad/pull/5664)]
|
||||
* metrics: add namespace label as appropriate to metrics [[GH-5847](https://github.com/hashicorp/nomad/issues/5847)]
|
||||
|
||||
BUG FIXES:
|
||||
|
||||
|
|
|
@ -362,6 +362,10 @@ func (tr *TaskRunner) initLabels() {
|
|||
Name: "task",
|
||||
Value: tr.taskName,
|
||||
},
|
||||
{
|
||||
Name: "namespace",
|
||||
Value: tr.alloc.Namespace,
|
||||
},
|
||||
}
|
||||
|
||||
if tr.alloc.Job.ParentID != "" {
|
||||
|
|
|
@ -2021,3 +2021,34 @@ func testWaitForTaskToStart(t *testing.T, tr *TaskRunner) {
|
|||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
// TestTaskRunner_BaseLabels tests that the base labels for the task metrics
|
||||
// are set appropriately.
|
||||
func TestTaskRunner_BaseLabels(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
|
||||
alloc := mock.BatchAlloc()
|
||||
alloc.Namespace = "not-default"
|
||||
task := alloc.Job.TaskGroups[0].Tasks[0]
|
||||
task.Driver = "raw_exec"
|
||||
task.Config = map[string]interface{}{
|
||||
"command": "whoami",
|
||||
}
|
||||
|
||||
config, cleanup := testTaskRunnerConfig(t, alloc, task.Name)
|
||||
defer cleanup()
|
||||
|
||||
tr, err := NewTaskRunner(config)
|
||||
require.NoError(err)
|
||||
|
||||
labels := map[string]string{}
|
||||
for _, e := range tr.baseLabels {
|
||||
labels[e.Name] = e.Value
|
||||
}
|
||||
require.Equal(alloc.Job.Name, labels["job"])
|
||||
require.Equal(alloc.TaskGroup, labels["task_group"])
|
||||
require.Equal(task.Name, labels["task"])
|
||||
require.Equal(alloc.ID, labels["alloc_id"])
|
||||
require.Equal(alloc.Namespace, labels["namespace"])
|
||||
}
|
||||
|
|
|
@ -657,6 +657,10 @@ func (s *Server) iterateJobSummaryMetrics(summary *structs.JobSummary) {
|
|||
Name: "task_group",
|
||||
Value: name,
|
||||
},
|
||||
{
|
||||
Name: "namespace",
|
||||
Value: summary.Namespace,
|
||||
},
|
||||
}
|
||||
|
||||
if strings.Contains(summary.JobID, "/dispatch-") {
|
||||
|
|
Loading…
Reference in New Issue