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

x-pack/metricbeat/module/gcp: Override GCP API endpoint in metric client #40918

Merged
merged 5 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Mark system process metricsets as running if metrics are partially available {pull}40565[40565]
- Added back `elasticsearch.node.stats.jvm.mem.pools.*` to the `node_stats` metricset {pull}40571[40571]
- Add GCP organization and project details to ECS cloud fields. {pull}40461[40461]
- Add `endpoint` field to the GCP configuration in order to append it to the metric client. {issue}40848[40848] {pull}40918[40918]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Add `endpoint` field to the GCP configuration in order to append it to the metric client. {issue}40848[40848] {pull}40918[40918]
- Add support for specifying a custom endpoint for GCP service clients. {issue}40848[40848] {pull}40918[40918]


*Osquerybeat*

Expand Down
12 changes: 12 additions & 0 deletions metricbeat/docs/modules/gcp.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ and metadata information from metricsets and fetch metrics only. At the moment,

* *period*: A single time duration specified for this module collection frequency.

* *endpoint*: A custom endpoint to use for the GCP API calls. If not specified, the default endpoint will be used.

[float]
== Example configuration
* `compute` metricset is enabled to collect metrics from `us-central1-a` zone
Expand Down Expand Up @@ -379,6 +381,16 @@ metricbeat.modules:
credentials_file_path: "your JSON credentials file path"
dataset_id: "dataset id"
table_pattern: "table pattern"

- module: gcp
metricsets:
- compute
region: "us-"
project_id: "your project id"
credentials_file_path: "your JSON credentials file path"
endpoint: http://your-endpoint
exclude_labels: false
period: 1m
----

[float]
Expand Down
10 changes: 10 additions & 0 deletions x-pack/metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,16 @@ metricbeat.modules:
dataset_id: "dataset id"
table_pattern: "table pattern"

- module: gcp
metricsets:
- compute
region: "us-"
project_id: "your project id"
credentials_file_path: "your JSON credentials file path"
endpoint: http://your-endpoint
exclude_labels: false
period: 1m

#-------------------------------- Golang Module --------------------------------
- module: golang
#metricsets:
Expand Down
10 changes: 10 additions & 0 deletions x-pack/metricbeat/module/gcp/_meta/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,13 @@
credentials_file_path: "your JSON credentials file path"
dataset_id: "dataset id"
table_pattern: "table pattern"

- module: gcp
metricsets:
- compute
region: "us-"
project_id: "your project id"
credentials_file_path: "your JSON credentials file path"
endpoint: http://your-endpoint
exclude_labels: false
period: 1m
Copy link
Contributor

Choose a reason for hiding this comment

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

The yaml block is not properly formatted and it might be redundant to add it again just to showcase the endpoint config param. I would probably add endpoint to an existing config in that file.

2 changes: 2 additions & 0 deletions x-pack/metricbeat/module/gcp/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ and metadata information from metricsets and fetch metrics only. At the moment,

* *period*: A single time duration specified for this module collection frequency.

* *endpoint*: A custom endpoint to use for the GCP API calls. If not specified, the default endpoint will be used.

[float]
== Example configuration
* `compute` metricset is enabled to collect metrics from `us-central1-a` zone
Expand Down
16 changes: 10 additions & 6 deletions x-pack/metricbeat/module/gcp/metrics/metricset.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ type config struct {
ExcludeLabels bool `config:"exclude_labels"`
CredentialsFilePath string `config:"credentials_file_path"`
CredentialsJSON string `config:"credentials_json"`

opt []option.ClientOption
period *durationpb.Duration
organizationID string
organizationName string
projectName string
Endpoint string `config:"endpoint"`
opt []option.ClientOption
period *durationpb.Duration
organizationID string
organizationName string
projectName string
Copy link
Contributor

@gpop63 gpop63 Sep 20, 2024

Choose a reason for hiding this comment

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

Let's keep a new line between these exported and unexported struct fields like it was before.

Suggested change
Endpoint string `config:"endpoint"`
opt []option.ClientOption
period *durationpb.Duration
organizationID string
organizationName string
projectName string
Endpoint string `config:"endpoint"`
opt []option.ClientOption
period *durationpb.Duration
organizationID string
organizationName string
projectName string

}

// New creates a new instance of the MetricSet. New is responsible for unpacking
Expand Down Expand Up @@ -143,6 +143,10 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
} else {
return m, fmt.Errorf("no credentials_file_path or credentials_json specified")
}
if m.config.Endpoint != "" {
m.Logger().Warnf("You are using a custom endpoint '%s' for the GCP API calls.", m.config.Endpoint)
m.config.opt = append(m.config.opt, option.WithEndpoint(m.config.Endpoint))
}
Comment on lines +148 to +151
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a new line to improve readability.

Suggested change
if m.config.Endpoint != "" {
m.Logger().Warnf("You are using a custom endpoint '%s' for the GCP API calls.", m.config.Endpoint)
m.config.opt = append(m.config.opt, option.WithEndpoint(m.config.Endpoint))
}
if m.config.Endpoint != "" {
m.Logger().Warnf("You are using a custom endpoint '%s' for the GCP API calls.", m.config.Endpoint)
m.config.opt = append(m.config.opt, option.WithEndpoint(m.config.Endpoint))
}


m.config.period = &durationpb.Duration{
Seconds: int64(m.Module().Config().Period.Seconds()),
Expand Down
10 changes: 10 additions & 0 deletions x-pack/metricbeat/modules.d/gcp.yml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,13 @@
credentials_file_path: "your JSON credentials file path"
dataset_id: "dataset id"
table_pattern: "table pattern"

- module: gcp
metricsets:
- compute
region: "us-"
project_id: "your project id"
credentials_file_path: "your JSON credentials file path"
endpoint: http://your-endpoint
exclude_labels: false
period: 1m
Loading