From 9700b8f3a13154b3e062f0f82e413418832467d0 Mon Sep 17 00:00:00 2001 From: David Pait Date: Wed, 6 Dec 2023 17:21:48 -0500 Subject: [PATCH] Fix: GCP pubsub / cloud tasks metric queries for metric scoped projects (#5258) --- CHANGELOG.md | 1 + pkg/scalers/gcp_stackdriver_client.go | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15decae897f..81171cf4bc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,7 @@ Here is an overview of all new **experimental** features: - **General**: Fix otelgrpc DoS vulnerability ([#5208](https://github.com/kedacore/keda/issues/5208)) - **General**: Prevented stuck status due to timeouts during scalers generation ([#5083](https://github.com/kedacore/keda/issues/5083)) - **Azure Pipelines**: No more HTTP 400 errors produced by poolName with spaces ([#5107](https://github.com/kedacore/keda/issues/5107)) +- **GCP pubsub scaler**: Added `project_id` to filter for metrics queries ([#5256](https://github.com/kedacore/keda/issues/5256)) - **GCP pubsub scaler**: Missing use of default value of `value` added ([#5093](https://github.com/kedacore/keda/issues/5093)) - **ScaledJobs**: Copy ScaledJob annotations to child Jobs ([#4594](https://github.com/kedacore/keda/issues/4594)) diff --git a/pkg/scalers/gcp_stackdriver_client.go b/pkg/scalers/gcp_stackdriver_client.go index 5beb42f404f..b759618157d 100644 --- a/pkg/scalers/gcp_stackdriver_client.go +++ b/pkg/scalers/gcp_stackdriver_client.go @@ -184,7 +184,6 @@ func (s StackDriverClient) GetMetrics( // Create a request with the filter and the GCP project ID var req = &monitoringpb.ListTimeSeriesRequest{ - Filter: filter, Interval: &monitoringpb.TimeInterval{ StartTime: ×tamppb.Timestamp{Seconds: startTime.Unix()}, EndTime: ×tamppb.Timestamp{Seconds: endTime.Unix()}, @@ -192,17 +191,24 @@ func (s StackDriverClient) GetMetrics( Aggregation: aggregation, } + // Set project to perform request in and update filter with project_id switch projectID { case "": if len(s.projectID) > 0 { req.Name = "projects/" + s.projectID + filter += ` AND resource.labels.project_id="` + s.projectID + `"` } else { req.Name = "projects/" + s.credentials.ProjectID + filter += ` AND resource.labels.project_id="` + s.credentials.ProjectID + `"` } default: req.Name = "projects/" + projectID + filter += ` AND resource.labels.project_id="` + projectID + `"` } + // Set filter on request + req.Filter = filter + // Get an iterator with the list of time series it := s.metricsClient.ListTimeSeries(ctx, req)