Skip to content

Commit d02a32d

Browse files
committed
Fixed error handling in prometheus plugin
1 parent 99ddf70 commit d02a32d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pkg/scheduler/cache/usagedb/prometheus/prometheus.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ func (p *PrometheusClient) queryResourceUsage(
190190

191191
usageVector := usageResult.(model.Vector)
192192
if len(usageVector) == 0 {
193-
return nil, fmt.Errorf("no data returned for cluster usage metric %s", decayedAllocationMetric)
193+
log.InfraLogger.V(3).Warnf("No data returned for cluster usage metric %s", decayedAllocationMetric)
194+
return queueUsage, nil
194195
}
195196

196197
for _, usageSample := range usageVector {
@@ -206,11 +207,14 @@ func (p *PrometheusClient) queryResourceUsage(
206207
func (p *PrometheusClient) querySlidingTimeWindow(ctx context.Context, decayedAllocationMetric string) (model.Value, promv1.Warnings, error) {
207208
usageQuery := fmt.Sprintf("sum_over_time((%s)[%s:%s])",
208209
decayedAllocationMetric,
209-
p.usageParams.WindowSize.String(),
210+
p.usageParams.WindowSize.Duration.String(),
210211
p.queryResolution.String(),
211212
)
212213

213214
usageResult, warnings, err := p.client.Query(ctx, usageQuery, time.Now())
215+
if err != nil {
216+
err = fmt.Errorf("%w, full query: %s", err, usageQuery)
217+
}
214218
return usageResult, warnings, err
215219
}
216220

@@ -223,6 +227,11 @@ func (p *PrometheusClient) queryTumblingTimeWindow(ctx context.Context, decayedA
223227
End: time.Now(),
224228
Step: p.queryResolution,
225229
})
230+
231+
if err != nil {
232+
err = fmt.Errorf("%w, full query: %s", err, usageQuery)
233+
}
234+
226235
return usageResult, warnings, err
227236
}
228237

0 commit comments

Comments
 (0)