Skip to content

Commit

Permalink
dco sign (kedacore#2739)
Browse files Browse the repository at this point in the history
Signed-off-by: Friedrich Albert Kyuri <friedrichak42@gmail.com>
Signed-off-by: Ram Cohen <ram.cohen@gmail.com>
  • Loading branch information
fira42073 authored and RamCohen committed Mar 23, 2022
1 parent 5243a81 commit 5151e1f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
- **Datadog Scaler:** Several improvements, including a new optional parameter `metricUnavailableValue` to fill data when no Datadog metric was returned ([#2657](https://github.com/kedacore/keda/issues/2657))
- **GCP Pubsub Scaler** Adding e2e test for GCP PubSub scaler ([#1528](https://github.com/kedacore/keda/issues/1528))
- **Kafka Scaler** Make "disable" a valid value for tls auth parameter ([#2608](https://github.com/kedacore/keda/issues/2608))
- **Metric API Scaler:** Improve error handling on not-ok response ([#2317](https://github.com/kedacore/keda/issues/2317))
- **Prometheus Scaler:** Support for `X-Scope-OrgID` header in Prometheus scaler ([#2667](https://github.com/kedacore/keda/issues/2667))
- **RabbitMQ Scaler:** Include `vhost` for RabbitMQ when retrieving queue info with `useRegex` ([#2498](https://github.com/kedacore/keda/issues/2498))

Expand Down
4 changes: 2 additions & 2 deletions pkg/scalers/metrics_api_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@ func (s *metricsAPIScaler) getMetricValue(ctx context.Context) (*resource.Quanti
if err != nil {
return nil, err
}
defer r.Body.Close()

if r.StatusCode != http.StatusOK {
msg := fmt.Sprintf("api returned %d", r.StatusCode)
msg := fmt.Sprintf("%s: api returned %d", r.Request.URL.Path, r.StatusCode)
return nil, errors.New(msg)
}

defer r.Body.Close()
b, err := ioutil.ReadAll(r.Body)
if err != nil {
return nil, err
Expand Down
30 changes: 30 additions & 0 deletions pkg/scalers/metrics_api_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package scalers
import (
"context"
"fmt"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"testing"
"time"

"github.com/stretchr/testify/mock"
)

type metricsAPIMetadataTestData struct {
Expand Down Expand Up @@ -213,3 +216,30 @@ func TestBearerAuth(t *testing.T) {
t.Errorf("Error getting the metric")
}
}

type MockHTTPRoundTripper struct {
mock.Mock
}

func (m *MockHTTPRoundTripper) RoundTrip(request *http.Request) (*http.Response, error) {
args := m.Called(request)
resp := args.Get(0).(*http.Response)
resp.Request = request
return resp, args.Error(1)
}

func TestGetMetricValueErrorMessage(t *testing.T) {
// mock roundtripper to return non-ok status code
mockHTTPRoundTripper := MockHTTPRoundTripper{}
mockHTTPRoundTripper.On("RoundTrip", mock.Anything).Return(&http.Response{StatusCode: http.StatusTeapot}, nil)

httpClient := http.Client{Transport: &mockHTTPRoundTripper}
s := metricsAPIScaler{
metadata: &metricsAPIScalerMetadata{url: "http://dummy:1230/api/v1/"},
client: &httpClient,
}

_, err := s.getMetricValue(context.TODO())

assert.Equal(t, err.Error(), "/api/v1/: api returned 418")
}

0 comments on commit 5151e1f

Please sign in to comment.