Skip to content

[receiver/azuremonitorreceiver] feat: multi subscriptions support and automatic discovery #37167

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

Merged
merged 3 commits into from
Mar 21, 2025

Conversation

celian-garcia
Copy link
Member

@celian-garcia celian-garcia commented Jan 13, 2025

Recreated from a diffferent fork. Context: #36467

Description

This PR allows to discover and scrape all the subscriptions located in the tenant.
I'm adding also at the same time the ability to give multiple subscriptions as it's free and can also be desired.

This is a part of this PR: #29593 that has been split for readability.
Indeed in a next PR, I'll propose the usage of the getBatch of metrics Azure API. Because if your tenant contains a lot of subscription, you can face rate limitations.

It contains also a little refactor of the tests and the "backdoor" used to mock the API. Now the tests are using the way provided by Azure: the fake API. https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/samples/fakes
The "backdoor" is now only the client options. So no weird interfaces nor weird constructor for the Azure clients inside the scraper.go file.

Link to tracking issue

Fixes #36612

Testing

Documentation

Thanks to the tests refactoring, closes #31264 (at best it fixes it, at worst this makes it obsolete), relates also #38639

Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Feb 25, 2025
@celian-garcia celian-garcia force-pushed the feat/discovery branch 3 times, most recently from 4decd8a to d4de022 Compare March 8, 2025 14:21
@celian-garcia
Copy link
Member Author

celian-garcia commented Mar 8, 2025

ping @andrzej-stencel @jmacd ready for review/merge 🚀

@@ -232,6 +224,11 @@ func (mb *MetricsBuilder) AddDataPoint(
dp.SetStartTimestamp(mb.startTime)
dp.SetTimestamp(ts)
dp.SetDoubleValue(val)

if mb.resourceAttributesSettings.AzureMonitorSubscriptionID.Enabled {
dp.Attributes().PutStr("azuremonitor.subscription_id", subscriptionID)
Copy link
Contributor

@atoulme atoulme Mar 9, 2025

Choose a reason for hiding this comment

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

maybe do this at the resource level? looks like maybe that's not possible, but the resourceAttributesSettings indicates it should be set on the resource, not the data point

Copy link
Member Author

@celian-garcia celian-garcia Mar 9, 2025

Choose a reason for hiding this comment

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

Yeah I struggled a bit with that part, as it looks like if I want to keep this way to enabled/disable subscription, with one subscription per resource, I'd have to emit several bunch of metrics per row. (call several time Emit) Is that something feasible or done by another receiver at your knowledge? I'm not sure of the consequences 🫤 -- I'm checking twice right now and this might be the purpose of EmitForResource I will investigate in that direction.

Otherwise I can also rename this "resource" config for subscriptionID to be "datapoint" to reflect more what it is. Which is a breaking change of the config but as in alpha that's okish. I'm more concern now of the scalability. It's probably better to have one metric resource per susbscription as if you have a lot of subscriptions, it may be a lot of metrics.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok let me know when is good to review again

Copy link
Member Author

Choose a reason for hiding this comment

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

@atoulme this is ready now. The subscription id is back a resource attribute. I inspired a lot from other receivers that are using resouce builder and emit for resources. Which forced me to align a bit more the internal with the other receivers that are generated. Not an easy job but now this is done.

This is too bad that the generated code for metrics through metadata generation could not offer more customization. Ideally I would like it to generate all the code for metrics exposure, without having to define statically the metrics in the metadata.yaml.

Anyway here I have something working perfectly and more aligned with recent code so satisfying 🙂

@atoulme
Copy link
Contributor

atoulme commented Mar 17, 2025

Please address conflicts and mark the PR as ready for review again.

@celian-garcia celian-garcia force-pushed the feat/discovery branch 2 times, most recently from 66bea01 to 2cfdbc7 Compare March 19, 2025 12:43
@@ -1,9 +1,6 @@
resourceMetrics:
Copy link
Member Author

@celian-garcia celian-garcia Mar 19, 2025

Choose a reason for hiding this comment

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

expected_metrics diff is not readable as I sorted by metrics name with yq, specifically to have a readable diff for me.
Capture d’écran 2025-03-19 à 18 15 18

@@ -1,9 +1,6 @@
resourceMetrics:
Copy link
Member Author

@celian-garcia celian-garcia Mar 19, 2025

Choose a reason for hiding this comment

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

expected_metrics diff is not readable as I sorted by metrics name with yq, specifically to have a readable diff for me. This only this + an additional metric that I added to have a second subscription
Capture d’écran 2025-03-19 à 18 16 07

@@ -1,9 +1,6 @@
resourceMetrics:
Copy link
Member Author

@celian-garcia celian-garcia Mar 19, 2025

Choose a reason for hiding this comment

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

expected_metrics diff is not readable as I sorted by metrics name with yq, specifically to have a readable diff for me. This only this + an additional metric that I added to have a second subscription
Capture d’écran 2025-03-19 à 18 17 21

@celian-garcia celian-garcia force-pushed the feat/discovery branch 3 times, most recently from 05b7d55 to 560e99d Compare March 19, 2025 17:27
@celian-garcia
Copy link
Member Author

/label -waiting-for-author

@celian-garcia celian-garcia marked this pull request as ready for review March 19, 2025 17:34
@celian-garcia
Copy link
Member Author

What is this ?

2025/03/19 17:42:34 receiver/azuremonitorreceiver has more than one function: "NewClientOptionsResolver,NewFactory,NewMockClientOptionsResolver"

I have to rename to unexported ?

@atoulme
Copy link
Contributor

atoulme commented Mar 19, 2025

yes please.

@celian-garcia
Copy link
Member Author

Okay I will 👍 . Besides this, this is ready for review.

… automatic discovery

Co-authored-by: Joshua MacDonald <[email protected]>
Signed-off-by: Célian Garcia <[email protected]>
@atoulme atoulme added ready to merge Code review completed; ready to merge by maintainers and removed waiting for author labels Mar 20, 2025
@atoulme
Copy link
Contributor

atoulme commented Mar 20, 2025

Nudging the build by merging latest main.

@atoulme atoulme merged commit 6ce5926 into open-telemetry:main Mar 21, 2025
171 checks passed
@github-actions github-actions bot added this to the next release milestone Mar 21, 2025
atoulme pushed a commit that referenced this pull request Mar 24, 2025
… cleaned because we take subID instead of resID (#38893)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

This is a fix of regression introduced here #37167. 
We are using this little map to cleanup Azure resources that are not
anymore discovered. In this case resources are now stored by
subcriptions so ``resources`` should be changed to ``resources[subID]``
to have existing resources.

<!-- Issue number (e.g. #1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes

<!--Describe what testing was performed and which tests were added.-->
#### Testing

<!--Describe the documentation added.-->
#### Documentation

<!--Please delete paragraphs that you did not use before submitting.-->

Signed-off-by: Célian Garcia <[email protected]>
Fiery-Fenix pushed a commit to Fiery-Fenix/opentelemetry-collector-contrib that referenced this pull request Apr 24, 2025
… automatic discovery (open-telemetry#37167)

Recreated from a diffferent fork. Context:
open-telemetry#36467

> <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
> Ex. Adding a feature - Explain what this achieves.-->
> #### Description
> 
> This PR allows to discover and scrape all the subscriptions located in
the tenant.
> I'm adding also at the same time the ability to give multiple
subscriptions as it's free and can also be desired.
> 
> This is a part of this PR:
open-telemetry#29593
that has been split for readability.
> Indeed in a next PR, I'll propose the usage of the getBatch of metrics
Azure API. Because if your tenant contains a lot of subscription, you
can face rate limitations.
> 
> 
> It contains also a little refactor of the tests and the "backdoor"
used to mock the API. Now the tests are using the way provided by Azure:
the fake API.
https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/samples/fakes
> The "backdoor" is now only the client options. So no weird interfaces
nor weird constructor for the Azure clients inside the ``scraper.go``
file.
> 
> <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable.
-->
> #### Link to tracking issue
> Fixes open-telemetry#36612
> 
> <!--Describe what testing was performed and which tests were added.-->
> #### Testing
> 
> <!--Describe the documentation added.-->
> #### Documentation
> 
> <!--Please delete paragraphs that you did not use before
submitting.-->

Thanks to the tests refactoring, closes open-telemetry#31264 (at best it fixes it, at
worst this makes it obsolete), relates also open-telemetry#38639

Signed-off-by: Célian Garcia <[email protected]>
Co-authored-by: Joshua MacDonald <[email protected]>
Co-authored-by: Antoine Toulme <[email protected]>
Fiery-Fenix pushed a commit to Fiery-Fenix/opentelemetry-collector-contrib that referenced this pull request Apr 24, 2025
… cleaned because we take subID instead of resID (open-telemetry#38893)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

This is a fix of regression introduced here open-telemetry#37167. 
We are using this little map to cleanup Azure resources that are not
anymore discovered. In this case resources are now stored by
subcriptions so ``resources`` should be changed to ``resources[subID]``
to have existing resources.

<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes

<!--Describe what testing was performed and which tests were added.-->
#### Testing

<!--Describe the documentation added.-->
#### Documentation

<!--Please delete paragraphs that you did not use before submitting.-->

Signed-off-by: Célian Garcia <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge Code review completed; ready to merge by maintainers receiver/azuremonitor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[receiver/azuremonitorreceiver] feat: multi subscriptions support and automatic discovery [receiver/azuremonitor] Return concrete types
5 participants