Skip to content

Commit

Permalink
add warn logs and remove redundant return
Browse files Browse the repository at this point in the history
  • Loading branch information
gpop63 committed Sep 9, 2022
1 parent f492e82 commit ecc40c6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions x-pack/metricbeat/module/gcp/metrics/metrics_requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ func (r *metricsRequester) getFilterForMetric(serviceName, m string) string {
"both are provided, only use region", r.config.Regions, r.config.Zone)
}

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)
}

if r.config.Region != "" {
f = fmt.Sprintf(
"%s AND %s = starts_with(\"%s\")",
Expand Down Expand Up @@ -203,15 +207,17 @@ func (r *metricsRequester) getFilterForMetric(serviceName, m string) string {
case gcp.ServicePubsub, gcp.ServiceLoadBalancing, gcp.ServiceCloudFunctions, gcp.ServiceFirestore, gcp.ServiceDataproc:
return f
case gcp.ServiceStorage:
if r.config.Region != "" && len(r.config.Regions) != 0 {
r.logger.Warnf("when region and regions config parameters are both provided, use region", r.config.Region)
}

switch {
case r.config.Region != "":
f = fmt.Sprintf(`%s AND resource.labels.location = "%s"`, f, r.config.Region)
case len(r.config.Regions) != 0:
regionsFilter := r.buildRegionsFilter(r.config.Regions, gcp.StorageResourceLabelLocation)
f = fmt.Sprintf("%s AND %s", f, regionsFilter)
}

return f
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 ecc40c6

Please sign in to comment.