diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index c764e5409ebc..86ae7fbc1db8 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -369,6 +369,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 an optional configuration parameter in GCP metrics metricset. {issue}41550[41550] {pull}41626[41626] *Metricbeat* diff --git a/metricbeat/docs/modules/gcp.asciidoc b/metricbeat/docs/modules/gcp.asciidoc index 025b70a94040..5adabe732b29 100644 --- a/metricbeat/docs/modules/gcp.asciidoc +++ b/metricbeat/docs/modules/gcp.asciidoc @@ -303,6 +303,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 diff --git a/x-pack/metricbeat/metricbeat.reference.yml b/x-pack/metricbeat/metricbeat.reference.yml index 7a32f16c19c8..f7f048da84bd 100644 --- a/x-pack/metricbeat/metricbeat.reference.yml +++ b/x-pack/metricbeat/metricbeat.reference.yml @@ -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 diff --git a/x-pack/metricbeat/module/gcp/_meta/config.yml b/x-pack/metricbeat/module/gcp/_meta/config.yml index ad0c7da852fa..55001654db98 100644 --- a/x-pack/metricbeat/module/gcp/_meta/config.yml +++ b/x-pack/metricbeat/module/gcp/_meta/config.yml @@ -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 diff --git a/x-pack/metricbeat/module/gcp/metrics/_meta/docs.asciidoc b/x-pack/metricbeat/module/gcp/metrics/_meta/docs.asciidoc index 642df10f4962..40dc27e80e8f 100644 --- a/x-pack/metricbeat/module/gcp/metrics/_meta/docs.asciidoc +++ b/x-pack/metricbeat/module/gcp/metrics/_meta/docs.asciidoc @@ -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. This is an optional configuration for the user. + [float] === Example Configuration * `metrics` metricset is enabled to collect metrics from all zones under @@ -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" # This is an optional configuration + regions: + - us-east4 + metrics: + - service: aiplatform + metric_types: + - "prediction/online/replicas" +---- \ No newline at end of file diff --git a/x-pack/metricbeat/module/gcp/metrics/metrics_requester.go b/x-pack/metricbeat/module/gcp/metrics/metrics_requester.go index ad0632e6c852..915ff63190f0 100644 --- a/x-pack/metricbeat/module/gcp/metrics/metrics_requester.go +++ b/x-pack/metricbeat/module/gcp/metrics/metrics_requester.go @@ -251,7 +251,7 @@ func (r *metricsRequester) getFilterForMetric(serviceName, m string) string { // NOTE: some GCP services are global, not regional or zonal. To these services we don't need // to apply any additional filters. if locationsConfigsAvailable && !isAGlobalService(serviceName) { - serviceLabel := getServiceLabelFor(serviceName) + serviceLabel := r.getServiceLabel(serviceName) f = r.buildLocationFilter(serviceLabel, f) } @@ -261,6 +261,16 @@ func (r *metricsRequester) getFilterForMetric(serviceName, m string) string { return f } +// getServiceLabel determines the service label to be used for the given service name. If a custom +// location label is configured, it will be used. Otherwise, the default service label for the +// given service name will be returned. +func (r *metricsRequester) getServiceLabel(serviceName string) string { + if r.config.LocationLabel != "" { + return r.config.LocationLabel + } + return getServiceLabelFor(serviceName) +} + // Returns a GCP TimeInterval based on the ingestDelay and samplePeriod from ListMetricDescriptor func getTimeIntervalAligner(ingestDelay time.Duration, samplePeriod time.Duration, collectionPeriod *durationpb.Duration, inputAligner string) (*monitoringpb.TimeInterval, string) { var startTime, endTime, currentTime time.Time diff --git a/x-pack/metricbeat/module/gcp/metrics/metrics_requester_test.go b/x-pack/metricbeat/module/gcp/metrics/metrics_requester_test.go index 9fb044e39e5f..20f8a5d9e366 100644 --- a/x-pack/metricbeat/module/gcp/metrics/metrics_requester_test.go +++ b/x-pack/metricbeat/module/gcp/metrics/metrics_requester_test.go @@ -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 { diff --git a/x-pack/metricbeat/module/gcp/metrics/metricset.go b/x-pack/metricbeat/module/gcp/metrics/metricset.go index 274a6153b54c..28ac514f1e5d 100644 --- a/x-pack/metricbeat/module/gcp/metrics/metricset.go +++ b/x-pack/metricbeat/module/gcp/metrics/metricset.go @@ -101,6 +101,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"` diff --git a/x-pack/metricbeat/modules.d/gcp.yml.disabled b/x-pack/metricbeat/modules.d/gcp.yml.disabled index 7d4723959546..0c77d8e37b86 100644 --- a/x-pack/metricbeat/modules.d/gcp.yml.disabled +++ b/x-pack/metricbeat/modules.d/gcp.yml.disabled @@ -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