forked from mirror/client_golang
fail Gather'ing when label value is not utf8
This commit is contained in:
parent
7ee20d77cb
commit
685a3c90d4
|
@ -23,6 +23,8 @@ import (
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
dto "github.com/prometheus/client_model/go"
|
dto "github.com/prometheus/client_model/go"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -679,6 +681,12 @@ func checkMetricConsistency(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, labelPair := range dtoMetric.GetLabel() {
|
||||||
|
if !utf8.ValidString(*labelPair.Value) {
|
||||||
|
return fmt.Errorf("collected metric's label %s is not utf8: %#v", *labelPair.Name, *labelPair.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Is the metric unique (i.e. no other metric with the same name and the same label values)?
|
// Is the metric unique (i.e. no other metric with the same name and the same label values)?
|
||||||
h := hashNew()
|
h := hashNew()
|
||||||
h = hashAdd(h, metricFamily.GetName())
|
h = hashAdd(h, metricFamily.GetName())
|
||||||
|
|
|
@ -209,6 +209,34 @@ metric: <
|
||||||
expectedMetricFamilyMergedWithExternalAsProtoCompactText := []byte(`name:"name" help:"docstring" type:COUNTER metric:<label:<name:"constname" value:"constvalue" > label:<name:"labelname" value:"different_val" > counter:<value:42 > > metric:<label:<name:"constname" value:"constvalue" > label:<name:"labelname" value:"val1" > counter:<value:1 > > metric:<label:<name:"constname" value:"constvalue" > label:<name:"labelname" value:"val2" > counter:<value:1 > >
|
expectedMetricFamilyMergedWithExternalAsProtoCompactText := []byte(`name:"name" help:"docstring" type:COUNTER metric:<label:<name:"constname" value:"constvalue" > label:<name:"labelname" value:"different_val" > counter:<value:42 > > metric:<label:<name:"constname" value:"constvalue" > label:<name:"labelname" value:"val1" > counter:<value:1 > > metric:<label:<name:"constname" value:"constvalue" > label:<name:"labelname" value:"val2" > counter:<value:1 > >
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
externalMetricFamilyWithInvalidLabelValue := &dto.MetricFamily{
|
||||||
|
Name: proto.String("name"),
|
||||||
|
Help: proto.String("docstring"),
|
||||||
|
Type: dto.MetricType_COUNTER.Enum(),
|
||||||
|
Metric: []*dto.Metric{
|
||||||
|
{
|
||||||
|
Label: []*dto.LabelPair{
|
||||||
|
{
|
||||||
|
Name: proto.String("constname"),
|
||||||
|
Value: proto.String("\xFF"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: proto.String("labelname"),
|
||||||
|
Value: proto.String("different_val"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Counter: &dto.Counter{
|
||||||
|
Value: proto.Float64(42),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedMetricFamilyInvalidLabelValueAsText := []byte(`An error has occurred during metrics gathering:
|
||||||
|
|
||||||
|
collected metric's label constname is not utf8: "\xff"
|
||||||
|
`)
|
||||||
|
|
||||||
type output struct {
|
type output struct {
|
||||||
headers map[string]string
|
headers map[string]string
|
||||||
body []byte
|
body []byte
|
||||||
|
@ -452,6 +480,22 @@ metric: <
|
||||||
externalMetricFamilyWithSameName,
|
externalMetricFamilyWithSameName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{ // 16
|
||||||
|
headers: map[string]string{
|
||||||
|
"Accept": "application/vnd.google.protobuf;proto=io.prometheus.client.MetricFamily;encoding=compact-text",
|
||||||
|
},
|
||||||
|
out: output{
|
||||||
|
headers: map[string]string{
|
||||||
|
"Content-Type": `text/plain; charset=utf-8`,
|
||||||
|
},
|
||||||
|
body: expectedMetricFamilyInvalidLabelValueAsText,
|
||||||
|
},
|
||||||
|
collector: metricVec,
|
||||||
|
externalMF: []*dto.MetricFamily{
|
||||||
|
externalMetricFamily,
|
||||||
|
externalMetricFamilyWithInvalidLabelValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for i, scenario := range scenarios {
|
for i, scenario := range scenarios {
|
||||||
registry := prometheus.NewPedanticRegistry()
|
registry := prometheus.NewPedanticRegistry()
|
||||||
|
|
Loading…
Reference in New Issue