Skip to content

Commit 524042b

Browse files
committed
Fix get cluster history from prometheus if job label is empty
1 parent 0255c11 commit 524042b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

vertical-pod-autoscaler/pkg/recommender/input/history/history_provider.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,12 @@ func (p *prometheusHistoryProvider) readLastLabels(res map[model.PodID]*PodHisto
190190

191191
func (p *prometheusHistoryProvider) GetClusterHistory() (map[model.PodID]*PodHistory, error) {
192192
res := make(map[model.PodID]*PodHistory)
193-
podSelector := fmt.Sprintf("job=\"%s\", %s=~\".+\", %s!=\"POD\", %s!=\"\"",
194-
p.config.CadvisorMetricsJobName, p.config.CtrPodNameLabel,
195-
p.config.CtrNameLabel, p.config.CtrNameLabel)
193+
var podSelector string
194+
if p.config.CadvisorMetricsJobName != "" {
195+
podSelector = fmt.Sprintf("job=\"%s\", ", p.config.CadvisorMetricsJobName)
196+
}
197+
podSelector = podSelector + fmt.Sprintf("%s=~\".+\", %s!=\"POD\", %s!=\"\"",
198+
p.config.CtrPodNameLabel, p.config.CtrNameLabel, p.config.CtrNameLabel)
196199

197200
// This query uses Prometheus Subquery notation, to gives us a result of a five minute cpu rate by default evaluated every 1minute for last config.HistoryLength days/hours/minutes. In order to change the evaluation step, you need change Prometheus global.evaluation_interval configuration parameter.
198201
err := p.readResourceHistory(res, fmt.Sprintf("rate(container_cpu_usage_seconds_total{%s}[5m])[%s:]", podSelector, p.config.HistoryLength), model.ResourceCPU)

0 commit comments

Comments
 (0)