@@ -21,6 +21,7 @@ type queryModel struct {
21
21
WithStreaming bool
22
22
ProfileTypeID string `json:"profileTypeId"`
23
23
LabelSelector string `json:"labelSelector"`
24
+ GroupBy string `json:"groupBy"`
24
25
}
25
26
26
27
type dsJsonModel struct {
@@ -68,8 +69,7 @@ func (d *FireDatasource) query(ctx context.Context, pCtx backend.PluginContext,
68
69
Start : query .TimeRange .From .UnixMilli (),
69
70
End : query .TimeRange .To .UnixMilli (),
70
71
Step : math .Max (query .Interval .Seconds (), parsedInterval .Seconds ()),
71
- // todo add one or more group bys
72
- GroupBy : []string {},
72
+ GroupBy : strings .Split (qm .GroupBy , "," ),
73
73
})
74
74
75
75
log .DefaultLogger .Debug ("Sending SelectSeriesRequest" , "request" , req , "queryModel" , qm )
@@ -80,7 +80,7 @@ func (d *FireDatasource) query(ctx context.Context, pCtx backend.PluginContext,
80
80
return response
81
81
}
82
82
// add the frames to the response.
83
- response .Frames = append (response .Frames , seriesToDataFrame (seriesResp , qm .ProfileTypeID ))
83
+ response .Frames = append (response .Frames , seriesToDataFrames (seriesResp , qm .ProfileTypeID )... )
84
84
}
85
85
86
86
if query .QueryType == queryTypeProfile || query .QueryType == queryTypeBoth {
@@ -285,41 +285,44 @@ func walkTree(tree *ProfileTree, fn func(tree *ProfileTree)) {
285
285
}
286
286
}
287
287
288
- func seriesToDataFrame (seriesResp * connect.Response [querierv1.SelectSeriesResponse ], profileTypeID string ) * data.Frame {
289
- frame := data .NewFrame ("series" )
290
- frame .Meta = & data.FrameMeta {PreferredVisualization : "graph" }
288
+ func seriesToDataFrames (seriesResp * connect.Response [querierv1.SelectSeriesResponse ], profileTypeID string ) []* data.Frame {
289
+ var frames []* data.Frame
291
290
292
- fields := data.Fields {}
293
- timeField := data .NewField ("time" , nil , []time.Time {})
294
- fields = append (fields , timeField )
291
+ for _ , series := range seriesResp .Msg .Series {
292
+ // We create separate data frames as the series may not have the same length
293
+ frame := data .NewFrame ("series" )
294
+ frame .Meta = & data.FrameMeta {PreferredVisualization : "graph" }
295
+
296
+ fields := data.Fields {}
297
+ timeField := data .NewField ("time" , nil , []time.Time {})
298
+ fields = append (fields , timeField )
295
299
296
- for index , series := range seriesResp .Msg .Series {
297
300
label := ""
298
301
unit := ""
299
- if len (series .Labels ) > 0 {
300
- label = series .Labels [0 ].Name
301
- } else {
302
- parts := strings .Split (profileTypeID , ":" )
303
- if len (parts ) == 5 {
304
- label = parts [1 ] // sample type e.g. cpu, goroutine, alloc_objects
305
- unit = normalizeUnit (parts [2 ])
306
- }
302
+ parts := strings .Split (profileTypeID , ":" )
303
+ if len (parts ) == 5 {
304
+ label = parts [1 ] // sample type e.g. cpu, goroutine, alloc_objects
305
+ unit = normalizeUnit (parts [2 ])
306
+ }
307
+
308
+ labels := make (map [string ]string )
309
+ for _ , label := range series .Labels {
310
+ labels [label .Name ] = label .Value
307
311
}
308
- valueField := data .NewField (label , nil , []float64 {})
312
+
313
+ valueField := data .NewField (label , labels , []float64 {})
309
314
valueField .Config = & data.FieldConfig {Unit : unit }
310
315
311
316
for _ , point := range series .Points {
312
- if index == 0 {
313
- timeField .Append (time .UnixMilli (point .Timestamp ))
314
- }
317
+ timeField .Append (time .UnixMilli (point .Timestamp ))
315
318
valueField .Append (point .Value )
316
319
}
317
320
318
321
fields = append (fields , valueField )
322
+ frame .Fields = fields
323
+ frames = append (frames , frame )
319
324
}
320
-
321
- frame .Fields = fields
322
- return frame
325
+ return frames
323
326
}
324
327
325
328
func normalizeUnit (unit string ) string {
0 commit comments