forked from mirror/client_golang
Check quantile label during SummaryVec construction
Also, document the existing behavior more clearly. Signed-off-by: beorn7 <beorn@soundcloud.com>
This commit is contained in:
parent
ee1c9d7e23
commit
e064aa97f1
|
@ -105,6 +105,11 @@ type SummaryOpts struct {
|
||||||
// with the same fully-qualified name must have the same label names in
|
// with the same fully-qualified name must have the same label names in
|
||||||
// their ConstLabels.
|
// their ConstLabels.
|
||||||
//
|
//
|
||||||
|
// Due to the way a Summary is represented in the Prometheus text format
|
||||||
|
// and how it is handled by the Prometheus server internally, “quantile”
|
||||||
|
// is an illegal label name. Construction of a Summary or SummaryVec
|
||||||
|
// will panic if this label name is used in ConstLabels.
|
||||||
|
//
|
||||||
// ConstLabels are only used rarely. In particular, do not use them to
|
// ConstLabels are only used rarely. In particular, do not use them to
|
||||||
// attach the same labels to all your metrics. Those use cases are
|
// attach the same labels to all your metrics. Those use cases are
|
||||||
// better covered by target labels set by the scraping Prometheus
|
// better covered by target labels set by the scraping Prometheus
|
||||||
|
@ -402,7 +407,16 @@ type SummaryVec struct {
|
||||||
|
|
||||||
// NewSummaryVec creates a new SummaryVec based on the provided SummaryOpts and
|
// NewSummaryVec creates a new SummaryVec based on the provided SummaryOpts and
|
||||||
// partitioned by the given label names.
|
// partitioned by the given label names.
|
||||||
|
//
|
||||||
|
// Due to the way a Summary is represented in the Prometheus text format and how
|
||||||
|
// it is handled by the Prometheus server internally, “quantile” is an illegal
|
||||||
|
// label name. NewSummaryVec will panic if this label name is used.
|
||||||
func NewSummaryVec(opts SummaryOpts, labelNames []string) *SummaryVec {
|
func NewSummaryVec(opts SummaryOpts, labelNames []string) *SummaryVec {
|
||||||
|
for _, ln := range labelNames {
|
||||||
|
if ln == quantileLabel {
|
||||||
|
panic(errQuantileLabelNotAllowed)
|
||||||
|
}
|
||||||
|
}
|
||||||
desc := NewDesc(
|
desc := NewDesc(
|
||||||
BuildFQName(opts.Namespace, opts.Subsystem, opts.Name),
|
BuildFQName(opts.Namespace, opts.Subsystem, opts.Name),
|
||||||
opts.Help,
|
opts.Help,
|
||||||
|
|
|
@ -64,6 +64,31 @@ func TestSummaryWithoutObjectives(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSummaryWithQuantileLabel(t *testing.T) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r == nil {
|
||||||
|
t.Error("Attempt to create Summary with 'quantile' label did not panic.")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
_ = NewSummary(SummaryOpts{
|
||||||
|
Name: "test_summary",
|
||||||
|
Help: "less",
|
||||||
|
ConstLabels: Labels{"quantile": "test"},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSummaryVecWithQuantileLabel(t *testing.T) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r == nil {
|
||||||
|
t.Error("Attempt to create SummaryVec with 'quantile' label did not panic.")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
_ = NewSummaryVec(SummaryOpts{
|
||||||
|
Name: "test_summary",
|
||||||
|
Help: "less",
|
||||||
|
}, []string{"quantile"})
|
||||||
|
}
|
||||||
|
|
||||||
func benchmarkSummaryObserve(w int, b *testing.B) {
|
func benchmarkSummaryObserve(w int, b *testing.B) {
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue