feat(outputs.stackdriver): Ensure quota is charged to configured project (#16583)

Co-authored-by: root <root@lpce28af8.homedepot.com>
This commit is contained in:
crflanigan 2025-03-19 11:22:39 -05:00 committed by GitHub
parent f1f32d721b
commit ceeb291e15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 1 deletions

View File

@ -36,6 +36,13 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
## GCP Project
project = "erudite-bloom-151019"
## Quota Project
## Specifies the Google Cloud project that should be billed for metric ingestion.
## If omitted, the quota is charged to the service accounts default project.
## This is useful when sending metrics to multiple projects using a single service account.
## The caller must have the `serviceusage.services.use` permission on the specified project.
# quota_project = ""
## The namespace for the metric descriptor
## This is optional and users are encouraged to set the namespace as a
## resource label instead. If omitted it is not included in the metric name.

View File

@ -3,6 +3,13 @@
## GCP Project
project = "erudite-bloom-151019"
## Quota Project
## Specifies the Google Cloud project that should be billed for metric ingestion.
## If omitted, the quota is charged to the service accounts default project.
## This is useful when sending metrics to multiple projects using a single service account.
## The caller must have the `serviceusage.services.use` permission on the specified project.
# quota_project = ""
## The namespace for the metric descriptor
## This is optional and users are encouraged to set the namespace as a
## resource label instead. If omitted it is not included in the metric name.

View File

@ -33,6 +33,7 @@ var sampleConfig string
// Stackdriver is the Google Stackdriver config info.
type Stackdriver struct {
Project string `toml:"project"`
QuotaProject string `toml:"quota_project"`
Namespace string `toml:"namespace"`
ResourceType string `toml:"resource_type"`
ResourceLabels map[string]string `toml:"resource_labels"`
@ -136,9 +137,19 @@ func (s *Stackdriver) Connect() error {
s.ResourceLabels["project_id"] = s.Project
// Define client options, starting with the user agent
options := []option.ClientOption{
option.WithUserAgent(internal.ProductToken()),
}
if s.QuotaProject != "" {
options = append(options, option.WithQuotaProject(s.QuotaProject))
s.Log.Infof("Using QuotaProject %s for quota attribution", s.QuotaProject)
}
if s.client == nil {
ctx := context.Background()
client, err := monitoring.NewMetricClient(ctx, option.WithUserAgent(internal.ProductToken()))
client, err := monitoring.NewMetricClient(ctx, options...)
if err != nil {
return err
}