Merge pull request #99 from prometheus/julius-constantize-name

Constantize metric name label name.
This commit is contained in:
Matt T. Proud 2013-03-26 08:33:23 -07:00
commit 00009e4ad1
15 changed files with 132 additions and 127 deletions

View file

@ -13,6 +13,9 @@
package model package model
// The label name used to indicate the metric name of a timeseries.
const MetricNameLabel = LabelName("name")
// A LabelName is a key for a LabelSet or Metric. It has a value associated // A LabelName is a key for a LabelSet or Metric. It has a value associated
// therewith. // therewith.
type LabelName string type LabelName string

View file

@ -37,125 +37,125 @@ func testProcessor001Process(t test.Tester) {
out: []Result{ out: []Result{
{ {
Sample: model.Sample{ Sample: model.Sample{
Metric: model.Metric{"service": "zed", "name": "rpc_calls_total"}, Metric: model.Metric{"service": "zed", model.MetricNameLabel: "rpc_calls_total"},
Value: 25, Value: 25,
}, },
}, },
{ {
Sample: model.Sample{ Sample: model.Sample{
Metric: model.Metric{"service": "bar", "name": "rpc_calls_total"}, Metric: model.Metric{"service": "bar", model.MetricNameLabel: "rpc_calls_total"},
Value: 25, Value: 25,
}, },
}, },
{ {
Sample: model.Sample{ Sample: model.Sample{
Metric: model.Metric{"service": "foo", "name": "rpc_calls_total"}, Metric: model.Metric{"service": "foo", model.MetricNameLabel: "rpc_calls_total"},
Value: 25, Value: 25,
}, },
}, },
{ {
Sample: model.Sample{ Sample: model.Sample{
Metric: model.Metric{"percentile": "0.010000", "name": "rpc_latency_microseconds", "service": "zed"}, Metric: model.Metric{"percentile": "0.010000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "zed"},
Value: 0.04598141, Value: 0.04598141,
}, },
}, },
{ {
Sample: model.Sample{ Sample: model.Sample{
Metric: model.Metric{"percentile": "0.010000", "name": "rpc_latency_microseconds", "service": "bar"}, Metric: model.Metric{"percentile": "0.010000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "bar"},
Value: 78.485634, Value: 78.485634,
}, },
}, },
{ {
Sample: model.Sample{ Sample: model.Sample{
Metric: model.Metric{"percentile": "0.010000", "name": "rpc_latency_microseconds", "service": "foo"}, Metric: model.Metric{"percentile": "0.010000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "foo"},
Value: 15.890724674774395, Value: 15.890724674774395,
}, },
}, },
{ {
Sample: model.Sample{ Sample: model.Sample{
Metric: model.Metric{"percentile": "0.050000", "name": "rpc_latency_microseconds", "service": "zed"}, Metric: model.Metric{"percentile": "0.050000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "zed"},
Value: 0.04598141, Value: 0.04598141,
}, },
}, },
{ {
Sample: model.Sample{ Sample: model.Sample{
Metric: model.Metric{"percentile": "0.050000", "name": "rpc_latency_microseconds", "service": "bar"}, Metric: model.Metric{"percentile": "0.050000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "bar"},
Value: 78.485634, Value: 78.485634,
}, },
}, },
{ {
Sample: model.Sample{ Sample: model.Sample{
Metric: model.Metric{"percentile": "0.050000", "name": "rpc_latency_microseconds", "service": "foo"}, Metric: model.Metric{"percentile": "0.050000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "foo"},
Value: 15.890724674774395, Value: 15.890724674774395,
}, },
}, },
{ {
Sample: model.Sample{ Sample: model.Sample{
Metric: model.Metric{"percentile": "0.500000", "name": "rpc_latency_microseconds", "service": "zed"}, Metric: model.Metric{"percentile": "0.500000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "zed"},
Value: 0.61204565, Value: 0.61204565,
}, },
}, },
{ {
Sample: model.Sample{ Sample: model.Sample{
Metric: model.Metric{"percentile": "0.500000", "name": "rpc_latency_microseconds", "service": "bar"}, Metric: model.Metric{"percentile": "0.500000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "bar"},
Value: 97.317986, Value: 97.317986,
}, },
}, },
{ {
Sample: model.Sample{ Sample: model.Sample{
Metric: model.Metric{"percentile": "0.500000", "name": "rpc_latency_microseconds", "service": "foo"}, Metric: model.Metric{"percentile": "0.500000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "foo"},
Value: 84.63044, Value: 84.63044,
}, },
}, },
{ {
Sample: model.Sample{ Sample: model.Sample{
Metric: model.Metric{"percentile": "0.900000", "name": "rpc_latency_microseconds", "service": "zed"}, Metric: model.Metric{"percentile": "0.900000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "zed"},
Value: 1.3559151, Value: 1.3559151,
}, },
}, },
{ {
Sample: model.Sample{ Sample: model.Sample{
Metric: model.Metric{"percentile": "0.900000", "name": "rpc_latency_microseconds", "service": "bar"}, Metric: model.Metric{"percentile": "0.900000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "bar"},
Value: 109.89202, Value: 109.89202,
}, },
}, },
{ {
Sample: model.Sample{ Sample: model.Sample{
Metric: model.Metric{"percentile": "0.900000", "name": "rpc_latency_microseconds", "service": "foo"}, Metric: model.Metric{"percentile": "0.900000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "foo"},
Value: 160.21101, Value: 160.21101,
}, },
}, },
{ {
Sample: model.Sample{ Sample: model.Sample{
Metric: model.Metric{"percentile": "0.990000", "name": "rpc_latency_microseconds", "service": "zed"}, Metric: model.Metric{"percentile": "0.990000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "zed"},
Value: 1.7727332, Value: 1.7727332,
}, },
}, },
{ {
Sample: model.Sample{ Sample: model.Sample{
Metric: model.Metric{"percentile": "0.990000", "name": "rpc_latency_microseconds", "service": "bar"}, Metric: model.Metric{"percentile": "0.990000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "bar"},
Value: 109.99626, Value: 109.99626,
}, },
}, },
{ {
Sample: model.Sample{ Sample: model.Sample{
Metric: model.Metric{"percentile": "0.990000", "name": "rpc_latency_microseconds", "service": "foo"}, Metric: model.Metric{"percentile": "0.990000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "foo"},
Value: 172.49829, Value: 172.49829,
}, },
}, },

View file

@ -503,7 +503,7 @@ func labelsEqual(labels1, labels2 model.Metric) bool {
return false return false
} }
for label, value := range labels1 { for label, value := range labels1 {
if labels2[label] != value && label != "name" { if labels2[label] != value && label != model.MetricNameLabel {
return false return false
} }
} }

View file

@ -128,67 +128,67 @@ func sampleVectorImpl(timestamp *time.Time, view *viewAdapter, args []Node) inte
return Vector{ return Vector{
&model.Sample{ &model.Sample{
Metric: model.Metric{ Metric: model.Metric{
"name": "http_requests", model.MetricNameLabel: "http_requests",
"job": "api-server", "job": "api-server",
"instance": "0", "instance": "0",
}, },
Value: 10, Value: 10,
Timestamp: *timestamp, Timestamp: *timestamp,
}, },
&model.Sample{ &model.Sample{
Metric: model.Metric{ Metric: model.Metric{
"name": "http_requests", model.MetricNameLabel: "http_requests",
"job": "api-server", "job": "api-server",
"instance": "1", "instance": "1",
}, },
Value: 20, Value: 20,
Timestamp: *timestamp, Timestamp: *timestamp,
}, },
&model.Sample{ &model.Sample{
Metric: model.Metric{ Metric: model.Metric{
"name": "http_requests", model.MetricNameLabel: "http_requests",
"job": "api-server", "job": "api-server",
"instance": "2", "instance": "2",
}, },
Value: 30, Value: 30,
Timestamp: *timestamp, Timestamp: *timestamp,
}, },
&model.Sample{ &model.Sample{
Metric: model.Metric{ Metric: model.Metric{
"name": "http_requests", model.MetricNameLabel: "http_requests",
"job": "api-server", "job": "api-server",
"instance": "3", "instance": "3",
"group": "canary", "group": "canary",
}, },
Value: 40, Value: 40,
Timestamp: *timestamp, Timestamp: *timestamp,
}, },
&model.Sample{ &model.Sample{
Metric: model.Metric{ Metric: model.Metric{
"name": "http_requests", model.MetricNameLabel: "http_requests",
"job": "api-server", "job": "api-server",
"instance": "2", "instance": "2",
"group": "canary", "group": "canary",
}, },
Value: 40, Value: 40,
Timestamp: *timestamp, Timestamp: *timestamp,
}, },
&model.Sample{ &model.Sample{
Metric: model.Metric{ Metric: model.Metric{
"name": "http_requests", model.MetricNameLabel: "http_requests",
"job": "api-server", "job": "api-server",
"instance": "3", "instance": "3",
"group": "mytest", "group": "mytest",
}, },
Value: 40, Value: 40,
Timestamp: *timestamp, Timestamp: *timestamp,
}, },
&model.Sample{ &model.Sample{
Metric: model.Metric{ Metric: model.Metric{
"name": "http_requests", model.MetricNameLabel: "http_requests",
"job": "api-server", "job": "api-server",
"instance": "3", "instance": "3",
"group": "mytest", "group": "mytest",
}, },
Value: 40, Value: 40,
Timestamp: *timestamp, Timestamp: *timestamp,

View file

@ -16,6 +16,7 @@ package ast
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/prometheus/prometheus/model"
"github.com/prometheus/prometheus/utility" "github.com/prometheus/prometheus/utility"
"sort" "sort"
"strings" "strings"
@ -69,13 +70,13 @@ func exprTypeToString(exprType ExprType) string {
func (vector Vector) String() string { func (vector Vector) String() string {
metricStrings := []string{} metricStrings := []string{}
for _, sample := range vector { for _, sample := range vector {
metricName, ok := sample.Metric["name"] metricName, ok := sample.Metric[model.MetricNameLabel]
if !ok { if !ok {
panic("Tried to print vector without metric name") panic("Tried to print vector without metric name")
} }
labelStrings := []string{} labelStrings := []string{}
for label, value := range sample.Metric { for label, value := range sample.Metric {
if label != "name" { if label != model.MetricNameLabel {
// TODO escape special chars in label values here and elsewhere. // TODO escape special chars in label values here and elsewhere.
labelStrings = append(labelStrings, fmt.Sprintf("%v='%v'", label, value)) labelStrings = append(labelStrings, fmt.Sprintf("%v='%v'", label, value))
} }
@ -94,13 +95,13 @@ func (vector Vector) String() string {
func (matrix Matrix) String() string { func (matrix Matrix) String() string {
metricStrings := []string{} metricStrings := []string{}
for _, sampleSet := range matrix { for _, sampleSet := range matrix {
metricName, ok := sampleSet.Metric["name"] metricName, ok := sampleSet.Metric[model.MetricNameLabel]
if !ok { if !ok {
panic("Tried to print matrix without metric name") panic("Tried to print matrix without metric name")
} }
labelStrings := []string{} labelStrings := []string{}
for label, value := range sampleSet.Metric { for label, value := range sampleSet.Metric {
if label != "name" { if label != model.MetricNameLabel {
labelStrings = append(labelStrings, fmt.Sprintf("%v='%v'", label, value)) labelStrings = append(labelStrings, fmt.Sprintf("%v='%v'", label, value))
} }
} }
@ -195,13 +196,13 @@ func EvalToString(node Node, timestamp *time.Time, format OutputFormat) string {
} }
func (node *VectorLiteral) String() string { func (node *VectorLiteral) String() string {
metricName, ok := node.labels["name"] metricName, ok := node.labels[model.MetricNameLabel]
if !ok { if !ok {
panic("Tried to print vector without metric name") panic("Tried to print vector without metric name")
} }
labelStrings := []string{} labelStrings := []string{}
for label, value := range node.labels { for label, value := range node.labels {
if label != "name" { if label != model.MetricNameLabel {
labelStrings = append(labelStrings, fmt.Sprintf("%v='%v'", label, value)) labelStrings = append(labelStrings, fmt.Sprintf("%v='%v'", label, value))
} }
} }

View file

@ -100,7 +100,7 @@ label_assign : IDENTIFIER '=' STRING
rule_expr : '(' rule_expr ')' rule_expr : '(' rule_expr ')'
{ $$ = $2 } { $$ = $2 }
| IDENTIFIER rule_labels | IDENTIFIER rule_labels
{ $2["name"] = model.LabelValue($1); $$ = ast.NewVectorLiteral($2) } { $2[model.MetricNameLabel] = model.LabelValue($1); $$ = ast.NewVectorLiteral($2) }
| IDENTIFIER '(' func_arg_list ')' | IDENTIFIER '(' func_arg_list ')'
{ {
var err error var err error

View file

@ -419,7 +419,7 @@ yydefault:
{ yyVAL.ruleNode = yyS[yypt-1].ruleNode } { yyVAL.ruleNode = yyS[yypt-1].ruleNode }
case 16: case 16:
//line parser.y:103 //line parser.y:103
{ yyS[yypt-0].labelSet["name"] = model.LabelValue(yyS[yypt-1].str); yyVAL.ruleNode = ast.NewVectorLiteral(yyS[yypt-0].labelSet) } { yyS[yypt-0].labelSet[model.MetricNameLabel] = model.LabelValue(yyS[yypt-1].str); yyVAL.ruleNode = ast.NewVectorLiteral(yyS[yypt-0].labelSet) }
case 17: case 17:
//line parser.y:105 //line parser.y:105
{ {

View file

@ -40,7 +40,7 @@ func (rule *Rule) Eval(timestamp *time.Time) ast.Vector {
// Override the metric name and labels. // Override the metric name and labels.
for _, sample := range vector { for _, sample := range vector {
sample.Metric["name"] = model.LabelValue(rule.name) sample.Metric[model.MetricNameLabel] = model.LabelValue(rule.name)
for label, value := range rule.labels { for label, value := range rule.labels {
if value == "" { if value == "" {
delete(sample.Metric, label) delete(sample.Metric, label)

View file

@ -70,73 +70,73 @@ func storeMatrix(storage metric.Storage, matrix ast.Matrix) error {
var testMatrix = ast.Matrix{ var testMatrix = ast.Matrix{
{ {
Metric: model.Metric{ Metric: model.Metric{
"name": "http_requests", model.MetricNameLabel: "http_requests",
"job": "api-server", "job": "api-server",
"instance": "0", "instance": "0",
"group": "production", "group": "production",
}, },
Values: getTestValueStream(0, 100, 10), Values: getTestValueStream(0, 100, 10),
}, },
{ {
Metric: model.Metric{ Metric: model.Metric{
"name": "http_requests", model.MetricNameLabel: "http_requests",
"job": "api-server", "job": "api-server",
"instance": "1", "instance": "1",
"group": "production", "group": "production",
}, },
Values: getTestValueStream(0, 200, 20), Values: getTestValueStream(0, 200, 20),
}, },
{ {
Metric: model.Metric{ Metric: model.Metric{
"name": "http_requests", model.MetricNameLabel: "http_requests",
"job": "api-server", "job": "api-server",
"instance": "0", "instance": "0",
"group": "canary", "group": "canary",
}, },
Values: getTestValueStream(0, 300, 30), Values: getTestValueStream(0, 300, 30),
}, },
{ {
Metric: model.Metric{ Metric: model.Metric{
"name": "http_requests", model.MetricNameLabel: "http_requests",
"job": "api-server", "job": "api-server",
"instance": "1", "instance": "1",
"group": "canary", "group": "canary",
}, },
Values: getTestValueStream(0, 400, 40), Values: getTestValueStream(0, 400, 40),
}, },
{ {
Metric: model.Metric{ Metric: model.Metric{
"name": "http_requests", model.MetricNameLabel: "http_requests",
"job": "app-server", "job": "app-server",
"instance": "0", "instance": "0",
"group": "production", "group": "production",
}, },
Values: getTestValueStream(0, 500, 50), Values: getTestValueStream(0, 500, 50),
}, },
{ {
Metric: model.Metric{ Metric: model.Metric{
"name": "http_requests", model.MetricNameLabel: "http_requests",
"job": "app-server", "job": "app-server",
"instance": "1", "instance": "1",
"group": "production", "group": "production",
}, },
Values: getTestValueStream(0, 600, 60), Values: getTestValueStream(0, 600, 60),
}, },
{ {
Metric: model.Metric{ Metric: model.Metric{
"name": "http_requests", model.MetricNameLabel: "http_requests",
"job": "app-server", "job": "app-server",
"instance": "0", "instance": "0",
"group": "canary", "group": "canary",
}, },
Values: getTestValueStream(0, 700, 70), Values: getTestValueStream(0, 700, 70),
}, },
{ {
Metric: model.Metric{ Metric: model.Metric{
"name": "http_requests", model.MetricNameLabel: "http_requests",
"job": "app-server", "job": "app-server",
"instance": "1", "instance": "1",
"group": "canary", "group": "canary",
}, },
Values: getTestValueStream(0, 800, 80), Values: getTestValueStream(0, 800, 80),
}, },

View file

@ -25,8 +25,8 @@ func GetFingerprintsForLabelSetTests(p MetricPersistence, t test.Tester) {
Value: 0, Value: 0,
Timestamp: time.Time{}, Timestamp: time.Time{},
Metric: model.Metric{ Metric: model.Metric{
"name": "my_metric", model.MetricNameLabel: "my_metric",
"request_type": "your_mom", "request_type": "your_mom",
}, },
}, t) }, t)
@ -34,13 +34,13 @@ func GetFingerprintsForLabelSetTests(p MetricPersistence, t test.Tester) {
Value: 0, Value: 0,
Timestamp: time.Time{}, Timestamp: time.Time{},
Metric: model.Metric{ Metric: model.Metric{
"name": "my_metric", model.MetricNameLabel: "my_metric",
"request_type": "your_dad", "request_type": "your_dad",
}, },
}, t) }, t)
result, err := p.GetFingerprintsForLabelSet(model.LabelSet{ result, err := p.GetFingerprintsForLabelSet(model.LabelSet{
model.LabelName("name"): model.LabelValue("my_metric"), model.MetricNameLabel: model.LabelValue("my_metric"),
}) })
if err != nil { if err != nil {
@ -81,9 +81,9 @@ func GetFingerprintsForLabelNameTests(p MetricPersistence, t test.Tester) {
Value: 0, Value: 0,
Timestamp: time.Time{}, Timestamp: time.Time{},
Metric: model.Metric{ Metric: model.Metric{
"name": "my_metric", model.MetricNameLabel: "my_metric",
"request_type": "your_mom", "request_type": "your_mom",
"language": "english", "language": "english",
}, },
}, t) }, t)
@ -91,13 +91,13 @@ func GetFingerprintsForLabelNameTests(p MetricPersistence, t test.Tester) {
Value: 0, Value: 0,
Timestamp: time.Time{}, Timestamp: time.Time{},
Metric: model.Metric{ Metric: model.Metric{
"name": "my_metric", model.MetricNameLabel: "my_metric",
"request_type": "your_dad", "request_type": "your_dad",
"sprache": "deutsch", "sprache": "deutsch",
}, },
}, t) }, t)
b := model.LabelName("name") b := model.MetricNameLabel
result, err := p.GetFingerprintsForLabelName(b) result, err := p.GetFingerprintsForLabelName(b)
if err != nil { if err != nil {
@ -230,9 +230,9 @@ func GetMetricForFingerprintTests(p MetricPersistence, t test.Tester) {
func AppendRepeatingValuesTests(p MetricPersistence, t test.Tester) { func AppendRepeatingValuesTests(p MetricPersistence, t test.Tester) {
metric := model.Metric{ metric := model.Metric{
"controller": "foo", model.MetricNameLabel: "errors_total",
"name": "errors_total", "controller": "foo",
"operation": "bar", "operation": "bar",
} }
increments := 10 increments := 10
@ -255,9 +255,9 @@ func AppendRepeatingValuesTests(p MetricPersistence, t test.Tester) {
} }
labelSet := model.LabelSet{ labelSet := model.LabelSet{
"controller": "foo", model.MetricNameLabel: "errors_total",
"name": "errors_total", "controller": "foo",
"operation": "bar", "operation": "bar",
} }
for i := 0; i < increments; i++ { for i := 0; i < increments; i++ {
@ -290,9 +290,9 @@ func AppendRepeatingValuesTests(p MetricPersistence, t test.Tester) {
func AppendsRepeatingValuesTests(p MetricPersistence, t test.Tester) { func AppendsRepeatingValuesTests(p MetricPersistence, t test.Tester) {
metric := model.Metric{ metric := model.Metric{
"controller": "foo", model.MetricNameLabel: "errors_total",
"name": "errors_total", "controller": "foo",
"operation": "bar", "operation": "bar",
} }
increments := 10 increments := 10
@ -318,9 +318,9 @@ func AppendsRepeatingValuesTests(p MetricPersistence, t test.Tester) {
} }
labelSet := model.LabelSet{ labelSet := model.LabelSet{
"controller": "foo", model.MetricNameLabel: "errors_total",
"name": "errors_total", "controller": "foo",
"operation": "bar", "operation": "bar",
} }
for i := 0; i < increments; i++ { for i := 0; i < increments; i++ {

View file

@ -21,12 +21,12 @@ import (
) )
func GetFingerprintsForLabelSetUsesAndForLabelMatchingTests(p MetricPersistence, t test.Tester) { func GetFingerprintsForLabelSetUsesAndForLabelMatchingTests(p MetricPersistence, t test.Tester) {
metrics := []map[string]string{ metrics := []model.LabelSet{
{"name": "request_metrics_latency_equal_tallying_microseconds", "instance": "http://localhost:9090/metrics.json", "percentile": "0.010000"}, {model.MetricNameLabel: "request_metrics_latency_equal_tallying_microseconds", "instance": "http://localhost:9090/metrics.json", "percentile": "0.010000"},
{"name": "requests_metrics_latency_equal_accumulating_microseconds", "instance": "http://localhost:9090/metrics.json", "percentile": "0.010000"}, {model.MetricNameLabel: "requests_metrics_latency_equal_accumulating_microseconds", "instance": "http://localhost:9090/metrics.json", "percentile": "0.010000"},
{"name": "requests_metrics_latency_logarithmic_accumulating_microseconds", "instance": "http://localhost:9090/metrics.json", "percentile": "0.010000"}, {model.MetricNameLabel: "requests_metrics_latency_logarithmic_accumulating_microseconds", "instance": "http://localhost:9090/metrics.json", "percentile": "0.010000"},
{"name": "requests_metrics_latency_logarithmic_tallying_microseconds", "instance": "http://localhost:9090/metrics.json", "percentile": "0.010000"}, {model.MetricNameLabel: "requests_metrics_latency_logarithmic_tallying_microseconds", "instance": "http://localhost:9090/metrics.json", "percentile": "0.010000"},
{"name": "targets_healthy_scrape_latency_ms", "instance": "http://localhost:9090/metrics.json", "percentile": "0.010000"}, {model.MetricNameLabel: "targets_healthy_scrape_latency_ms", "instance": "http://localhost:9090/metrics.json", "percentile": "0.010000"},
} }
for _, metric := range metrics { for _, metric := range metrics {
@ -44,8 +44,8 @@ func GetFingerprintsForLabelSetUsesAndForLabelMatchingTests(p MetricPersistence,
} }
labelSet := model.LabelSet{ labelSet := model.LabelSet{
"name": "targets_healthy_scrape_latency_ms", model.MetricNameLabel: "targets_healthy_scrape_latency_ms",
"percentile": "0.010000", "percentile": "0.010000",
} }
fingerprints, err := p.GetFingerprintsForLabelSet(labelSet) fingerprints, err := p.GetFingerprintsForLabelSet(labelSet)

View file

@ -567,7 +567,7 @@ func GetValueAtTimeTests(persistenceMaker func() (MetricPersistence, io.Closer),
}() }()
m := model.Metric{ m := model.Metric{
"name": "age_in_years", model.MetricNameLabel: "age_in_years",
} }
for _, value := range context.values { for _, value := range context.values {
@ -1012,7 +1012,7 @@ func GetBoundaryValuesTests(persistenceMaker func() (MetricPersistence, io.Close
}() }()
m := model.Metric{ m := model.Metric{
"name": "age_in_years", model.MetricNameLabel: "age_in_years",
} }
for _, value := range context.values { for _, value := range context.values {
@ -1369,7 +1369,7 @@ func GetRangeValuesTests(persistenceMaker func() (MetricPersistence, io.Closer),
}() }()
m := model.Metric{ m := model.Metric{
"name": "age_in_years", model.MetricNameLabel: "age_in_years",
} }
for _, value := range context.values { for _, value := range context.values {

View file

@ -173,7 +173,7 @@ func AppendSampleAsPureSingleEntityAppendTests(p MetricPersistence, t test.Teste
sample := model.Sample{ sample := model.Sample{
Value: model.SampleValue(x), Value: model.SampleValue(x),
Timestamp: time.Unix(int64(x), 0), Timestamp: time.Unix(int64(x), 0),
Metric: model.Metric{"name": "my_metric"}, Metric: model.Metric{model.MetricNameLabel: "my_metric"},
} }
err := p.AppendSample(sample) err := p.AppendSample(sample)
@ -215,7 +215,7 @@ func StochasticTests(persistenceMaker func() MetricPersistence, t test.Tester) {
} }
v := model.LabelValue(fmt.Sprintf("metric_index_%d", metricIndex)) v := model.LabelValue(fmt.Sprintf("metric_index_%d", metricIndex))
sample.Metric["name"] = v sample.Metric[model.MetricNameLabel] = v
for sharedLabelIndex := 0; sharedLabelIndex < numberOfSharedLabels; sharedLabelIndex++ { for sharedLabelIndex := 0; sharedLabelIndex < numberOfSharedLabels; sharedLabelIndex++ {
l := model.LabelName(fmt.Sprintf("shared_label_%d", sharedLabelIndex)) l := model.LabelName(fmt.Sprintf("shared_label_%d", sharedLabelIndex))
@ -348,7 +348,7 @@ func StochasticTests(persistenceMaker func() MetricPersistence, t test.Tester) {
} }
metric := model.Metric{} metric := model.Metric{}
metric["name"] = model.LabelValue(fmt.Sprintf("metric_index_%d", metricIndex)) metric[model.MetricNameLabel] = model.LabelValue(fmt.Sprintf("metric_index_%d", metricIndex))
for i := 0; i < numberOfSharedLabels; i++ { for i := 0; i < numberOfSharedLabels; i++ {
l := model.LabelName(fmt.Sprintf("shared_label_%d", i)) l := model.LabelName(fmt.Sprintf("shared_label_%d", i))

View file

@ -81,7 +81,7 @@ func testMakeView(t test.Tester) {
} }
var ( var (
instant = time.Date(1984, 3, 30, 0, 0, 0, 0, time.Local) instant = time.Date(1984, 3, 30, 0, 0, 0, 0, time.Local)
metric = model.Metric{"name": "request_count"} metric = model.Metric{model.MetricNameLabel: "request_count"}
fingerprint = model.NewFingerprintFromMetric(metric) fingerprint = model.NewFingerprintFromMetric(metric)
scenarios = []struct { scenarios = []struct {
data []model.Sample data []model.Sample
@ -498,7 +498,7 @@ func TestGetAllValuesForLabel(t *testing.T) {
defer closer.Close() defer closer.Close()
for j, metric := range scenario.in { for j, metric := range scenario.in {
sample := model.Sample{ sample := model.Sample{
Metric: model.Metric{"name": model.LabelValue(metric.metricName)}, Metric: model.Metric{model.MetricNameLabel: model.LabelValue(metric.metricName)},
} }
if metric.appendToMemory { if metric.appendToMemory {
if err := tiered.(*tieredStorage).memoryArena.AppendSample(sample); err != nil { if err := tiered.(*tieredStorage).memoryArena.AppendSample(sample); err != nil {
@ -511,7 +511,7 @@ func TestGetAllValuesForLabel(t *testing.T) {
} }
} }
} }
metricNames, err := tiered.GetAllValuesForLabel("name") metricNames, err := tiered.GetAllValuesForLabel(model.MetricNameLabel)
if err != nil { if err != nil {
t.Fatalf("%d. Error getting metric names: %s", i, err) t.Fatalf("%d. Error getting metric names: %s", i, err)
} }

View file

@ -17,6 +17,7 @@ import (
"code.google.com/p/gorest" "code.google.com/p/gorest"
"encoding/json" "encoding/json"
"errors" "errors"
"github.com/prometheus/prometheus/model"
"github.com/prometheus/prometheus/rules" "github.com/prometheus/prometheus/rules"
"github.com/prometheus/prometheus/rules/ast" "github.com/prometheus/prometheus/rules/ast"
"log" "log"
@ -86,7 +87,7 @@ func (serv MetricsService) QueryRange(expr string, end int64, duration int64, st
} }
func (serv MetricsService) Metrics() string { func (serv MetricsService) Metrics() string {
metricNames, err := serv.appState.Storage.GetAllValuesForLabel("name") metricNames, err := serv.appState.Storage.GetAllValuesForLabel(model.MetricNameLabel)
rb := serv.ResponseBuilder() rb := serv.ResponseBuilder()
rb.SetContentType(gorest.Application_Json) rb.SetContentType(gorest.Application_Json)
if err != nil { if err != nil {