Skip to content

Commit

Permalink
prometheus scaler: handle errors from Prometheus server (#1497)
Browse files Browse the repository at this point in the history
* prometheus scaler: handle errors from Prometheus server

When there is a typo or some other error in query, prometheus server returns
non-2xx response, which is being ignored silently. This checks for response
code and returns appropriate error

Signed-off-by: Suresh Kumar <sureshkumar.pp@gmail.com>

* Update changelog

Signed-off-by: Suresh Kumar <sureshkumar.pp@gmail.com>
  • Loading branch information
surki committed Jan 12, 2021
1 parent aa0ea79 commit c09a1e3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- Automatically determine the RabbitMQ protocol when possible, and support setting the protocl via TriggerAuthentication ([#1459](https://github.com/kedacore/keda/pulls/1459),[#1483](https://github.com/kedacore/keda/pull/1483))
- Improve performance when fetching pod information ([#1457](https://github.com/kedacore/keda/pull/1457))
- Improve performance when fetching current scaling information on Deployments ([#1458](https://github.com/kedacore/keda/pull/1458))
- Improve error reporting in prometheus scaler ([PR #1497](https://github.com/kedacore/keda/pull/1497))

### Breaking Changes

Expand Down
4 changes: 4 additions & 0 deletions pkg/scalers/prometheus_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ func (s *prometheusScaler) ExecutePromQuery() (float64, error) {
}
r.Body.Close()

if !(r.StatusCode >= 200 && r.StatusCode <= 299) {
return -1, fmt.Errorf("prometheus query api returned error. status: %d response: %s", r.StatusCode, string(b))
}

var result promQueryResult
err = json.Unmarshal(b, &result)
if err != nil {
Expand Down

0 comments on commit c09a1e3

Please sign in to comment.