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] fix ARN parsing in cloudwatch collector for API Gateway metrics #32358

Conversation

tommyers-elastic
Copy link
Contributor

@tommyers-elastic tommyers-elastic commented Jul 14, 2022

What does this PR do?

Whilst investigating an issue around tag filtering not working for API Gateway metrics, it was discovered that the ARN parsing logic in the AWS cloudwatch collector did not correctly parse ARNs from cloudwatch which start with a leading /; this caused all API gateway metrics to get filtered out. The crux of this PR is pre-strip leading slashes (or colons, just in case) from the ARN resource string before splitting. The result is that ARN resource strings like /apis/123, apis/123 both result in a 'short' identifier of 123.

This PR also removes an used field from the internal data structure metricsWithStatistics, which was causing some additional overhead when trying to grep the code. When updating the test case I added the 'happy path' tagging case to validate the difference between matching tags and not matching tags.

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

Combined with #32408 and #32435, fixes #32408.

Use cases

Screenshots

Logs

For resources with names like "/apis/123-abc", the parsing logic to
generate 'short' identifiers should return just the last segment of the
name. However currently the split + rejoin logic ends up returning
"apis/123-abc". By trimming leading separators we avoid this.
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Jul 14, 2022
@elasticmachine
Copy link
Collaborator

elasticmachine commented Jul 14, 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-07-20T16:59:34.670+0000

  • Duration: 91 min 52 sec

Test stats 🧪

Test Results
Failed 0
Passed 1109
Skipped 107
Total 1216

💚 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!)

@mtojek mtojek added the Team:Cloud-Monitoring Label for the Cloud Monitoring team label Jul 18, 2022
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Jul 18, 2022
@tommyers-elastic tommyers-elastic changed the title [metricbeat] WIP - fix filtering by tag in AWS cloudwatch metrics collector [metricbeat] WIP - fix ARN parsing in cloudwatch collector for Api Gateway metrics Jul 20, 2022
@tommyers-elastic tommyers-elastic force-pushed the fix-filtering-by-tag-in-cloudwatch-metrics branch from 0765ef8 to 0eaf7e6 Compare July 20, 2022 16:41
@tommyers-elastic tommyers-elastic changed the title [metricbeat] WIP - fix ARN parsing in cloudwatch collector for Api Gateway metrics [metricbeat] fix ARN parsing in cloudwatch collector for Api Gateway metrics Jul 20, 2022
@tommyers-elastic tommyers-elastic marked this pull request as ready for review July 20, 2022 16:45
@tommyers-elastic tommyers-elastic requested a review from a team as a code owner July 20, 2022 16:45
Copy link
Contributor

@kaiyan-sheng kaiyan-sheng left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@kaiyan-sheng kaiyan-sheng added backport-v8.3.0 Automated backport with mergify backport-7.17 Automated backport to the 7.17 branch with mergify labels Jul 20, 2022
@tommyers-elastic tommyers-elastic changed the title [metricbeat] fix ARN parsing in cloudwatch collector for Api Gateway metrics [metricbeat] fix ARN parsing in cloudwatch collector for API Gateway metrics Jul 21, 2022
@tommyers-elastic tommyers-elastic merged commit e3c609c into elastic:main Jul 21, 2022
@tommyers-elastic tommyers-elastic deleted the fix-filtering-by-tag-in-cloudwatch-metrics branch July 21, 2022 15:46
mergify bot pushed a commit that referenced this pull request Jul 21, 2022
…metrics (#32358)

* Trim leading separators from ARN resource strings before parsing.

For resources with names like "/apis/123-abc", the parsing logic to
generate 'short' identifiers should return just the last segment of the
name. However currently the split + rejoin logic ends up returning
"apis/123-abc". By trimming leading separators we avoid this.

* remove unused tags list from config struct

* update unit tests for removal of unused tag field in metrics struct

* remove usages of errors.Wrap from aws/utils.go

* remove usages of fmt.Println from aws/utils_test.go

* update changelog

* pr comments

(cherry picked from commit e3c609c)

# Conflicts:
#	x-pack/metricbeat/module/aws/cloudwatch/cloudwatch_test.go
mergify bot pushed a commit that referenced this pull request Jul 21, 2022
…metrics (#32358)

* Trim leading separators from ARN resource strings before parsing.

For resources with names like "/apis/123-abc", the parsing logic to
generate 'short' identifiers should return just the last segment of the
name. However currently the split + rejoin logic ends up returning
"apis/123-abc". By trimming leading separators we avoid this.

* remove unused tags list from config struct

* update unit tests for removal of unused tag field in metrics struct

* remove usages of errors.Wrap from aws/utils.go

* remove usages of fmt.Println from aws/utils_test.go

* update changelog

* pr comments

(cherry picked from commit e3c609c)

# Conflicts:
#	x-pack/metricbeat/module/aws/cloudwatch/cloudwatch_test.go
tommyers-elastic added a commit that referenced this pull request Jul 25, 2022
…llector for API Gateway metrics (#32445)

* [metricbeat] fix ARN parsing in cloudwatch collector for API Gateway metrics (#32358)

* Trim leading separators from ARN resource strings before parsing.

For resources with names like "/apis/123-abc", the parsing logic to
generate 'short' identifiers should return just the last segment of the
name. However currently the split + rejoin logic ends up returning
"apis/123-abc". By trimming leading separators we avoid this.

* remove unused tags list from config struct

* update unit tests for removal of unused tag field in metrics struct

* remove usages of errors.Wrap from aws/utils.go

* remove usages of fmt.Println from aws/utils_test.go

* update changelog

* pr comments

(cherry picked from commit e3c609c)

# Conflicts:
#	x-pack/metricbeat/module/aws/cloudwatch/cloudwatch_test.go

* fix merge conflicts

Co-authored-by: Tom Myers <106530686+tommyers-elastic@users.noreply.github.com>
tommyers-elastic added a commit that referenced this pull request Jul 25, 2022
…lector for API Gateway metrics (#32446)

* [metricbeat] fix ARN parsing in cloudwatch collector for API Gateway metrics (#32358)

* Trim leading separators from ARN resource strings before parsing.

For resources with names like "/apis/123-abc", the parsing logic to
generate 'short' identifiers should return just the last segment of the
name. However currently the split + rejoin logic ends up returning
"apis/123-abc". By trimming leading separators we avoid this.

* remove unused tags list from config struct

* update unit tests for removal of unused tag field in metrics struct

* remove usages of errors.Wrap from aws/utils.go

* remove usages of fmt.Println from aws/utils_test.go

* update changelog

* pr comments

(cherry picked from commit e3c609c)

# Conflicts:
#	x-pack/metricbeat/module/aws/cloudwatch/cloudwatch_test.go

* update changelog with correct PR link

Co-authored-by: Tom Myers <106530686+tommyers-elastic@users.noreply.github.com>
chrisberkhout pushed a commit that referenced this pull request Jun 1, 2023
…metrics (#32358)

* Trim leading separators from ARN resource strings before parsing.

For resources with names like "/apis/123-abc", the parsing logic to
generate 'short' identifiers should return just the last segment of the
name. However currently the split + rejoin logic ends up returning
"apis/123-abc". By trimming leading separators we avoid this.

* remove unused tags list from config struct

* update unit tests for removal of unused tag field in metrics struct

* remove usages of errors.Wrap from aws/utils.go

* remove usages of fmt.Println from aws/utils_test.go

* update changelog

* pr comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-7.17 Automated backport to the 7.17 branch with mergify backport-v8.3.0 Automated backport with mergify bug Team:Cloud-Monitoring Label for the Cloud Monitoring team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants