Skip to content

Commit

Permalink
[Metricbeat] Add GCP CloudSQL region filter (#32943)
Browse files Browse the repository at this point in the history
* add cloudsql region filter

* add changelog entry

* fix comment for golangci-lint

* fix get filter for metric tests

* better AlignersMapToGCP comment

* revert to zone and add comment

* Revert "fix get filter for metric tests"

This reverts commit e3ea3b8.

* add cloudsql region label

* add regions filter

* fix changelog

* remove comment from metrics requester
  • Loading branch information
gpop63 authored Sep 19, 2022
1 parent 867ad49 commit f90a066
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ https://github.com/elastic/beats/compare/v8.2.0\...main[Check the HEAD diff]
- in module/windows/perfmon, changed collection method of the second counter value required to create a displayable value {pull}32305[32305]
- Fix and improve AWS metric period calculation to avoid zero-length intervals {pull}32724[32724]
- Add missing cluster metadata to k8s module metricsets {pull}32979[32979] {pull}33032[33032]
- Add GCP CloudSQL region filter {pull}32943[32943]

*Packetbeat*

Expand Down
2 changes: 2 additions & 0 deletions x-pack/metricbeat/module/gcp/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
ServiceStorage = "storage"
ServiceFirestore = "firestore"
ServiceDataproc = "dataproc"
ServiceCloudSQL = "cloudsql"
)

//Paths within the GCP monitoring.TimeSeries response, if converted to JSON, where you can find each ECS field required for the output event
Expand Down Expand Up @@ -81,6 +82,7 @@ const (
ComputeResourceLabelZone = "resource.labels.zone"
GKEResourceLabelLocation = "resource.label.location"
StorageResourceLabelLocation = "resource.label.location"
CloudSQLResourceLabelRegion = "resource.labels.region"
)

// AlignersMapToGCP map contains available perSeriesAligner
Expand Down
13 changes: 13 additions & 0 deletions x-pack/metricbeat/module/gcp/metrics/metrics_requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,19 @@ func (r *metricsRequester) getFilterForMetric(serviceName, m string) string {
regionsFilter := r.buildRegionsFilter(r.config.Regions, gcp.StorageResourceLabelLocation)
f = fmt.Sprintf("%s AND %s", f, regionsFilter)
}
case gcp.ServiceCloudSQL:
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.CloudSQLResourceLabelRegion, region)
case len(r.config.Regions) != 0:
regionsFilter := r.buildRegionsFilter(r.config.Regions, gcp.CloudSQLResourceLabelRegion)
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 "+
Expand Down

0 comments on commit f90a066

Please sign in to comment.