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
|
## GCP Project
|
||||||
project = "erudite-bloom-151019"
|
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
|
## The namespace for the metric descriptor
|
||||||
## This is optional and users are encouraged to set the namespace as a
|
## 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.
|
## resource label instead. If omitted it is not included in the metric name.
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,13 @@
|
||||||
## GCP Project
|
## GCP Project
|
||||||
project = "erudite-bloom-151019"
|
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
|
## The namespace for the metric descriptor
|
||||||
## This is optional and users are encouraged to set the namespace as a
|
## 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.
|
## 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.
|
// Stackdriver is the Google Stackdriver config info.
|
||||||
type Stackdriver struct {
|
type Stackdriver struct {
|
||||||
Project string `toml:"project"`
|
Project string `toml:"project"`
|
||||||
|
QuotaProject string `toml:"quota_project"`
|
||||||
Namespace string `toml:"namespace"`
|
Namespace string `toml:"namespace"`
|
||||||
ResourceType string `toml:"resource_type"`
|
ResourceType string `toml:"resource_type"`
|
||||||
ResourceLabels map[string]string `toml:"resource_labels"`
|
ResourceLabels map[string]string `toml:"resource_labels"`
|
||||||
|
|
@ -136,9 +137,19 @@ func (s *Stackdriver) Connect() error {
|
||||||
|
|
||||||
s.ResourceLabels["project_id"] = s.Project
|
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 {
|
if s.client == nil {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
client, err := monitoring.NewMetricClient(ctx, option.WithUserAgent(internal.ProductToken()))
|
client, err := monitoring.NewMetricClient(ctx, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue