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

[Azure] [Billing] Switch to Consumption API 1.1.0 with patches #37158

Merged
merged 6 commits into from Nov 30, 2023

Conversation

zmoog
Copy link
Contributor

@zmoog zmoog commented Nov 20, 2023

Proposed commit message

Bump the following package versions to patch the Consumption SDK 1.1.0:

  • Bump armconsumption package version from 1.0.0+patch to 1.1.0+patch
  • Bump azcore package version from 1.4.0 to 1.9.0 to use the URL encoder helper used in the Azure SDK

The Consumption SDK does not correctly handle query parameters in the 'next link' when the dataset in Azure requires pagination. See elastic/integrations#7478 (comment) for more details.

We manage the patches to the Azure SDK for Go in the repository fork. To learn more about the patches and the fork, see #37151

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.

How to test this PR locally

Our Azure accounts does not have enough usage details items to trigger pagination; the default page size is 1000 items.

You can trigger the pagination by setting the top parameter to a low value (for example, 10 items) when in the pager at

pager := service.usageDetailsClient.NewListPager(scope, &armconsumption.UsageDetailsClientListOptions{
Expand: &expand,
Filter: &filter,
Metric: &metrictype,
StartDate: &startDate,
EndDate: &endDate,
})

Related issues

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Nov 20, 2023
@zmoog zmoog changed the title Switch to Consumption API 1.1.0 with patches [Azure] [Billing] Switch to Consumption API 1.1.0 with patches Nov 20, 2023
@zmoog zmoog self-assigned this Nov 20, 2023
@zmoog zmoog added the Team:Cloud-Monitoring Label for the Cloud Monitoring team label Nov 20, 2023
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Nov 20, 2023
Copy link
Contributor

mergify bot commented Nov 20, 2023

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @zmoog? 🙏.
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

❕ Build Aborted

Either there was a build timeout or someone aborted the build.

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

Expand to view the summary

Build stats

  • Duration: 48 min 39 sec

🤖 GitHub comments

Expand to view the 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!)

@zmoog zmoog added the bug label Nov 20, 2023
@zmoog zmoog marked this pull request as ready for review November 20, 2023 17:44
@zmoog zmoog requested a review from a team as a code owner November 20, 2023 17:44
@zmoog zmoog added the backport-v8.11.0 Automated backport with mergify label Nov 20, 2023
@elasticmachine
Copy link
Collaborator

❕ Build Aborted

Either there was a build timeout or someone aborted the build.

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

Expand to view the summary

Build stats

  • Duration: 81 min 10 sec

🤖 GitHub comments

Expand to view the 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!)

@elasticmachine
Copy link
Collaborator

💚 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

  • Duration: 168 min 59 sec

❕ Flaky test report

No test was executed to be analysed.

🤖 GitHub comments

Expand to view the 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!)

@shmsr
Copy link
Member

shmsr commented Nov 21, 2023

The changes here look good. I'll take a look at the patches.

Copy link
Contributor

mergify bot commented Nov 21, 2023

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b zmoog/url-encode-next-link-in-azure-billing upstream/zmoog/url-encode-next-link-in-azure-billing
git merge upstream/main
git push upstream zmoog/url-encode-next-link-in-azure-billing

@gpop63
Copy link
Contributor

gpop63 commented Nov 27, 2023

I did replicate this by setting Top param in UsageDetailsClientListOptions to 10 or 100 to enable pagination (the way @zmoog told me to). Used modern account which I believe uses MCA agreement.

{"log.level":"error","@timestamp":"2023-11-28T00:32:41.751+0200","log.origin":{"file.name":"module/wrapper.go","file.line":256},"message":"Error fetching data for metricset azure.billing: error retrieving usage information: retrieving usage details failed in client: GET https://management.azure.com/subscriptions/REDACTED/providers/Microsoft.Consumption/usageDetails\n--------------------------------------------------------------------------------\nRESPONSE 400: 400 Bad Request\nERROR CODE: MissingApiVersionParameter\n--------------------------------------------------------------------------------\n{\n  \"error\": {\n    \"code\": \"MissingApiVersionParameter\",\n    \"message\": \"The api-version query parameter (?api-version=) is required for all requests.\"\n  }\n}\n--------------------------------------------------------------------------------\n","service.name":"metricbeat","ecs.version":"1.6.0"}

I tried setting the Skiptoken parameter by parsing nextPage.NextLink to see if this is a viable solution, but this does nothing.

@muthu-mps
Copy link
Contributor

I did replicate this by setting Top param in UsageDetailsClientListOptions to 10 or 100 to enable pagination (the way @zmoog told me to). Used modern account which I believe uses MCA agreement.

{"log.level":"error","@timestamp":"2023-11-28T00:32:41.751+0200","log.origin":{"file.name":"module/wrapper.go","file.line":256},"message":"Error fetching data for metricset azure.billing: error retrieving usage information: retrieving usage details failed in client: GET https://management.azure.com/subscriptions/REDACTED/providers/Microsoft.Consumption/usageDetails\n--------------------------------------------------------------------------------\nRESPONSE 400: 400 Bad Request\nERROR CODE: MissingApiVersionParameter\n--------------------------------------------------------------------------------\n{\n  \"error\": {\n    \"code\": \"MissingApiVersionParameter\",\n    \"message\": \"The api-version query parameter (?api-version=) is required for all requests.\"\n  }\n}\n--------------------------------------------------------------------------------\n","service.name":"metricbeat","ecs.version":"1.6.0"}

I tried setting the Skiptoken parameter by parsing nextPage.NextLink to see if this is a viable solution, but this does nothing.

@gpop63 - Thanks for verifying the changes.

  • I have tried with multiple scenarios to verify the expected behaviour and it works as mentioned above.
  • I am getting the error you have mentioned only when I run the pagination scenario against the main branch.
  • Can you please double check the code which you have been using to test is from this PR?

@gpop63
Copy link
Contributor

gpop63 commented Nov 28, 2023

@muthu-mps this fix is great, I was saying I was able to replicate this issue (using the main branch). So the changes here fix it.

@muthu-mps
Copy link
Contributor

@muthu-mps this fix is great, I was saying I was able to replicate this issue (using the main branch). So the changes here fix it.

Thanks @gpop63

@muthu-mps
Copy link
Contributor

Azure Billing Metrics

Verified the following scenarios

  • Pulled the latest code from this PR.
  • Configured the EA account in the Azure(billing) metricbeat module.
  • Verified the metrics collection for billing account with default settings. It works fine.
  • configured the Top parameter as suggested to test the pagination use-case and verified the metrics collection and it works as expected.
  • Checked whether the data is pulled for the previous date.
  • The same has been verified against the MCA account and working as expected.

Issue Replication

  • The issue is reproducible when doing the same against the main branch.

Copy link
Contributor

@muthu-mps muthu-mps left a comment

Choose a reason for hiding this comment

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

LGTM!

@zmoog
Copy link
Contributor Author

zmoog commented Nov 28, 2023

Hey friends at @elastic/beats-tech-leads, we need your review on this change because it affects go.mod ^^

@zmoog
Copy link
Contributor Author

zmoog commented Nov 28, 2023

We're tageting the upcoming 8.12.0 and 8.11.2.

@elasticmachine
Copy link
Collaborator

💚 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: 2023-11-28T16:38:30.153+0000

  • Duration: 164 min 0 sec

Test stats 🧪

Test Results
Failed 0
Passed 28694
Skipped 2015
Total 30709

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

Expand to view the 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!)

Copy link
Contributor

mergify bot commented Nov 28, 2023

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b zmoog/url-encode-next-link-in-azure-billing upstream/zmoog/url-encode-next-link-in-azure-billing
git merge upstream/main
git push upstream zmoog/url-encode-next-link-in-azure-billing

@elasticmachine
Copy link
Collaborator

💚 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

  • Duration: 163 min 21 sec

❕ Flaky test report

No test was executed to be analysed.

🤖 GitHub comments

Expand to view the 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!)

@tommyers-elastic
Copy link
Contributor

thanks @zmoog ! i would like to tidy up the tag on the fork so the version is a little better defined in the go.mod here.

@zmoog
Copy link
Contributor Author

zmoog commented Nov 29, 2023

i would like to tidy up the tag on the fork so the version is a little better defined in the go.mod here.

On it!

The Consumption SDK does not URL encode the query parameters in the
next link when the response requires more than one page to fetch all
the usage details items.

Our Azure SDK for Go fork contains a small patch to URL encode the
next link value and avoid the 400 error.

We also upgraded the azcore package to use the standard URL helper for
the Azure SDK.
I replaced the original commit with a new one with a better comment.
Tidy up the go.mod file by targeting the tag `v1.1.0-elastic` on the
Azure SDK fork instead of the commit.
@zmoog zmoog force-pushed the zmoog/url-encode-next-link-in-azure-billing branch from 8dbccb7 to cfa82f2 Compare November 29, 2023 18:03
Yes, again.
@elasticmachine
Copy link
Collaborator

❕ Build Aborted

Either there was a build timeout or someone aborted the build.

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

Expand to view the summary

Build stats

  • Duration: 126 min 39 sec

🤖 GitHub comments

Expand to view the 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!)

@elasticmachine
Copy link
Collaborator

💚 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: 2023-11-29T18:15:07.324+0000

  • Duration: 164 min 31 sec

Test stats 🧪

Test Results
Failed 0
Passed 28694
Skipped 2015
Total 30709

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

Expand to view the 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!)

@zmoog
Copy link
Contributor Author

zmoog commented Nov 29, 2023

@tommyers-elastic, I made the following changes:

  • I created a PR to merge the patches into our sdk/.../v1.1.0-elastic branch (I shuffled the branches around but kept the commits with the two patches intact).
  • Added a v1.1.0-elastic tag on the last commit.
  • Updated the go.mod file to target the v1.1.0-elastic tag.

You now can:

Copy link
Contributor

@tommyers-elastic tommyers-elastic left a comment

Choose a reason for hiding this comment

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

LGTM

@zmoog zmoog merged commit 9de3307 into elastic:main Nov 30, 2023
113 checks passed
@zmoog zmoog deleted the zmoog/url-encode-next-link-in-azure-billing branch November 30, 2023 10:06
mergify bot pushed a commit that referenced this pull request Nov 30, 2023
* Switch to consumption 1.1.0 with patches

The Consumption SDK does not URL encode the query parameters in the
next link when the response requires more than one page to fetch all
the usage details items.

Our Azure SDK for Go fork contains a small patch to URL encode the
next link value and avoid the 400 error.

We also upgraded the azcore package to use the standard URL helper for
the Azure SDK.

* Update NOTICE.txt

* Target tag v1.1.0-elastic instead of the commit

Tidy up the go.mod file by targeting the tag `v1.1.0-elastic` on the
Azure SDK fork instead of the commit.

(cherry picked from commit 9de3307)
@zmoog zmoog added the backport-v7.17.0 Automated backport with mergify label Nov 30, 2023
mergify bot pushed a commit that referenced this pull request Nov 30, 2023
* Switch to consumption 1.1.0 with patches

The Consumption SDK does not URL encode the query parameters in the
next link when the response requires more than one page to fetch all
the usage details items.

Our Azure SDK for Go fork contains a small patch to URL encode the
next link value and avoid the 400 error.

We also upgraded the azcore package to use the standard URL helper for
the Azure SDK.

* Update NOTICE.txt

* Target tag v1.1.0-elastic instead of the commit

Tidy up the go.mod file by targeting the tag `v1.1.0-elastic` on the
Azure SDK fork instead of the commit.

(cherry picked from commit 9de3307)

# Conflicts:
#	NOTICE.txt
#	go.mod
#	go.sum
zmoog added a commit that referenced this pull request Nov 30, 2023
… (#37242)

* Switch to consumption 1.1.0 with patches

The Consumption SDK does not URL encode the query parameters in the
next link when the response requires more than one page to fetch all
the usage details items.

Our Azure SDK for Go fork contains a small patch to URL encode the
next link value and avoid the 400 error.

We also upgraded the azcore package to use the standard URL helper for
the Azure SDK.

* Update NOTICE.txt

* Target tag v1.1.0-elastic instead of the commit

Tidy up the go.mod file by targeting the tag `v1.1.0-elastic` on the
Azure SDK fork instead of the commit.

(cherry picked from commit 9de3307)

Co-authored-by: Maurizio Branca <maurizio.branca@elastic.co>
Scholar-Li pushed a commit to Scholar-Li/beats that referenced this pull request Feb 5, 2024
…ic#37158)

* Switch to consumption 1.1.0 with patches

The Consumption SDK does not URL encode the query parameters in the
next link when the response requires more than one page to fetch all
the usage details items.

Our Azure SDK for Go fork contains a small patch to URL encode the
next link value and avoid the 400 error.

We also upgraded the azcore package to use the standard URL helper for
the Azure SDK.

* Update NOTICE.txt

* Target tag v1.1.0-elastic instead of the commit

Tidy up the go.mod file by targeting the tag `v1.1.0-elastic` on the
Azure SDK fork instead of the commit.
@JuddDeaver
Copy link

@zmoog I don't see any actual version tags applied to this PR. I have support case 01523048 where they are hitting this known issue. Has his fix made it into the product, and what version?

@zmoog
Copy link
Contributor Author

zmoog commented Mar 26, 2024

The fix has been released in Beats and Elastic Agent version 8.11.2.

@zmoog
Copy link
Contributor Author

zmoog commented Mar 26, 2024

@JuddDeaver, which tags should I apply to the PR to properly communicate this info?

@JuddDeaver
Copy link

In that case I think adding the v8.11.2 label would typically be used to indicate the version it was merged. I thought this was usually added by automation, but that might not be an accurate assumption for this repo.

@zmoog zmoog added the v8.11.2 label Mar 26, 2024
@zmoog
Copy link
Contributor Author

zmoog commented Mar 26, 2024

Yeah, it's not a common practice for this repo, but conveying this information with tags/labels or a last comment with a recap makes sense.

I'll do one or the other in current and future PRs.

Thanks for the heads up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v7.17.0 Automated backport with mergify backport-v8.11.0 Automated backport with mergify bug Team:Cloud-Monitoring Label for the Cloud Monitoring team v8.11.2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Azure Billing Integration omit API version
7 participants