Change internal metric name label to __name__.
This also adds a check that forbids any user-supplied metrics to start with the reserved label name prefix "__". Change-Id: I2fe94c740b685ad05c4c670613cf2af7b9e1c1c0
This commit is contained in:
parent
29ebb580db
commit
bb957bc145
|
@ -1,7 +1,7 @@
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"baseLabels": {
|
"baseLabels": {
|
||||||
"name": "rpc_calls_total",
|
"__name__": "rpc_calls_total",
|
||||||
"job": "batch_job"
|
"job": "batch_job"
|
||||||
},
|
},
|
||||||
"docstring": "RPC calls.",
|
"docstring": "RPC calls.",
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"baseLabels": {
|
"baseLabels": {
|
||||||
"name": "rpc_latency_microseconds"
|
"__name__": "rpc_latency_microseconds"
|
||||||
},
|
},
|
||||||
"docstring": "RPC latency.",
|
"docstring": "RPC latency.",
|
||||||
"metric": {
|
"metric": {
|
||||||
|
|
|
@ -70,12 +70,12 @@ func TestMetricFamilyProcessor(t *testing.T) {
|
||||||
{
|
{
|
||||||
Samples: model.Samples{
|
Samples: model.Samples{
|
||||||
&model.Sample{
|
&model.Sample{
|
||||||
Metric: model.Metric{"name": "request_count", "some_label_name": "some_label_value"},
|
Metric: model.Metric{model.MetricNameLabel: "request_count", "some_label_name": "some_label_value"},
|
||||||
Value: -42,
|
Value: -42,
|
||||||
Timestamp: testTime,
|
Timestamp: testTime,
|
||||||
},
|
},
|
||||||
&model.Sample{
|
&model.Sample{
|
||||||
Metric: model.Metric{"name": "request_count", "another_label_name": "another_label_value"},
|
Metric: model.Metric{model.MetricNameLabel: "request_count", "another_label_name": "another_label_value"},
|
||||||
Value: 84,
|
Value: 84,
|
||||||
Timestamp: testTime,
|
Timestamp: testTime,
|
||||||
},
|
},
|
||||||
|
@ -89,17 +89,17 @@ func TestMetricFamilyProcessor(t *testing.T) {
|
||||||
{
|
{
|
||||||
Samples: model.Samples{
|
Samples: model.Samples{
|
||||||
&model.Sample{
|
&model.Sample{
|
||||||
Metric: model.Metric{"name": "request_count", "some_label_name": "some_label_value", "quantile": "0.99"},
|
Metric: model.Metric{model.MetricNameLabel: "request_count", "some_label_name": "some_label_value", "quantile": "0.99"},
|
||||||
Value: -42,
|
Value: -42,
|
||||||
Timestamp: testTime,
|
Timestamp: testTime,
|
||||||
},
|
},
|
||||||
&model.Sample{
|
&model.Sample{
|
||||||
Metric: model.Metric{"name": "request_count", "some_label_name": "some_label_value", "quantile": "0.999"},
|
Metric: model.Metric{model.MetricNameLabel: "request_count", "some_label_name": "some_label_value", "quantile": "0.999"},
|
||||||
Value: -84,
|
Value: -84,
|
||||||
Timestamp: testTime,
|
Timestamp: testTime,
|
||||||
},
|
},
|
||||||
&model.Sample{
|
&model.Sample{
|
||||||
Metric: model.Metric{"name": "request_count", "another_label_name": "another_label_value", "quantile": "0.5"},
|
Metric: model.Metric{model.MetricNameLabel: "request_count", "another_label_name": "another_label_value", "quantile": "0.5"},
|
||||||
Value: 10,
|
Value: 10,
|
||||||
Timestamp: testTime,
|
Timestamp: testTime,
|
||||||
},
|
},
|
||||||
|
|
|
@ -23,7 +23,11 @@ const (
|
||||||
ExporterLabelPrefix LabelName = "exporter_"
|
ExporterLabelPrefix LabelName = "exporter_"
|
||||||
|
|
||||||
// The label name indicating the metric name of a timeseries.
|
// The label name indicating the metric name of a timeseries.
|
||||||
MetricNameLabel LabelName = "name"
|
MetricNameLabel LabelName = "__name__"
|
||||||
|
|
||||||
|
// ReservedLabelPrefix is a prefix which is not legal in user-supplied label
|
||||||
|
// names.
|
||||||
|
ReservedLabelPrefix = "__"
|
||||||
|
|
||||||
// The label name indicating the job from which a timeseries was scraped.
|
// The label name indicating the job from which a timeseries was scraped.
|
||||||
JobLabel LabelName = "job"
|
JobLabel LabelName = "job"
|
||||||
|
|
|
@ -37,7 +37,6 @@ const (
|
||||||
baseLabelsKey = "baseLabels"
|
baseLabelsKey = "baseLabels"
|
||||||
docstringKey = "docstring"
|
docstringKey = "docstring"
|
||||||
metricKey = "metric"
|
metricKey = "metric"
|
||||||
nameLabel = "name"
|
|
||||||
|
|
||||||
counterTypeValue = "counter"
|
counterTypeValue = "counter"
|
||||||
floatBitCount = 64
|
floatBitCount = 64
|
||||||
|
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"code.google.com/p/goprotobuf/proto"
|
"code.google.com/p/goprotobuf/proto"
|
||||||
"github.com/matttproud/golang_protobuf_extensions/ext"
|
"github.com/matttproud/golang_protobuf_extensions/ext"
|
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/model"
|
||||||
"github.com/prometheus/client_golang/vendor/goautoneg"
|
"github.com/prometheus/client_golang/vendor/goautoneg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -124,8 +125,9 @@ func (r *registry) isValidCandidate(name string, baseLabels map[string]string) (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, contains := baseLabels[nameLabel]; contains {
|
for label := range baseLabels {
|
||||||
err = fmt.Errorf("metric named %s with baseLabels %s contains reserved label name %s in baseLabels", name, baseLabels, nameLabel)
|
if strings.HasPrefix(label, model.ReservedLabelPrefix) {
|
||||||
|
err = fmt.Errorf("metric named %s with baseLabels %s contains reserved label name %s in baseLabels", name, baseLabels, label)
|
||||||
|
|
||||||
if *abortOnMisuse {
|
if *abortOnMisuse {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -135,8 +137,9 @@ func (r *registry) isValidCandidate(name string, baseLabels map[string]string) (
|
||||||
|
|
||||||
return signature, err
|
return signature, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
baseLabels[nameLabel] = name
|
baseLabels[string(model.MetricNameLabel)] = name
|
||||||
signature = labelsToSignature(baseLabels)
|
signature = labelsToSignature(baseLabels)
|
||||||
|
|
||||||
if _, contains := r.signatureContainers[signature]; contains {
|
if _, contains := r.signatureContainers[signature]; contains {
|
||||||
|
|
|
@ -15,6 +15,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.google.com/p/goprotobuf/proto"
|
"code.google.com/p/goprotobuf/proto"
|
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testRegister(t tester) {
|
func testRegister(t tester) {
|
||||||
|
@ -83,7 +85,7 @@ func testRegister(t tester) {
|
||||||
inputs: []input{
|
inputs: []input{
|
||||||
{
|
{
|
||||||
name: "valid_name",
|
name: "valid_name",
|
||||||
baseLabels: map[string]string{"name": "illegal_duplicate_name"},
|
baseLabels: map[string]string{model.ReservedLabelPrefix + "internal": "illegal_internal_name"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
outputs: []bool{
|
outputs: []bool{
|
||||||
|
@ -303,7 +305,7 @@ func testDumpToWriter(t tester) {
|
||||||
"foo": NewCounter(),
|
"foo": NewCounter(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
out: []byte(`[{"baseLabels":{"label_foo":"foo","name":"foo"},"docstring":"metric foo","metric":{"type":"counter","value":[]}}]`),
|
out: []byte(`[{"baseLabels":{"__name__":"foo","label_foo":"foo"},"docstring":"metric foo","metric":{"type":"counter","value":[]}}]`),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
in: input{
|
in: input{
|
||||||
|
@ -312,7 +314,7 @@ func testDumpToWriter(t tester) {
|
||||||
"bar": NewCounter(),
|
"bar": NewCounter(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
out: []byte(`[{"baseLabels":{"label_bar":"bar","name":"bar"},"docstring":"metric bar","metric":{"type":"counter","value":[]}},{"baseLabels":{"label_foo":"foo","name":"foo"},"docstring":"metric foo","metric":{"type":"counter","value":[]}}]`),
|
out: []byte(`[{"baseLabels":{"__name__":"bar","label_bar":"bar"},"docstring":"metric bar","metric":{"type":"counter","value":[]}},{"baseLabels":{"__name__":"foo","label_foo":"foo"},"docstring":"metric foo","metric":{"type":"counter","value":[]}}]`),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue