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

[Metricbeat] Add support for multiple regions in GCP #32964

Merged
merged 8 commits into from
Sep 11, 2022

Conversation

gpop63
Copy link
Contributor

@gpop63 gpop63 commented Sep 1, 2022

What does this PR do?

Adds support for multiple regions in GCP.

Why is it important?

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Sep 1, 2022
@gpop63 gpop63 added the Team:Cloud-Monitoring Label for the Cloud Monitoring team label Sep 1, 2022
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Sep 1, 2022
@mergify mergify bot assigned gpop63 Sep 1, 2022
@mergify
Copy link
Contributor

mergify bot commented Sep 1, 2022

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @gpop63? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v8./d.0 is the label to automatically backport to the 8./d branch. /d is the digit

@elasticmachine
Copy link
Collaborator

elasticmachine commented Sep 1, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-09-09T19:07:00.861+0000

  • Duration: 51 min 52 sec

Test stats 🧪

Test Results
Failed 0
Passed 1316
Skipped 87
Total 1403

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@gpop63 gpop63 marked this pull request as ready for review September 1, 2022 22:44
@gpop63 gpop63 requested a review from a team as a code owner September 1, 2022 22:44
Copy link
Member

@endorama endorama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of things I think needs to be improved before merging, but overall 👍

return f
}

switch serviceName {
case gcp.ServiceCompute:
if r.config.Region != "" && r.config.Zone != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition should take into account the case where region and regions are both configured

}

f = fmt.Sprintf(`%s AND resource.labels.location = "%s"`, f, r.config.Region)
return f
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this return needed? If not I would remove it there is just one return at the end (where we also log the full filter).

if len(r.config.Regions) != 0 {
regionsFilter := r.buildRegionsFilter(r.config.Regions, gcp.ComputeResourceLabelZone)
f = fmt.Sprintf("%s AND %s", f, regionsFilter)
}
case gcp.ServiceGKE:
if r.config.Region != "" && r.config.Zone != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cThis condition should take into account the case where region and regions are both configured

}
case gcp.ServicePubsub, gcp.ServiceLoadBalancing, gcp.ServiceCloudFunctions, gcp.ServiceFirestore, gcp.ServiceDataproc:
return f
case gcp.ServiceStorage:
if r.config.Region == "" {
return f
switch {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here should be added the warning about region taking precedence over regions

@endorama
Copy link
Member

endorama commented Sep 7, 2022

@gpop63 I notice we use a if/break pattern that screams refactoring. What do you think about following up with a PR that changes that for if/elseif/else or switch/case like you did in gcp.ServiceStorage?

@elastic elastic deleted a comment from cla-checker-service bot Sep 9, 2022
@endorama endorama added the backport-v8.4.0 Automated backport with mergify label Sep 9, 2022
@gpop63 gpop63 merged commit 3bcefab into elastic:main Sep 11, 2022
mergify bot pushed a commit that referenced this pull request Sep 11, 2022
* add regions config setting and pass it as argument

* add services region resource label constants

* add buildRegionsFilter and update getFilterForMetric logic

* add getFilterForMetric and buildRegionsFilter tests

* add changelog entry

* minor changes for golangci-lint

* add warn logs and remove redundant return

* add missing argument in warnf log

(cherry picked from commit 3bcefab)
@kaiyan-sheng kaiyan-sheng removed the backport-v8.4.0 Automated backport with mergify label Sep 12, 2022
@endorama
Copy link
Member

I'm going to backport this to 7.17, otherwise this change would make our integration not compatible with the 7.x branch.

@endorama endorama added the backport-v7.17.0 Automated backport with mergify label Sep 15, 2022
mergify bot pushed a commit that referenced this pull request Sep 15, 2022
* add regions config setting and pass it as argument

* add services region resource label constants

* add buildRegionsFilter and update getFilterForMetric logic

* add getFilterForMetric and buildRegionsFilter tests

* add changelog entry

* minor changes for golangci-lint

* add warn logs and remove redundant return

* add missing argument in warnf log

(cherry picked from commit 3bcefab)

# Conflicts:
#	x-pack/metricbeat/module/gcp/metrics/compute/metadata.go
#	x-pack/metricbeat/module/gcp/metrics/metrics_requester.go
#	x-pack/metricbeat/module/gcp/metrics/metrics_requester_test.go
#	x-pack/metricbeat/module/gcp/metrics/metricset.go
@endorama
Copy link
Member

Removing backport as backport is not needed.

@endorama endorama removed the backport-v7.17.0 Automated backport with mergify label Sep 15, 2022
@@ -145,6 +145,7 @@ The list below covers the major changes between 7.0.0-rc2 and main only.
- Add regex support for drop_fields processor.
- Improve compatibility and reduce flakyness of Python tests {pull}31588[31588]
- Added `.python-version` file {pull}32323[32323]
- Add support for multiple regions in GCP {pull}32964[32964]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saw this changelog is under developer changelog, should this be under CHANGELOG-next?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! @gpop63 may you please add this line to CHANGELOG.next with a separate PR?

chrisberkhout pushed a commit that referenced this pull request Jun 1, 2023
* add regions config setting and pass it as argument

* add services region resource label constants

* add buildRegionsFilter and update getFilterForMetric logic

* add getFilterForMetric and buildRegionsFilter tests

* add changelog entry

* minor changes for golangci-lint

* add warn logs and remove redundant return

* add missing argument in warnf log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Cloud-Monitoring Label for the Cloud Monitoring team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Metricbeat] Allow to specify more than one regions in googlecloud module
4 participants