add endTime variable for promeClient.Series api

Signed-off-by: 屈骏 <qujun@tiduyun.com>
This commit is contained in:
屈骏 2020-07-22 10:51:08 +08:00
parent 6e05ab938e
commit 5e169f5b0d
3 changed files with 6 additions and 3 deletions

View file

@ -218,6 +218,7 @@ type selectorSeries struct {
func (l *cachingMetricsLister) updateMetrics() error {
startTime := pmodel.Now().Add(-1 * l.maxAge)
endTime := pmodel.Now().Add(1 * l.maxAge)
// don't do duplicate queries when it's just the matchers that change
seriesCacheByQuery := make(map[prom.Selector][]prom.Series)
@ -236,7 +237,7 @@ func (l *cachingMetricsLister) updateMetrics() error {
}
selectors[sel] = struct{}{}
go func() {
series, err := l.promClient.Series(context.TODO(), pmodel.Interval{startTime, 0}, sel)
series, err := l.promClient.Series(context.TODO(), pmodel.Interval{startTime, endTime}, sel)
if err != nil {
errs <- fmt.Errorf("unable to fetch metrics for query %q: %v", sel, err)
return

View file

@ -87,7 +87,8 @@ var _ = Describe("Custom Metrics Provider", func() {
By("setting the acceptible interval to now until the next update, with a bit of wiggle room")
startTime := pmodel.Now().Add(-1*fakeProviderUpdateInterval - fakeProviderUpdateInterval/10)
fakeProm.AcceptableInterval = pmodel.Interval{Start: startTime, End: 0}
endTime := pmodel.Now().Add(1*fakeProviderUpdateInterval + fakeProviderUpdateInterval/10)
fakeProm.AcceptableInterval = pmodel.Interval{Start: startTime, End: endTime}
By("updating the list of available metrics")
// don't call RunUntil to avoid timing issue

View file

@ -84,6 +84,7 @@ func (l *basicMetricLister) ListAllMetrics() (MetricUpdateResult, error) {
}
startTime := pmodel.Now().Add(-1 * l.lookback)
endTime := pmodel.Now().Add(1 * l.lookback)
// these can take a while on large clusters, so launch in parallel
// and don't duplicate
@ -99,7 +100,7 @@ func (l *basicMetricLister) ListAllMetrics() (MetricUpdateResult, error) {
}
selectors[sel] = struct{}{}
go func() {
series, err := l.promClient.Series(context.TODO(), pmodel.Interval{startTime, 0}, sel)
series, err := l.promClient.Series(context.TODO(), pmodel.Interval{startTime, endTime}, sel)
if err != nil {
errs <- fmt.Errorf("unable to fetch metrics for query %q: %v", sel, err)
return