Skip to content

Commit

Permalink
x-pack/metricbeat/module/gcp: Override GCP API endpoint in metric cli…
Browse files Browse the repository at this point in the history
…ent (#40918)

* override endpoint to etric client

* config and changelog

* doc

* resolved comments

* lint fix

(cherry picked from commit 7720c90)
  • Loading branch information
Linu-Elias authored and mergify[bot] committed Sep 21, 2024
1 parent 467121b commit 2356d10
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ 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 support for snapshot in vSphere virtualmachine metricset {pull}40683[40683]
- Add GCP organization and project details to ECS cloud fields. {pull}40461[40461]
- Add support for specifying a custom endpoint for GCP service clients. {issue}40848[40848] {pull}40918[40918]

*Osquerybeat*

Expand Down
3 changes: 3 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 @@ -334,6 +336,7 @@ metricbeat.modules:
period: 24h
project_id: "your project id"
credentials_file_path: "your JSON credentials file path"
endpoint: http://your-endpoint
dataset_id: "dataset id"
table_pattern: "table pattern"
----
Expand Down
1 change: 1 addition & 0 deletions x-pack/metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ metricbeat.modules:
period: 24h
project_id: "your project id"
credentials_file_path: "your JSON credentials file path"
endpoint: http://your-endpoint
dataset_id: "dataset id"
table_pattern: "table pattern"

Expand Down
1 change: 1 addition & 0 deletions x-pack/metricbeat/module/gcp/_meta/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@
period: 24h
project_id: "your project id"
credentials_file_path: "your JSON credentials file path"
endpoint: http://your-endpoint
dataset_id: "dataset id"
table_pattern: "table pattern"
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
6 changes: 6 additions & 0 deletions x-pack/metricbeat/module/gcp/metrics/metricset.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ type config struct {
ExcludeLabels bool `config:"exclude_labels"`
CredentialsFilePath string `config:"credentials_file_path"`
CredentialsJSON string `config:"credentials_json"`
Endpoint string `config:"endpoint"`

opt []option.ClientOption
period *durationpb.Duration
Expand Down Expand Up @@ -139,6 +140,11 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
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))
}

m.config.period = &durationpb.Duration{
Seconds: int64(m.Module().Config().Period.Seconds()),
}
Expand Down
1 change: 1 addition & 0 deletions x-pack/metricbeat/modules.d/gcp.yml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@
period: 24h
project_id: "your project id"
credentials_file_path: "your JSON credentials file path"
endpoint: http://your-endpoint
dataset_id: "dataset id"
table_pattern: "table pattern"

0 comments on commit 2356d10

Please sign in to comment.