feat(outputs.stackdriver): Ensure quota is charged to configured project (#16583)
Co-authored-by: root <root@lpce28af8.homedepot.com>
This commit is contained in:
parent
f1f32d721b
commit
ceeb291e15
|
|
@ -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 account’s 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.
|
||||
|
|
|
|||
|
|
@ -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 account’s 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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue