forked from mirror/client_golang
Add more info to the inconsistent cardinality errors
Signed-off-by: Peter Jausovec <peter.jausovec@oracle.com>
This commit is contained in:
parent
f30f428035
commit
902733d080
|
@ -136,7 +136,8 @@ func NewCounterVec(opts CounterOpts, labelNames []string) *CounterVec {
|
|||
return &CounterVec{
|
||||
metricVec: newMetricVec(desc, func(lvs ...string) Metric {
|
||||
if len(lvs) != len(desc.variableLabels) {
|
||||
panic(errInconsistentCardinality)
|
||||
err := fmt.Errorf("%s: labels and values for '%s' don't match: labels %v, values %v", errInconsistentCardinality, desc.fqName, desc.variableLabels, lvs)
|
||||
panic(err)
|
||||
}
|
||||
result := &counter{desc: desc, labelPairs: makeLabelPairs(desc, lvs)}
|
||||
result.init(result) // Init self-collection.
|
||||
|
|
|
@ -147,7 +147,8 @@ func NewGaugeVec(opts GaugeOpts, labelNames []string) *GaugeVec {
|
|||
return &GaugeVec{
|
||||
metricVec: newMetricVec(desc, func(lvs ...string) Metric {
|
||||
if len(lvs) != len(desc.variableLabels) {
|
||||
panic(errInconsistentCardinality)
|
||||
err := fmt.Errorf("%s: labels and values for '%s' don't match: labels %v, values %v", errInconsistentCardinality, desc.fqName, desc.variableLabels, labelValues)
|
||||
panic(err)
|
||||
}
|
||||
result := &gauge{desc: desc, labelPairs: makeLabelPairs(desc, lvs)}
|
||||
result.init(result) // Init self-collection.
|
||||
|
|
|
@ -165,7 +165,8 @@ func NewHistogram(opts HistogramOpts) Histogram {
|
|||
|
||||
func newHistogram(desc *Desc, opts HistogramOpts, labelValues ...string) Histogram {
|
||||
if len(desc.variableLabels) != len(labelValues) {
|
||||
panic(errInconsistentCardinality)
|
||||
err := fmt.Errorf("%s: labels and values for '%s' don't match: labels %v, values %v", errInconsistentCardinality, desc.fqName, desc.variableLabels, labelValues)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for _, n := range desc.variableLabels {
|
||||
|
|
|
@ -39,7 +39,7 @@ var errInconsistentCardinality = errors.New("inconsistent label cardinality")
|
|||
|
||||
func validateValuesInLabels(labels Labels, expectedNumberOfValues int) error {
|
||||
if len(labels) != expectedNumberOfValues {
|
||||
return errInconsistentCardinality
|
||||
return fmt.Errorf("%s: number of labels and values don't match: expected %d, actual %d, labels %v", errInconsistentCardinality, expectedNumberOfValues, len(labels), labels)
|
||||
}
|
||||
|
||||
for name, val := range labels {
|
||||
|
|
|
@ -181,7 +181,8 @@ func NewSummary(opts SummaryOpts) Summary {
|
|||
|
||||
func newSummary(desc *Desc, opts SummaryOpts, labelValues ...string) Summary {
|
||||
if len(desc.variableLabels) != len(labelValues) {
|
||||
panic(errInconsistentCardinality)
|
||||
err := fmt.Errorf("%s: labels and values for '%s' don't match: labels %v, values %v", errInconsistentCardinality, desc.fqName, desc.variableLabels, labelValues)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for _, n := range desc.variableLabels {
|
||||
|
|
Loading…
Reference in New Issue