Skip to content

Commit

Permalink
GCP Storage scaler: Add Prefix and Delimiter support
Browse files Browse the repository at this point in the history
Signed-off-by: Ward Loos <ward@banked.com>
  • Loading branch information
wrdls committed Oct 26, 2022
1 parent 74d84a6 commit bfd56da
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
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

0 comments on commit bfd56da

Please sign in to comment.