From 55085a7b4473cffa7879e96599020b0ecb75ea0f Mon Sep 17 00:00:00 2001 From: ilyam8 Date: Thu, 8 Sep 2022 13:42:54 +0300 Subject: [PATCH] add collect job label to charts --- agent/module/job.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/agent/module/job.go b/agent/module/job.go index 1b6759cb7..8285b3a08 100644 --- a/agent/module/job.go +++ b/agent/module/job.go @@ -378,6 +378,7 @@ func (j *Job) createChart(chart *Chart) { if chart.ignore { return } + j.addJobNameLabel(chart) if chart.Priority == 0 { chart.Priority = j.priority @@ -483,6 +484,22 @@ func (j *Job) updateChart(chart *Chart, collected map[string]int64, sinceLastRun return chart.updated } +func (j Job) addJobNameLabel(chart *Chart) { + const lblKey = "_collect_job" + var ok bool + for _, lbl := range chart.Labels { + if ok = lbl.Key == lblKey; ok { + break + } + } + if !ok { + chart.Labels = append(chart.Labels, Label{ + Key: lblKey, + Value: j.Name(), + }) + } +} + func (j Job) penalty() int { v := j.retries / penaltyStep * penaltyStep * j.updateEvery / 2 if v > maxPenalty {