Skip to content

Commit

Permalink
Fix: GCP pubsub / cloud tasks metric queries for metric scoped projec…
Browse files Browse the repository at this point in the history
…ts (kedacore#5258)

Signed-off-by: anton.lysina <alysina@gmail.com>
  • Loading branch information
DP19 authored and toniiiik committed Jan 15, 2024
1 parent 7a12f47 commit 38454df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
8 changes: 7 additions & 1 deletion pkg/scalers/gcp_stackdriver_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,25 +184,31 @@ 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: &timestamppb.Timestamp{Seconds: startTime.Unix()},
EndTime: &timestamppb.Timestamp{Seconds: endTime.Unix()},
},
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)

Expand Down

0 comments on commit 38454df

Please sign in to comment.