@@ -56,6 +56,263 @@ func Test_SeriesMerger(t *testing.T) {
5656 }
5757}
5858
59+ func Test_SeriesMerger_Annotations (t * testing.T ) {
60+ for _ , tc := range []struct {
61+ name string
62+ in [][]* typesv1.Series
63+ out []* typesv1.Series
64+ }{
65+ {
66+ name : "merge two distinct annotations" ,
67+ in : [][]* typesv1.Series {
68+ {
69+ {
70+ Labels : LabelsFromStrings ("foo" , "bar" ),
71+ Points : []* typesv1.Point {
72+ {
73+ Timestamp : 1 ,
74+ Value : 1 ,
75+ Annotations : []* typesv1.ProfileAnnotation {
76+ {Key : "key1" , Value : "value1" },
77+ },
78+ },
79+ },
80+ },
81+ },
82+ {
83+ {
84+ Labels : LabelsFromStrings ("foo" , "bar" ),
85+ Points : []* typesv1.Point {
86+ {
87+ Timestamp : 1 ,
88+ Value : 2 ,
89+ Annotations : []* typesv1.ProfileAnnotation {
90+ {Key : "key1" , Value : "value2" },
91+ },
92+ },
93+ },
94+ },
95+ },
96+ },
97+ out : []* typesv1.Series {
98+ {
99+ Labels : LabelsFromStrings ("foo" , "bar" ),
100+ Points : []* typesv1.Point {
101+ {
102+ Timestamp : 1 ,
103+ Value : 3 ,
104+ Annotations : []* typesv1.ProfileAnnotation {
105+ {Key : "key1" , Value : "value1" },
106+ {Key : "key1" , Value : "value2" },
107+ },
108+ },
109+ },
110+ },
111+ },
112+ },
113+ {
114+ name : "merge duplicate annotations" ,
115+ in : [][]* typesv1.Series {
116+ {
117+ {
118+ Labels : LabelsFromStrings ("foo" , "bar" ),
119+ Points : []* typesv1.Point {
120+ {
121+ Timestamp : 1 ,
122+ Value : 1 ,
123+ Annotations : []* typesv1.ProfileAnnotation {
124+ {Key : "key1" , Value : "value1" },
125+ {Key : "key2" , Value : "value2" },
126+ },
127+ },
128+ },
129+ },
130+ },
131+ {
132+ {
133+ Labels : LabelsFromStrings ("foo" , "bar" ),
134+ Points : []* typesv1.Point {
135+ {
136+ Timestamp : 1 ,
137+ Value : 2 ,
138+ Annotations : []* typesv1.ProfileAnnotation {
139+ {Key : "key1" , Value : "value1" },
140+ {Key : "key3" , Value : "value3" },
141+ },
142+ },
143+ },
144+ },
145+ },
146+ },
147+ out : []* typesv1.Series {
148+ {
149+ Labels : LabelsFromStrings ("foo" , "bar" ),
150+ Points : []* typesv1.Point {
151+ {
152+ Timestamp : 1 ,
153+ Value : 3 ,
154+ Annotations : []* typesv1.ProfileAnnotation {
155+ {Key : "key1" , Value : "value1" },
156+ {Key : "key2" , Value : "value2" },
157+ {Key : "key3" , Value : "value3" },
158+ },
159+ },
160+ },
161+ },
162+ },
163+ },
164+ {
165+ name : "merge all duplicate annotations" ,
166+ in : [][]* typesv1.Series {
167+ {
168+ {
169+ Labels : LabelsFromStrings ("foo" , "bar" ),
170+ Points : []* typesv1.Point {
171+ {
172+ Timestamp : 1 ,
173+ Value : 1 ,
174+ Annotations : []* typesv1.ProfileAnnotation {
175+ {Key : "key1" , Value : "value1" },
176+ {Key : "key2" , Value : "value2" },
177+ },
178+ },
179+ },
180+ },
181+ },
182+ {
183+ {
184+ Labels : LabelsFromStrings ("foo" , "bar" ),
185+ Points : []* typesv1.Point {
186+ {
187+ Timestamp : 1 ,
188+ Value : 2 ,
189+ Annotations : []* typesv1.ProfileAnnotation {
190+ {Key : "key1" , Value : "value1" },
191+ {Key : "key2" , Value : "value2" },
192+ },
193+ },
194+ },
195+ },
196+ },
197+ },
198+ out : []* typesv1.Series {
199+ {
200+ Labels : LabelsFromStrings ("foo" , "bar" ),
201+ Points : []* typesv1.Point {
202+ {
203+ Timestamp : 1 ,
204+ Value : 3 ,
205+ Annotations : []* typesv1.ProfileAnnotation {
206+ {Key : "key1" , Value : "value1" },
207+ {Key : "key2" , Value : "value2" },
208+ },
209+ },
210+ },
211+ },
212+ },
213+ },
214+ {
215+ name : "annotations sorted by key then value" ,
216+ in : [][]* typesv1.Series {
217+ {
218+ {
219+ Labels : LabelsFromStrings ("foo" , "bar" ),
220+ Points : []* typesv1.Point {
221+ {
222+ Timestamp : 1 ,
223+ Value : 1 ,
224+ Annotations : []* typesv1.ProfileAnnotation {
225+ {Key : "z" , Value : "last" },
226+ {Key : "a" , Value : "first" },
227+ },
228+ },
229+ },
230+ },
231+ },
232+ {
233+ {
234+ Labels : LabelsFromStrings ("foo" , "bar" ),
235+ Points : []* typesv1.Point {
236+ {
237+ Timestamp : 1 ,
238+ Value : 2 ,
239+ Annotations : []* typesv1.ProfileAnnotation {
240+ {Key : "m" , Value : "middle" },
241+ },
242+ },
243+ },
244+ },
245+ },
246+ },
247+ out : []* typesv1.Series {
248+ {
249+ Labels : LabelsFromStrings ("foo" , "bar" ),
250+ Points : []* typesv1.Point {
251+ {
252+ Timestamp : 1 ,
253+ Value : 3 ,
254+ Annotations : []* typesv1.ProfileAnnotation {
255+ {Key : "a" , Value : "first" },
256+ {Key : "m" , Value : "middle" },
257+ {Key : "z" , Value : "last" },
258+ },
259+ },
260+ },
261+ },
262+ },
263+ },
264+ {
265+ name : "empty annotations on one side" ,
266+ in : [][]* typesv1.Series {
267+ {
268+ {
269+ Labels : LabelsFromStrings ("foo" , "bar" ),
270+ Points : []* typesv1.Point {
271+ {
272+ Timestamp : 1 ,
273+ Value : 1 ,
274+ Annotations : []* typesv1.ProfileAnnotation {},
275+ },
276+ },
277+ },
278+ },
279+ {
280+ {
281+ Labels : LabelsFromStrings ("foo" , "bar" ),
282+ Points : []* typesv1.Point {
283+ {
284+ Timestamp : 1 ,
285+ Value : 2 ,
286+ Annotations : []* typesv1.ProfileAnnotation {
287+ {Key : "key1" , Value : "value1" },
288+ },
289+ },
290+ },
291+ },
292+ },
293+ },
294+ out : []* typesv1.Series {
295+ {
296+ Labels : LabelsFromStrings ("foo" , "bar" ),
297+ Points : []* typesv1.Point {
298+ {
299+ Timestamp : 1 ,
300+ Value : 3 ,
301+ Annotations : []* typesv1.ProfileAnnotation {
302+ {Key : "key1" , Value : "value1" },
303+ },
304+ },
305+ },
306+ },
307+ },
308+ },
309+ } {
310+ t .Run (tc .name , func (t * testing.T ) {
311+ testhelper .EqualProto (t , tc .out , MergeSeries (nil , tc .in ... ))
312+ })
313+ }
314+ }
315+
59316func Test_SeriesMerger_Overlap_Sum (t * testing.T ) {
60317 for _ , tc := range []struct {
61318 name string
0 commit comments