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

Support location_label config in GCP Metrics Metricset #41626

Merged
merged 11 commits into from
Dec 2, 2024
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Bump aerospike-client-go to version v7.7.1 and add support for basic auth in Aerospike module {pull}41233[41233]
- Only watch metadata for ReplicaSets in metricbeat k8s module {pull}41289[41289]
- Add support for region/zone for Vertex AI service in GCP module {pull}41551[41551]
- Add support for location label as a configuration parameter in GCP metrics metricset. {issue}41550[41550] {pull}41626[41626]
ishleenk17 marked this conversation as resolved.
Show resolved Hide resolved

*Metricbeat*

Expand Down
1 change: 1 addition & 0 deletions metricbeat/docs/modules/gcp.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ metricbeat.modules:
credentials_file_path: "your JSON credentials file path"
exclude_labels: false
period: 1m
location_label: "resource.labels.zone"
ishleenk17 marked this conversation as resolved.
Show resolved Hide resolved
metrics:
- aligner: ALIGN_NONE
service: compute
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 @@ -618,6 +618,7 @@ metricbeat.modules:
credentials_file_path: "your JSON credentials file path"
exclude_labels: false
period: 1m
location_label: "resource.labels.zone"
metrics:
- aligner: ALIGN_NONE
service: compute
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 @@ -34,6 +34,7 @@
credentials_file_path: "your JSON credentials file path"
exclude_labels: false
period: 1m
location_label: "resource.labels.zone"
metrics:
- aligner: ALIGN_NONE
service: compute
Expand Down
27 changes: 27 additions & 0 deletions x-pack/metricbeat/module/gcp/metrics/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ services under "Google Cloud metrics", but does not work for other services
(`kubernetes` aka GKE for example).
This option allow to override the default and specify an arbitrary metric prefix.

* *location_label*: Use this option to specify the resource label that identifies the location (such as zone or region) for a Google Cloud service when filtering metrics. For example, labels like `resource.label.location` or `resource.label.zone` are used by Google Cloud to represent the region or zone of a resource.
ishleenk17 marked this conversation as resolved.
Show resolved Hide resolved

[float]
=== Example Configuration
* `metrics` metricset is enabled to collect metrics from all zones under
Expand Down Expand Up @@ -134,3 +136,28 @@ metric prefix, as for GKE metrics the required prefix is `kubernetes.io/`
metric_types:
- "container/cpu/core_usage_time"
----

* `metrics` metricset is enabled to collect metrics from region
`us-east4` in `elastic-observability` project. The metric, number of replicas of the prediction model is
collected from a new GCP service `aiplatform`. Since its a new service which is not supported by
default in this metricset, the user provides the servicelabel (resource.label.location), for which
user wants to filter the incoming data

+
[source,yaml]
----
- module: gcp
metricsets:
- metrics
project_id: "elastic-observability"
credentials_json: "your JSON credentials"
exclude_labels: false
period: 1m
location_label: "resource.label.location"
regions:
- us-east4
metrics:
- service: aiplatform
metric_types:
- "prediction/online/replicas"
----
4 changes: 4 additions & 0 deletions x-pack/metricbeat/module/gcp/metrics/metrics_requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ func (r *metricsRequester) getFilterForMetric(serviceName, m string) string {
// to apply any additional filters.
if locationsConfigsAvailable && !isAGlobalService(serviceName) {
serviceLabel := getServiceLabelFor(serviceName)
// If user has entered a location label, overide the serviceLabel with the locationlabel
if r.config.LocationLabel != "" {
ishleenk17 marked this conversation as resolved.
Show resolved Hide resolved
serviceLabel = r.config.LocationLabel
}
ishleenk17 marked this conversation as resolved.
Show resolved Hide resolved
f = r.buildLocationFilter(serviceLabel, f)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ func TestGetFilterForMetric(t *testing.T) {
metricsRequester{config: config{Region: "foobar", Regions: []string{"foo", "bar"}}, logger: logger},
"metric.type=\"dummy\" AND resource.labels.zone = starts_with(\"foobar\")",
},
{
"aiplatform service with configured region and zone",
"aiplatform",
"",
metricsRequester{config: config{Region: "foo", Zone: "bar", LocationLabel: "resource.label.location"}, logger: logger},
"metric.type=\"dummy\" AND resource.label.location = starts_with(\"foo\")",
},
}

for _, c := range cases {
Expand Down
1 change: 1 addition & 0 deletions x-pack/metricbeat/module/gcp/metrics/metricset.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type config struct {
Zone string `config:"zone"`
Region string `config:"region"`
Regions []string `config:"regions"`
LocationLabel string `config:"location_label"`
ProjectID string `config:"project_id" validate:"required"`
ExcludeLabels bool `config:"exclude_labels"`
CredentialsFilePath string `config:"credentials_file_path"`
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 @@ -37,6 +37,7 @@
credentials_file_path: "your JSON credentials file path"
exclude_labels: false
period: 1m
location_label: "resource.labels.zone"
metrics:
- aligner: ALIGN_NONE
service: compute
Expand Down
Loading