Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions plugins/outputs/stackdriver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ 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 charged for metric ingestion quota.
## If omitted, the quota is charged to the project associated with the service account.
## This is useful when sending metrics to multiple projects using a single service account,
## ensuring that the target projects are billed instead of the service account's project.
##
## The caller must have the `serviceusage.services.use` permission on the specified quota project.
# quota_project = "billing-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.
Expand Down
9 changes: 9 additions & 0 deletions plugins/outputs/stackdriver/sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
## GCP Project
project = "erudite-bloom-151019"

## Quota Project
## Specifies the Google Cloud project that should be charged for metric ingestion quota.
## If omitted, the quota is charged to the project associated with the service account.
## This is useful when sending metrics to multiple projects using a single service account,
## ensuring that the target projects are billed instead of the service account's project.
##
## The caller must have the `serviceusage.services.use` permission on the specified quota project.
# quota_project = "billing-project"

Comment on lines +6 to +14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the default is empty isn't it? So how about shortening this to

Suggested change
## Quota Project
## Specifies the Google Cloud project that should be charged for metric ingestion quota.
## If omitted, the quota is charged to the project associated with the service account.
## This is useful when sending metrics to multiple projects using a single service account,
## ensuring that the target projects are billed instead of the service account's project.
##
## The caller must have the `serviceusage.services.use` permission on the specified quota project.
# quota_project = "billing-project"
## Quota Project to charge for metric ingestion quota
## If omitted, the quota is charged to the project associated with the service account.
## The caller must have the `serviceusage.services.use` permission on the specified quota project.
# quota_project = ""

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there! So I guess the only concern I would have is that we removed the explanation as to what this would be used for, sending to multiple projects using a single SA while pointing the quota at the destination project instead of the SA project.

How about this?

## 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.
Expand Down
13 changes: 12 additions & 1 deletion plugins/outputs/stackdriver/stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
}
Expand Down
Loading