Exemplo n.º 1
0
func viewAdapterForInstantQuery(node Node, timestamp time.Time) (viewAdapter *viewAdapter, err error) {
	analyzer := NewQueryAnalyzer()
	analyzer.AnalyzeQueries(node)
	viewBuilder := metric.NewViewRequestBuilder()
	for fingerprint, rangeDuration := range analyzer.FullRanges {
		viewBuilder.GetMetricRange(fingerprint, timestamp.Add(-rangeDuration), timestamp)
	}
	for fingerprint := range analyzer.IntervalRanges {
		viewBuilder.GetMetricAtTime(fingerprint, timestamp)
	}
	view, err := queryStorage.MakeView(viewBuilder, time.Duration(60)*time.Second)
	if err == nil {
		viewAdapter = NewViewAdapter(view)
	}
	return
}
Exemplo n.º 2
0
func viewAdapterForRangeQuery(node Node, start time.Time, end time.Time, interval time.Duration) (viewAdapter *viewAdapter, err error) {
	analyzer := NewQueryAnalyzer()
	analyzer.AnalyzeQueries(node)
	viewBuilder := metric.NewViewRequestBuilder()
	for fingerprint, rangeDuration := range analyzer.FullRanges {
		// TODO: we should support GetMetricRangeAtInterval() or similar ops in the view builder.
		for t := start; t.Before(end); t = t.Add(interval) {
			viewBuilder.GetMetricRange(fingerprint, t.Add(-rangeDuration), t)
		}
	}
	for fingerprint := range analyzer.IntervalRanges {
		viewBuilder.GetMetricAtInterval(fingerprint, start, end, interval)
	}
	view, err := queryStorage.MakeView(viewBuilder, time.Duration(60)*time.Second)
	if err == nil {
		viewAdapter = NewViewAdapter(view)
	}
	return
}