From 457c3e960ce27472352a2cc83c067a471c1d5d33 Mon Sep 17 00:00:00 2001 From: Gabriel Pop <94497545+gpop63@users.noreply.github.com> Date: Thu, 1 Dec 2022 13:39:42 +0200 Subject: [PATCH] [metricbeat] [gcp] add redis regions support (#33728) * add redis regions support * add changelog entry --- CHANGELOG.next.asciidoc | 1 + x-pack/metricbeat/module/gcp/constants.go | 4 +++- .../module/gcp/metrics/metrics_requester.go | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index b9b7355c1616..a7237553551f 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -191,6 +191,7 @@ https://github.com/elastic/beats/compare/v8.2.0\...main[Check the HEAD diff] - Update README file on how to run Metricbeat on Kubernetes. {pull}33308[33308] - Add per-thread metrics to system_summary {pull}33614[33614] - Add GCP CloudSQL metadata {pull}33066[33066] +- Add GCP Redis regions support {pull}33728[33728] *Packetbeat* diff --git a/x-pack/metricbeat/module/gcp/constants.go b/x-pack/metricbeat/module/gcp/constants.go index 5c9e7e5a2b1c..cd539d5653b2 100644 --- a/x-pack/metricbeat/module/gcp/constants.go +++ b/x-pack/metricbeat/module/gcp/constants.go @@ -25,9 +25,10 @@ const ( ServiceFirestore = "firestore" ServiceDataproc = "dataproc" ServiceCloudSQL = "cloudsql" + ServiceRedis = "redis" ) -//Paths within the GCP monitoring.TimeSeries response, if converted to JSON, where you can find each ECS field required for the output event +// Paths within the GCP monitoring.TimeSeries response, if converted to JSON, where you can find each ECS field required for the output event const ( TimeSeriesResponsePathForECSAvailabilityZone = "zone" TimeSeriesResponsePathForECSAccountID = "project_id" @@ -84,6 +85,7 @@ const ( StorageResourceLabelLocation = "resource.label.location" CloudSQLResourceLabelRegion = "resource.labels.region" DataprocResourceLabelLocation = "resource.label.region" + RedisResourceLabelRegion = "resource.label.region" ) // AlignersMapToGCP map contains available perSeriesAligner diff --git a/x-pack/metricbeat/module/gcp/metrics/metrics_requester.go b/x-pack/metricbeat/module/gcp/metrics/metrics_requester.go index 4eed3ad0400d..682957bacedf 100644 --- a/x-pack/metricbeat/module/gcp/metrics/metrics_requester.go +++ b/x-pack/metricbeat/module/gcp/metrics/metrics_requester.go @@ -215,6 +215,19 @@ func (r *metricsRequester) getFilterForMetric(serviceName, m string) string { regionsFilter := r.buildRegionsFilter(r.config.Regions, gcp.CloudSQLResourceLabelRegion) f = fmt.Sprintf("%s AND %s", f, regionsFilter) } + case gcp.ServiceRedis: + if r.config.Region != "" && len(r.config.Regions) != 0 { + r.logger.Warnf("when region %s and regions config parameters are both provided, use region", r.config.Region) + } + + switch { + case r.config.Region != "": + region := strings.TrimSuffix(r.config.Region, "*") + f = fmt.Sprintf("%s AND %s = starts_with(\"%s\")", f, gcp.RedisResourceLabelRegion, region) + case len(r.config.Regions) != 0: + regionsFilter := r.buildRegionsFilter(r.config.Regions, gcp.RedisResourceLabelRegion) + f = fmt.Sprintf("%s AND %s", f, regionsFilter) + } default: if r.config.Region != "" && r.config.Zone != "" { r.logger.Warnf("when region %s and zone %s config parameter "+