Exemplo n.º 1
0
func (m *sequentialMultiBackend) FetchMultipleSeries(request api.FetchMultipleRequest) (api.SeriesList, error) {
	series := make([]api.Timeseries, len(request.Metrics))
	var err error = nil
	for i, metric := range request.Metrics {
		series[i], err = m.Backend.FetchSingleSeries(request.ToSingle(metric))
		if err != nil {
			return api.SeriesList{}, err
		}
	}

	return api.SeriesList{
		Series:    series,
		Timerange: request.Timerange,
	}, nil
}
Exemplo n.º 2
0
func (m *parallelMultiBackend) FetchMultipleSeries(request api.FetchMultipleRequest) (api.SeriesList, error) {
	works := make([]func() (api.Timeseries, error), len(request.Metrics))
	for i, metric := range request.Metrics {
		// Since we want to create a closure, we want to close over this particular metric,
		// rather than the variable itself (which is the same between iterations).
		// We accomplish this here:
		metric := metric
		works[i] = func() (api.Timeseries, error) {
			return m.Backend.FetchSingleSeries(request.ToSingle(metric))
		}
	}

	resultSeries, err := m.fetchManyLazy(request.Cancellable, works)
	if err != nil {
		return api.SeriesList{}, err
	}

	return api.SeriesList{
		Series:    resultSeries,
		Timerange: request.Timerange,
	}, nil
}