@@ -31,27 +31,29 @@ func EmptyLables() Labels {
31
31
// LabelsFromSlice converts a labels.Labels to a Labels object
32
32
func LabelsFromSlice (ls labels.Labels ) (Labels , error ) {
33
33
length := len (ls )
34
- names := make ([]string , 0 , length )
35
- values := make ([]string , 0 , length )
34
+ labels := Labels {
35
+ names : make ([]string , 0 , length ),
36
+ values : make ([]string , 0 , length ),
37
+ }
36
38
37
- metricName : = ""
39
+ labels . metricName = ""
38
40
for _ , l := range ls {
39
- names = append (names , l .Name )
40
- values = append (values , l .Value )
41
+ labels . names = append (labels . names , l .Name )
42
+ labels . values = append (labels . values , l .Value )
41
43
if l .Name == MetricNameLabelName {
42
- metricName = l .Value
44
+ labels . metricName = l .Value
43
45
}
44
46
}
45
47
46
- return LabelsFromSlices (names , values , metricName )
48
+ err := initLabels (& labels )
49
+ return labels , err
47
50
}
48
51
49
- // LabelsFromSlices creates a Labels object from keys, values, and metric name
50
- func LabelsFromSlices (names []string , values []string , metricName string ) (Labels , error ) {
51
- l := Labels {names : names , values : values , metricName : metricName }
52
+ // initLabels intializes labels
53
+ func initLabels (l * Labels ) error {
52
54
53
- if ! sort .IsSorted (& l ) {
54
- sort .Sort (& l )
55
+ if ! sort .IsSorted (l ) {
56
+ sort .Sort (l )
55
57
}
56
58
57
59
length := len (l .names )
@@ -67,7 +69,7 @@ func LabelsFromSlices(names []string, values []string, metricName string) (Label
67
69
// total length anyway, we only use 16bits to store the legth of each substring
68
70
// in our string encoding
69
71
if expectedStrLen > math .MaxUint16 {
70
- return l , fmt .Errorf ("series too long, combined series has length %d, max length %d" , expectedStrLen , ^ uint16 (0 ))
72
+ return fmt .Errorf ("series too long, combined series has length %d, max length %d" , expectedStrLen , ^ uint16 (0 ))
71
73
}
72
74
73
75
// the string representation is
@@ -100,26 +102,28 @@ func LabelsFromSlices(names []string, values []string, metricName string) (Label
100
102
101
103
l .str = builder .String ()
102
104
103
- return l , nil
105
+ return nil
104
106
}
105
107
106
108
func labelProtosToLabels (labelPairs []prompb.Label ) (Labels , string , error ) {
107
109
length := len (labelPairs )
108
- names := make ([]string , 0 , length )
109
- values := make ([]string , 0 , length )
110
+ labels := Labels {
111
+ names : make ([]string , 0 , length ),
112
+ values : make ([]string , 0 , length ),
113
+ }
110
114
111
- metricName : = ""
115
+ labels . metricName = ""
112
116
for _ , l := range labelPairs {
113
- names = append (names , l .Name )
114
- values = append (values , l .Value )
117
+ labels . names = append (labels . names , l .Name )
118
+ labels . values = append (labels . values , l .Value )
115
119
if l .Name == MetricNameLabelName {
116
- metricName = l .Value
120
+ labels . metricName = l .Value
117
121
}
118
122
}
119
123
120
- ls , err := LabelsFromSlices ( names , values , metricName )
124
+ err := initLabels ( & labels )
121
125
122
- return ls , metricName , err
126
+ return labels , labels . metricName , err
123
127
}
124
128
125
129
func (l Labels ) isEmpty () bool {
0 commit comments