func()

in metrics/internal/metrics/consul/consul.go [181:217]


func (c *Client) GetAllMetricValues(metric string) (map[string]float64, error) {
	kv := c.client.KV()

	treeKey := metricTree(metric)
	pairs, _, err := kv.List(treeKey, nil)
	if err != nil {
		c.logger.
			WithError(err).
			WithField("key", treeKey).
			Errorf("Failed to get list of keys")

		return nil, err
	}

	values := make(map[string]float64)
	for _, pair := range pairs {
		if pair.Value == nil {
			continue
		}

		metricValue, err := c.getMetricValue(pair.Value)
		if err != nil {
			logrus.
				WithError(err).
				WithField("metric", metric).
				WithField("key", pair.Key).
				Errorf("Could not parse metric value from Consul")

			continue
		}

		labels := labelsFromKey(pair.Key)
		values[labels] = metricValue
	}

	return values, nil
}