in pkg/graphql/dashboard/global.go [174:202]
func responseLatency(ctx context.Context, duration api.Duration) map[string]map[string]*displayable.MetricValue {
template, err := LoadTemplate(ctx.Value(contextkey.DashboardTemplate{}).(string))
if err != nil {
return nil
}
// Check if there is a template of response latency.
if template.ResponseLatency == (ChartTemplate{}) {
return nil
}
// Labels in the template file is string type, like "0, 1, 2",
// need use ", " to split into string array for graphql query.
labels := strings.Split(template.ResponseLatency.Labels, ",")
relabels := strings.Split(template.ResponseLatency.Relabels, ",")
responseLatency, err := metrics.MultipleLinearIntValues(ctx, template.ResponseLatency.Condition, labels, duration)
if err != nil {
logger.Log.Fatalln(err)
}
mapping := make(map[string]string, len(labels))
for i := range labels {
mapping[labels[i]] = relabels[i]
}
// Convert metrics values to map type data.
return utils.MetricsValuesArrayToMap(duration, responseLatency, mapping)
}