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

GCP Storage scaler: Add Prefix and Delimiter support #3774

Merged
merged 1 commit into from
Nov 3, 2022
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 @@ -54,6 +54,7 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio
- **Apache Kafka Scaler:** SASL/OAuthbearer Implementation ([#3681](https://github.com/kedacore/keda/issues/3681))
- **Azure AD Pod Identity Authentication:** Improve error messages to emphasize problems around the integration with aad-pod-identity itself ([#3610](https://github.com/kedacore/keda/issues/3610))
- **Azure Pipelines Scaler:** Improved speed of profiling large set of Job Requests from Azure Pipelines ([#3702](https://github.com/kedacore/keda/issues/3702))
- **GCP Storage Scaler:** Add prefix and delimiter support ([#3756](https://github.com/kedacore/keda/issues/3756))
- **Prometheus Scaler:** Introduce skipping of certificate check for unsigned certs ([#2310](https://github.com/kedacore/keda/issues/2310))

### Fixes
Expand Down
12 changes: 11 additions & 1 deletion pkg/scalers/gcp_storage_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type gcsMetadata struct {
metricName string
targetObjectCount int64
activationTargetObjectCount int64
blobDelimiter string
blobPrefix string
}

// NewGcsScaler creates a new gcsScaler
Expand Down Expand Up @@ -136,6 +138,14 @@ func parseGcsMetadata(config *ScalerConfig, logger logr.Logger) (*gcsMetadata, e
meta.maxBucketItemsToScan = maxBucketItemsToScan
}

if val, ok := config.TriggerMetadata["blobDelimiter"]; ok {
meta.blobDelimiter = val
}

if val, ok := config.TriggerMetadata["blobPrefix"]; ok {
meta.blobPrefix = val
}

auth, err := getGcpAuthorization(config, config.ResolvedEnv)
if err != nil {
return nil, err
Expand Down Expand Up @@ -191,7 +201,7 @@ func (s *gcsScaler) GetMetrics(ctx context.Context, metricName string, metricSel

// getItemCount gets the number of items in the bucket, up to maxCount
func (s *gcsScaler) getItemCount(ctx context.Context, maxCount int64) (int64, error) {
query := &storage.Query{Prefix: ""}
query := &storage.Query{Delimiter: s.metadata.blobDelimiter, Prefix: s.metadata.blobPrefix}
err := query.SetAttrSelection([]string{"Name"})
if err != nil {
s.logger.Error(err, "failed to set attribute selection")
Expand Down
2 changes: 1 addition & 1 deletion pkg/scalers/gcp_storage_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type gcpGcsMetricIdentifier struct {
var testGcsMetadata = []parseGcsMetadataTestData{
{map[string]string{}, map[string]string{}, true},
// all properly formed
{nil, map[string]string{"bucketName": "test-bucket", "targetObjectCount": "7", "maxBucketItemsToScan": "100", "credentialsFromEnv": "SAMPLE_CREDS", "activationTargetObjectCount": "5"}, false},
{nil, map[string]string{"bucketName": "test-bucket", "targetObjectCount": "7", "maxBucketItemsToScan": "100", "credentialsFromEnv": "SAMPLE_CREDS", "activationTargetObjectCount": "5", "blobPrefix": "blobsubpath", "blobDelimiter": "/"}, false},
// all properly formed while using defaults
{nil, map[string]string{"bucketName": "test-bucket", "credentialsFromEnv": "SAMPLE_CREDS"}, false},
// missing bucketName
Expand Down