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

feat: SDK migration single resource scraping #2470

Merged

Conversation

hkfgo
Copy link
Contributor

@hkfgo hkfgo commented Apr 20, 2024

This PR implements the Azure Monitor SDK migration. It migrates away from the deprecated Azure Fluent SDK to Azure SDK for .NET. Specifically, it uses the Azure.Monitor.Query package to implement integration. Since the new SDK is essentially a different wrapper around the same REST API, I'd expect identical behavior in terms of

  • Billing(free through ARM)
  • Metric querying
  • Meta-level metrics to track ARM throttling
  • Meta-level metrics to track usage

A summary of how I did it:

  • Abstracted Azure Monitor integration through the IAzureMonitorClient interface.
  • Implemented Azure Monitor integration using the new SDK, under the IAzureMonitorClient interface
  • Implemented high-level control flow to use either the new client or the legacy client, depending on feature flag

Things I need help with:

  • If this looks like a good approach to you
  • I need some pointers on how to test this :( Specifically, how do you think end-to-end testing should be performed for a major PR like this? I was thinking either integration tests or building a custom branch image and deploying to our test environment. I'm not quite sure how to do either of them though. Some help would be much appreciated!

Relates to #2209

@hkfgo hkfgo requested a review from tomkerkhove as a code owner April 20, 2024 02:37
@trafico-bot trafico-bot bot added the 🔍 Ready for Review Pull Request is not reviewed yet label Apr 20, 2024
Copy link

Thank you for your contribution! 🙏 We will review it as soon as possible.

@tomkerkhove
Copy link
Owner

I need some pointers on how to test this :( Specifically, how do you think end-to-end testing should be performed for a major PR like this? I was thinking either integration tests or building a custom branch image and deploying to our test environment. I'm not quite sure how to do either of them though. Some help would be much appreciated!

This should be covered by the testing sweet so no worries!

Copy link
Owner

@tomkerkhove tomkerkhove left a comment

Choose a reason for hiding this comment

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

Thanks for doing this, added some comments but good first step!

src/Promitor.Agents.Scraper/AzureMonitorClientFactory.cs Outdated Show resolved Hide resolved
Comment on lines +28 to +32
var request = message.Request;
string agentVersion = Version.Get();
var promitorUserAgent = ArmUserAgent.Generate(agentVersion, _metricSinkWriter.EnabledMetricSinks);
request.Headers.Remove(HttpHeader.Names.UserAgent);
request.Headers.Add(HttpHeader.Names.UserAgent, promitorUserAgent);
Copy link
Owner

Choose a reason for hiding this comment

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

This can be moved to a dedicated method and called in respective Process methods, or not?

Copy link
Contributor Author

@hkfgo hkfgo May 8, 2024

Choose a reason for hiding this comment

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

Same comment here, decided it made more sense to thrown an exception on the synchronous path instead.

@hkfgo
Copy link
Contributor Author

hkfgo commented Apr 21, 2024

I need some pointers on how to test this :( Specifically, how do you think end-to-end testing should be performed for a major PR like this? I was thinking either integration tests or building a custom branch image and deploying to our test environment. I'm not quite sure how to do either of them though. Some help would be much appreciated!

This should be covered by the testing sweet so no worries!

Are these pipeline steps something I can repeatedly trigger on my own? I read the README more carefully and it seems like I can find my branch build under :pr{pr-id}. If I can re-trigger the CI pipeline on my own then that'd definitely cover end-to-end testing!

@tomkerkhove
Copy link
Owner

I need some pointers on how to test this :( Specifically, how do you think end-to-end testing should be performed for a major PR like this? I was thinking either integration tests or building a custom branch image and deploying to our test environment. I'm not quite sure how to do either of them though. Some help would be much appreciated!

This should be covered by the testing sweet so no worries!

Are these pipeline steps something I can repeatedly trigger on my own? I read the README more carefully and it seems like I can find my branch build under :pr{pr-id}. If I can re-trigger the CI pipeline on my own then that'd definitely cover end-to-end testing!

Hey, there are docs how to run things locally here: https://github.com/tomkerkhove/promitor/blob/master/CONTRIBUTING.md#net-development

The CI also runs all these integration tests automatically in case you were wondering

@hkfgo
Copy link
Contributor Author

hkfgo commented May 9, 2024

Looks like all tests are passing now! The failing CodeFactor was on the giant MetricScraperFactory method to find the matching scraper. There's not much we can do I think.

Do you mind taking another look? Please ignore the log statements and modification to GitHub action for now. We can remove those before pressing the merge button

@hkfgo
Copy link
Contributor Author

hkfgo commented May 9, 2024

Also, any pointers on how to do remote debugging? I've found some online articles on remote debugging with VS Code + .NET + Kubernetes. Probably should have tried that to begin with instead of doing so many print statements..

@tomkerkhove
Copy link
Owner

Also, any pointers on how to do remote debugging? I've found some online articles on remote debugging with VS Code + .NET + Kubernetes. Probably should have tried that to begin with instead of doing so many print statements..

No, I always use VS to run the container locally and troubleshoot. If a running instance does not provide the insights you need, then we may be missing some logs

Copy link
Owner

@tomkerkhove tomkerkhove left a comment

Choose a reason for hiding this comment

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

Requesting changes to ensure we revert the GitHub action changes, but otherwise it looks good and added some small comments.

Thanks a ton!!

.github/workflows/templates-build-push-image.yml Outdated Show resolved Hide resolved
.MapUsing(DetermineAzureCloud);
}

// TODO: validate cloud configuration in a SDK-agnostic way
Copy link
Owner

Choose a reason for hiding this comment

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

Can you open an issue and link to it here please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used azureCloud.DetermineMetricsClientAudience() for validation, see comment above

@trafico-bot trafico-bot bot added ⚠️ Changes requested Pull Request needs changes before it can be reviewed again and removed 🔍 Ready for Review Pull Request is not reviewed yet labels May 16, 2024
@trafico-bot trafico-bot bot added 🔍 Ready for Review Pull Request is not reviewed yet and removed ⚠️ Changes requested Pull Request needs changes before it can be reviewed again labels May 17, 2024
@hkfgo
Copy link
Contributor Author

hkfgo commented May 17, 2024

Also, I believe there should be two quick PRs to

  1. Update documentation
  2. Make useAzureMonitor flag available in the Promitor chart

Be on the look out :)

@hkfgo
Copy link
Contributor Author

hkfgo commented May 25, 2024

Promitor documentation PR: promitor/docs#62
Promitor chart PR: promitor/charts#168

I believe they are dependencies of the next release but not this PR getting merged. I'm making this distinction because I'm waiting on merge to master to rebase and continue batch scraping work. No rush though. Thanks!

Copy link
Owner

@tomkerkhove tomkerkhove left a comment

Choose a reason for hiding this comment

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

Thanks a ton for doing this and not giving up after all my comments!

@trafico-bot trafico-bot bot added ✅ Approved Pull Request has been approved and can be merged and removed 🔍 Ready for Review Pull Request is not reviewed yet labels May 27, 2024
@tomkerkhove tomkerkhove merged commit 7e288ed into tomkerkhove:master May 27, 2024
26 of 27 checks passed
@trafico-bot trafico-bot bot added ✨ Merged Pull Request has been merged successfully and removed ✅ Approved Pull Request has been approved and can be merged labels May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Merged Pull Request has been merged successfully
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants