Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2] Improved GCP PubSub Scaler performance by closing the client correctly #1087

Merged
merged 2 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- Improve `kubectl get triggerauthentication` to show information about configured parameters ([#778](https://github.com/kedacore/keda/issues/778))
- Added ScaledObject Status Conditions to display status of scaling ([#750](https://github.com/kedacore/keda/pull/750))
- Added optional authentication parameters for the Redis Scaler ([#962](https://github.com/kedacore/keda/pull/962))
- Improved GCP PubSub Scaler performance by closing the client correctly ([#1087](https://github.com/kedacore/keda/pull/1087))

### Breaking Changes

Expand Down
11 changes: 10 additions & 1 deletion pkg/scalers/gcp_pub_sub_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
)

type pubsubScaler struct {
client *StackDriverClient
metadata *pubsubMetadata
}

Expand Down Expand Up @@ -92,6 +93,14 @@ func (s *pubsubScaler) IsActive(ctx context.Context) (bool, error) {
}

func (s *pubsubScaler) Close() error {

if s.client != nil {
err := s.client.metricsClient.Close()
if err != nil {
gcpPubSubLog.Error(err, "error closing StackDriver client")
}
}

return nil
}

Expand Down Expand Up @@ -142,10 +151,10 @@ func (s *pubsubScaler) GetMetrics(ctx context.Context, metricName string, metric
// Stackdriver api
func (s *pubsubScaler) GetSubscriptionSize(ctx context.Context) (int64, error) {
client, err := NewStackDriverClient(ctx, s.metadata.credentials)

if err != nil {
return -1, err
}
s.client = client

filter := `metric.type="` + pubSubStackDriverMetricName + `" AND resource.labels.subscription_id="` + s.metadata.subscriptionName + `"`

Expand Down
2 changes: 1 addition & 1 deletion pkg/scalers/gcp_pubsub_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestGcpPubSubGetMetricSpecForScaling(t *testing.T) {
if err != nil {
t.Fatal("Could not parse metadata:", err)
}
mockGcpPubSubScaler := pubsubScaler{meta}
mockGcpPubSubScaler := pubsubScaler{nil, meta}

metricSpec := mockGcpPubSubScaler.GetMetricSpecForScaling()
metricName := metricSpec[0].External.Metric.Name
Expand Down