@@ -21,6 +21,7 @@ package prometheus_test
21
21
22
22
import (
23
23
"bytes"
24
+ "fmt"
24
25
"io/ioutil"
25
26
"math/rand"
26
27
"net/http"
@@ -783,6 +784,11 @@ func TestAlreadyRegistered(t *testing.T) {
783
784
// same HistogramVec is registered concurrently and the Gather method of the
784
785
// registry is called concurrently.
785
786
func TestHistogramVecRegisterGatherConcurrency (t * testing.T ) {
787
+ labelNames := make ([]string , 16 ) // Need at least 13 to expose #512.
788
+ for i := range labelNames {
789
+ labelNames [i ] = fmt .Sprint ("label_" , i )
790
+ }
791
+
786
792
var (
787
793
reg = prometheus .NewPedanticRegistry ()
788
794
hv = prometheus .NewHistogramVec (
@@ -791,7 +797,7 @@ func TestHistogramVecRegisterGatherConcurrency(t *testing.T) {
791
797
Help : "This helps testing." ,
792
798
ConstLabels : prometheus.Labels {"foo" : "bar" },
793
799
},
794
- [] string { "one" , "two" , "three" } ,
800
+ labelNames ,
795
801
)
796
802
labelValues = []string {"a" , "b" , "c" , "alpha" , "beta" , "gamma" , "aleph" , "beth" , "gimel" }
797
803
quit = make (chan struct {})
@@ -806,11 +812,11 @@ func TestHistogramVecRegisterGatherConcurrency(t *testing.T) {
806
812
return
807
813
default :
808
814
obs := rand .NormFloat64 ()* .1 + .2
809
- hv . WithLabelValues (
810
- labelValues [ rand . Intn ( len ( labelValues ))],
811
- labelValues [rand .Intn (len (labelValues ))],
812
- labelValues [ rand . Intn ( len ( labelValues ))],
813
- ).Observe (obs )
815
+ values := make ([] string , 0 , len ( labelNames ))
816
+ for range labelNames {
817
+ values = append ( values , labelValues [rand .Intn (len (labelValues ))])
818
+ }
819
+ hv . WithLabelValues ( values ... ).Observe (obs )
814
820
}
815
821
}
816
822
}
@@ -848,7 +854,7 @@ func TestHistogramVecRegisterGatherConcurrency(t *testing.T) {
848
854
if len (g ) != 1 {
849
855
t .Error ("Gathered unexpected number of metric families:" , len (g ))
850
856
}
851
- if len (g [0 ].Metric [0 ].Label ) != 4 {
857
+ if len (g [0 ].Metric [0 ].Label ) != len ( labelNames ) + 1 {
852
858
t .Error ("Gathered unexpected number of label pairs:" , len (g [0 ].Metric [0 ].Label ))
853
859
}
854
860
}
0 commit comments