Browse Source

Constantize job name label.

pull/141/head
Julius Volz 12 years ago
parent
commit
a0d311c9e6
  1. 3
      model/labelname.go
  2. 2
      retrieval/targetmanager.go
  3. 14
      rules/ast/functions.go
  4. 16
      rules/testdata.go
  5. 2
      web/api/targets.go

3
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

2
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

14
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",
},

16
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",
},

2
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)

Loading…
Cancel
Save