@@ -17,6 +17,7 @@ package metrics
17
17
import (
18
18
"fmt"
19
19
"regexp"
20
+ "sort"
20
21
"strconv"
21
22
"time"
22
23
@@ -1877,18 +1878,30 @@ func (c *PrometheusCollector) collectContainersInfo(session *prometheus.CollectS
1877
1878
if err != nil {
1878
1879
return err
1879
1880
}
1880
- rawLabels := map [string ]struct {}{}
1881
+
1882
+ rawLabelsDup := map [string ]struct {}{}
1881
1883
for _ , container := range containers {
1882
1884
for l := range c .containerLabelsFunc (container ) {
1883
- rawLabels [l ] = struct {}{}
1885
+ rawLabelsDup [l ] = struct {}{}
1884
1886
}
1885
1887
}
1886
1888
1889
+ rawLabels := make ([]string , 0 , len (rawLabelsDup ))
1890
+ for r := range rawLabelsDup {
1891
+ rawLabels = append (rawLabels , r )
1892
+ }
1893
+ sort .Strings (rawLabels )
1894
+
1895
+ values := make ([]string , 0 , len (rawLabels ))
1896
+ labels := make ([]string , 0 , len (rawLabels ))
1897
+
1898
+ clabels := make ([]string , 0 , len (rawLabels ))
1899
+ cvalues := make ([]string , 0 , len (rawLabels ))
1887
1900
for _ , cont := range containers {
1888
- values := make ([] string , 0 , len ( rawLabels ))
1889
- labels := make ([] string , 0 , len ( rawLabels ))
1901
+ values := values [: 0 ]
1902
+ labels := labels [: 0 ]
1890
1903
containerLabels := c .containerLabelsFunc (cont )
1891
- for l := range rawLabels {
1904
+ for _ , l := range rawLabels {
1892
1905
duplicate := false
1893
1906
sl := sanitizeLabelName (l )
1894
1907
for _ , x := range labels {
@@ -1950,18 +1963,27 @@ func (c *PrometheusCollector) collectContainersInfo(session *prometheus.CollectS
1950
1963
continue
1951
1964
}
1952
1965
for _ , metricValue := range cm .getValues (stats ) {
1966
+ labels = append (labels , cm .extraLabels ... )
1967
+ values = append (values , metricValue .labels ... )
1953
1968
session .MustAddMetric (
1954
- cm .name , cm .help ,
1955
- append (labels , cm .extraLabels ... ), append (values , metricValue .labels ... ),
1956
- cm .valueType , metricValue .value , & metricValue .timestamp ,
1969
+ cm .name , cm .help , labels , values , cm .valueType , metricValue .value , & metricValue .timestamp ,
1957
1970
)
1971
+ labels = labels [:len (labels )- len (cm .extraLabels )]
1972
+ values = values [:len (values )- len (metricValue .labels )]
1958
1973
}
1959
1974
}
1960
1975
if c .includedMetrics .Has (container .AppMetrics ) {
1961
- for metricLabel , v := range stats .CustomMetrics {
1976
+ metricLabels := make ([]string , 0 , len (stats .CustomMetrics ))
1977
+ for metricLabel := range stats .CustomMetrics {
1978
+ metricLabels = append (metricLabels , metricLabel )
1979
+ }
1980
+ sort .Strings (metricLabels )
1981
+
1982
+ for _ , metricLabel := range metricLabels {
1983
+ v := stats .CustomMetrics [metricLabel ]
1962
1984
for _ , metric := range v {
1963
- clabels := make ([] string , len (rawLabels ), len ( rawLabels ) + len ( metric . Labels ))
1964
- cvalues := make ([] string , len (rawLabels ), len ( rawLabels ) + len ( metric . Labels ))
1985
+ clabels = clabels [: len (rawLabels )]
1986
+ cvalues = cvalues [: len (rawLabels )]
1965
1987
copy (clabels , labels )
1966
1988
copy (cvalues , values )
1967
1989
for label , value := range metric .Labels {
0 commit comments