Skip to content

Commit

Permalink
Pulsar: improve error messages (kedacore#4564)
Browse files Browse the repository at this point in the history
Signed-off-by: Zbynek Roubalik <[email protected]>
  • Loading branch information
zroubalik authored May 22, 2023
1 parent 4dc95fd commit 3c184e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio
- **External Scaler**: Add tls options in TriggerAuth metadata. ([#3565](https://github.com/kedacore/keda/issues/3565))
- **GCP PubSub Scaler**: Make it more flexible for metrics ([#4243](https://github.com/kedacore/keda/issues/4243))
- **Kafka Scaler:** Add support for OAuth extensions ([#4544](https://github.com/kedacore/keda/issues/4544))
- **Pulsar Scaler**: Improve error messages for unsuccessful connections ([#4563](https://github.com/kedacore/keda/issues/4563))
- **Security:** Enable secret scanning in GitHub repo

### Fixes
Expand Down
15 changes: 9 additions & 6 deletions pkg/scalers/pulsar_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,17 @@ func (s *pulsarScaler) GetStats(ctx context.Context) (*pulsarStats, error) {

req, err := http.NewRequestWithContext(ctx, "GET", s.metadata.statsURL, nil)
if err != nil {
return nil, fmt.Errorf("error requesting stats from url: %w", err)
return nil, fmt.Errorf("error requesting stats from admin url: %w", err)
}

addAuthHeaders(req, &s.metadata)

res, err := s.client.Do(req)
if res == nil || err != nil {
return nil, fmt.Errorf("error requesting stats from url: %w", err)
if err != nil {
return nil, fmt.Errorf("error requesting stats from admin url: %w", err)
}
if res == nil {
return nil, fmt.Errorf("error requesting stats from admin url, got empty response")
}

defer res.Body.Close()
Expand All @@ -225,17 +228,17 @@ func (s *pulsarScaler) GetStats(ctx context.Context) (*pulsarStats, error) {
case 200:
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, fmt.Errorf("error requesting stats from url: %w", err)
return nil, fmt.Errorf("error requesting stats from admin url: %w", err)
}
err = json.Unmarshal(body, stats)
if err != nil {
return nil, fmt.Errorf("error unmarshalling response: %w", err)
}
return stats, nil
case 404:
return nil, fmt.Errorf("error requesting stats from url: %w", err)
return nil, fmt.Errorf("error requesting stats from admin url, response status is (404): %s", res.Status)
default:
return nil, fmt.Errorf("error requesting stats from url: %w", err)
return nil, fmt.Errorf("error requesting stats from admin url, response status is: %s", res.Status)
}
}

Expand Down

0 comments on commit 3c184e2

Please sign in to comment.