@@ -377,22 +377,27 @@ func (ds *SlsDatasource) BuildFlowGraphV2(logs []map[string]string, xcol string,
377
377
return
378
378
}
379
379
ds .SortLogs (logs , xcol )
380
- metricName := ycols [1 ]
380
+ metricNames := strings .Split (ycols [1 ], "," )
381
+ metricMap := make (map [string ]bool )
382
+ for _ , n := range metricNames {
383
+ metricMap [n ] = true
384
+ }
381
385
var labelNames []string
382
386
for k := range logs [0 ] {
383
- if k != "__source__" && k != "__time__" && k != metricName && k != xcol {
387
+ if k != "__source__" && k != "__time__" && ! metricMap [ k ] && k != xcol {
384
388
labelNames = append (labelNames , k )
385
389
}
386
390
}
387
391
sort .Strings (labelNames )
388
392
timeFields := make (map [string ][]time.Time )
389
- metricFields := make (map [string ][]float64 )
390
-
393
+ nameMetricFields := make (map [string ]map [string ][]float64 )
394
+ for _ , n := range metricNames {
395
+ nameMetricFields [n ] = make (map [string ][]float64 )
396
+ }
391
397
frameLabelsMap := make (map [string ]map [string ]string )
392
398
393
399
for _ , alog := range logs {
394
400
timeVal := alog [xcol ]
395
- metricVal := alog [metricName ]
396
401
labels := map [string ]string {}
397
402
labelsKey := ""
398
403
for _ , l := range labelNames {
@@ -407,20 +412,29 @@ func (ds *SlsDatasource) BuildFlowGraphV2(logs []map[string]string, xcol string,
407
412
} else {
408
413
timeFields [labelsKey ] = []time.Time {toTime (timeVal )}
409
414
}
410
- floatV , err := strconv .ParseFloat (metricVal , 64 )
411
- if err != nil {
412
- log .DefaultLogger .Info ("BuildFlowGraphV2" , "ParseFloat" , err , "value" , metricVal )
413
- }
414
- if _ , ok := metricFields [labelsKey ]; ok {
415
- metricFields [labelsKey ] = append (metricFields [labelsKey ], floatV )
416
- } else {
417
- metricFields [labelsKey ] = []float64 {floatV }
415
+ for _ , n := range metricNames {
416
+ metricVal := alog [n ]
417
+ floatV , err := strconv .ParseFloat (metricVal , 64 )
418
+ if err != nil {
419
+ log .DefaultLogger .Info ("BuildFlowGraphV2" , "ParseFloat" , err , "value" , metricVal )
420
+ }
421
+ if _ , ok := nameMetricFields [n ][labelsKey ]; ok {
422
+ nameMetricFields [n ][labelsKey ] = append (nameMetricFields [n ][labelsKey ], floatV )
423
+ } else {
424
+ nameMetricFields [n ][labelsKey ] = []float64 {floatV }
425
+ }
418
426
}
419
427
}
420
428
for k , v := range timeFields {
421
429
frame := data .NewFrame ("" )
422
430
frame .Fields = append (frame .Fields , data .NewField ("Time" , nil , v ))
423
- frame .Fields = append (frame .Fields , data .NewField ("Value" , frameLabelsMap [k ], metricFields [k ]))
431
+ if len (metricNames ) == 1 {
432
+ frame .Fields = append (frame .Fields , data .NewField ("Value" , frameLabelsMap [k ], nameMetricFields [metricNames [0 ]][k ]))
433
+ } else {
434
+ for _ , n := range metricNames {
435
+ frame .Fields = append (frame .Fields , data .NewField (n , frameLabelsMap [k ], nameMetricFields [n ][k ]))
436
+ }
437
+ }
424
438
* frames = append (* frames , frame )
425
439
}
426
440
}
0 commit comments