in pkg/sls-plugin.go [857:909]
func (ds *SlsDatasource) BuildTimingGraph(logs []map[string]string, xcol string, ycols []string, keys []string, frames *data.Frames) {
ds.SortLogs(logs, xcol)
var frame *data.Frame
if compatible {
frame = data.NewFrame("response")
} else {
frame = data.NewFrame("")
}
fieldMap := make(map[string][]*float64)
var times []time.Time
if len(ycols) == 1 && ycols[0] == "" && len(keys) > 0 {
ycols = keys
}
for _, v := range ycols {
if v != xcol {
fieldMap[v] = make([]*float64, 0)
}
}
for _, alog := range logs {
for k, v := range alog {
if fieldMap[k] != nil {
// 判断一下这个v 是不是'null'
if v == "null" {
fieldMap[k] = append(fieldMap[k], nil)
} else {
floatV, err := strconv.ParseFloat(v, 64)
if err != nil {
log.DefaultLogger.Debug("BuildTimingGraph", "ParseFloat", err, "value", v)
}
fieldMap[k] = append(fieldMap[k], &floatV)
}
}
if xcol != "" && xcol == k {
times = append(times, toTime(v))
}
}
}
var frameLen int
for _, v := range fieldMap {
if len(v) > frameLen {
frameLen = len(v)
}
}
if len(times) == frameLen {
frame.Fields = append(frame.Fields, data.NewField("time", nil, times))
}
for _, v := range ycols {
if field, ok := fieldMap[v]; ok && len(field) == frameLen {
frame.Fields = append(frame.Fields, data.NewField(v, nil, field))
}
}
*frames = append(*frames, frame)
}