@@ -3,6 +3,7 @@ package firedb
3
3
import (
4
4
"compress/gzip"
5
5
"context"
6
+ "encoding/json"
6
7
"io/ioutil"
7
8
"os"
8
9
"testing"
@@ -270,9 +271,13 @@ func TestSelectProfiles(t *testing.T) {
270
271
271
272
// todo write more robust tests.
272
273
for i := int64 (0 ); i < 4 ; i ++ {
273
- p := newProfileBar ()
274
- p .TimeNanos = int64 (time .Second * time .Duration (i ))
275
- err = head .Ingest (context .Background (), p , & commonv1.LabelPair {Name : "job" , Value : "bar" }, & commonv1.LabelPair {Name : "__name__" , Value : "memory" })
274
+ pF := newProfileFoo ()
275
+ pB := newProfileBar ()
276
+ pF .TimeNanos = int64 (time .Second * time .Duration (i ))
277
+ pB .TimeNanos = int64 (time .Second * time .Duration (i ))
278
+ err = head .Ingest (context .Background (), pF , & commonv1.LabelPair {Name : "job" , Value : "foo" }, & commonv1.LabelPair {Name : "__name__" , Value : "foomemory" })
279
+ require .NoError (t , err )
280
+ err = head .Ingest (context .Background (), pB , & commonv1.LabelPair {Name : "job" , Value : "bar" }, & commonv1.LabelPair {Name : "__name__" , Value : "memory" })
276
281
require .NoError (t , err )
277
282
}
278
283
@@ -290,7 +295,60 @@ func TestSelectProfiles(t *testing.T) {
290
295
}))
291
296
require .NoError (t , err )
292
297
require .Equal (t , 2 , len (resp .Msg .Profiles ))
293
- require .Equal (t , 1 , len (resp .Msg .FunctionNames ))
298
+
299
+ // compare the first profile deep
300
+ profileJSON , err := json .Marshal (& resp .Msg .Profiles [0 ])
301
+ require .NoError (t , err )
302
+ require .JSONEq (t , `{
303
+ "type": {
304
+ "name": "memory",
305
+ "sampleType": "type",
306
+ "sampleUnit": "unit",
307
+ "periodType": "type",
308
+ "periodUnit": "unit"
309
+ },
310
+ "labels": [
311
+ {
312
+ "name": "__name__",
313
+ "value": "memory"
314
+ },
315
+ {
316
+ "name": "__period_type__",
317
+ "value": "type"
318
+ },
319
+ {
320
+ "name": "__period_unit__",
321
+ "value": "unit"
322
+ },
323
+ {
324
+ "name": "__profile_type__",
325
+ "value": "memory:type:unit:type:unit"
326
+ },
327
+ {
328
+ "name": "__type__",
329
+ "value": "type"
330
+ },
331
+ {
332
+ "name": "__unit__",
333
+ "value": "unit"
334
+ },
335
+ {
336
+ "name": "job",
337
+ "value": "bar"
338
+ }
339
+ ],
340
+ "timestamp": 1000,
341
+ "stacktraces": [
342
+ {
343
+ "function_ids": [
344
+ 0
345
+ ],
346
+ "value": 2345
347
+ }
348
+ ]}` , string (profileJSON ))
349
+
350
+ // ensure the func name matches
351
+ require .Equal (t , []string {"func_a" }, resp .Msg .FunctionNames )
294
352
}
295
353
296
354
func BenchmarkHeadIngestProfiles (t * testing.B ) {
0 commit comments