diff --git a/model/labelname.go b/model/labelname.go index 26c5342ae..b9bf32cc4 100644 --- a/model/labelname.go +++ b/model/labelname.go @@ -16,6 +16,9 @@ package model // The label name used to indicate the metric name of a timeseries. const MetricNameLabel = LabelName("name") +// The label name used to indicate the job from which a timeseries was scraped. +const JobLabel = LabelName("job") + // A LabelName is a key for a LabelSet or Metric. It has a value associated // therewith. type LabelName string diff --git a/retrieval/targetmanager.go b/retrieval/targetmanager.go index f4a24093a..9ca7bb180 100644 --- a/retrieval/targetmanager.go +++ b/retrieval/targetmanager.go @@ -89,7 +89,7 @@ func (m *targetManager) AddTargetsFromConfig(config *config.Config) { for _, job := range config.Jobs { for _, configTargets := range job.Targets { baseLabels := model.LabelSet{ - model.LabelName("job"): model.LabelValue(job.Name), + model.JobLabel: model.LabelValue(job.Name), } for label, value := range configTargets.Labels { baseLabels[label] = value diff --git a/rules/ast/functions.go b/rules/ast/functions.go index 4af4abcca..17d808ceb 100644 --- a/rules/ast/functions.go +++ b/rules/ast/functions.go @@ -167,7 +167,7 @@ func sampleVectorImpl(timestamp time.Time, view *viewAdapter, args []Node) inter model.Sample{ Metric: model.Metric{ model.MetricNameLabel: "http_requests", - "job": "api-server", + model.JobLabel: "api-server", "instance": "0", }, Value: 10, @@ -176,7 +176,7 @@ func sampleVectorImpl(timestamp time.Time, view *viewAdapter, args []Node) inter model.Sample{ Metric: model.Metric{ model.MetricNameLabel: "http_requests", - "job": "api-server", + model.JobLabel: "api-server", "instance": "1", }, Value: 20, @@ -185,7 +185,7 @@ func sampleVectorImpl(timestamp time.Time, view *viewAdapter, args []Node) inter model.Sample{ Metric: model.Metric{ model.MetricNameLabel: "http_requests", - "job": "api-server", + model.JobLabel: "api-server", "instance": "2", }, Value: 30, @@ -194,7 +194,7 @@ func sampleVectorImpl(timestamp time.Time, view *viewAdapter, args []Node) inter model.Sample{ Metric: model.Metric{ model.MetricNameLabel: "http_requests", - "job": "api-server", + model.JobLabel: "api-server", "instance": "3", "group": "canary", }, @@ -204,7 +204,7 @@ func sampleVectorImpl(timestamp time.Time, view *viewAdapter, args []Node) inter model.Sample{ Metric: model.Metric{ model.MetricNameLabel: "http_requests", - "job": "api-server", + model.JobLabel: "api-server", "instance": "2", "group": "canary", }, @@ -214,7 +214,7 @@ func sampleVectorImpl(timestamp time.Time, view *viewAdapter, args []Node) inter model.Sample{ Metric: model.Metric{ model.MetricNameLabel: "http_requests", - "job": "api-server", + model.JobLabel: "api-server", "instance": "3", "group": "mytest", }, @@ -224,7 +224,7 @@ func sampleVectorImpl(timestamp time.Time, view *viewAdapter, args []Node) inter model.Sample{ Metric: model.Metric{ model.MetricNameLabel: "http_requests", - "job": "api-server", + model.JobLabel: "api-server", "instance": "3", "group": "mytest", }, diff --git a/rules/testdata.go b/rules/testdata.go index 7a900bab0..1fb833814 100644 --- a/rules/testdata.go +++ b/rules/testdata.go @@ -71,7 +71,7 @@ var testMatrix = ast.Matrix{ { Metric: model.Metric{ model.MetricNameLabel: "http_requests", - "job": "api-server", + model.JobLabel: "api-server", "instance": "0", "group": "production", }, @@ -80,7 +80,7 @@ var testMatrix = ast.Matrix{ { Metric: model.Metric{ model.MetricNameLabel: "http_requests", - "job": "api-server", + model.JobLabel: "api-server", "instance": "1", "group": "production", }, @@ -89,7 +89,7 @@ var testMatrix = ast.Matrix{ { Metric: model.Metric{ model.MetricNameLabel: "http_requests", - "job": "api-server", + model.JobLabel: "api-server", "instance": "0", "group": "canary", }, @@ -98,7 +98,7 @@ var testMatrix = ast.Matrix{ { Metric: model.Metric{ model.MetricNameLabel: "http_requests", - "job": "api-server", + model.JobLabel: "api-server", "instance": "1", "group": "canary", }, @@ -107,7 +107,7 @@ var testMatrix = ast.Matrix{ { Metric: model.Metric{ model.MetricNameLabel: "http_requests", - "job": "app-server", + model.JobLabel: "app-server", "instance": "0", "group": "production", }, @@ -116,7 +116,7 @@ var testMatrix = ast.Matrix{ { Metric: model.Metric{ model.MetricNameLabel: "http_requests", - "job": "app-server", + model.JobLabel: "app-server", "instance": "1", "group": "production", }, @@ -125,7 +125,7 @@ var testMatrix = ast.Matrix{ { Metric: model.Metric{ model.MetricNameLabel: "http_requests", - "job": "app-server", + model.JobLabel: "app-server", "instance": "0", "group": "canary", }, @@ -134,7 +134,7 @@ var testMatrix = ast.Matrix{ { Metric: model.Metric{ model.MetricNameLabel: "http_requests", - "job": "app-server", + model.JobLabel: "app-server", "instance": "1", "group": "canary", }, diff --git a/web/api/targets.go b/web/api/targets.go index aa74ce9f3..687ebfbbd 100644 --- a/web/api/targets.go +++ b/web/api/targets.go @@ -34,7 +34,7 @@ func (serv MetricsService) SetTargets(targetGroups []TargetGroup, jobName string for _, targetGroup := range targetGroups { // Do mandatory map type conversion due to Go shortcomings. baseLabels := model.LabelSet{ - model.LabelName("job"): model.LabelValue(job.Name), + model.JobLabel: model.LabelValue(job.Name), } for label, value := range targetGroup.BaseLabels { baseLabels[model.LabelName(label)] = model.LabelValue(value)