func responseLatency()

in pkg/graphql/dashboard/global.go [171:200]


func responseLatency(ctx *cli.Context, duration api.Duration) map[string]map[string]*displayable.MetricValue {
	template, err := LoadTemplate(ctx.String("template"))
	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 := 0; i < len(labels); i++ {
		mapping[labels[i]] = relabels[i]
	}

	// Convert metrics values to map type data.
	return utils.MetricsValuesArrayToMap(duration, responseLatency, mapping)
}