-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(azure): add vm_id to KVP telemetry event keys #6551
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
base: main
Are you sure you want to change the base?
Conversation
cloudinit/reporting/handlers.py
Outdated
| ) | ||
|
|
||
| try: | ||
| from cloudinit.sources.azure.identity import query_vm_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was this done late to avoid circular imports?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that was exactly why - I kept getting an error message about that. Let me know if there is a better way to avoid that circular import!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally a circular import error indicates a lack of clear hierarchy in the code. The reporting code is currently not coupled to any particular cloud, but after this change that would no longer be true.
I haven't put much thought into it, but since query_vm_id is currently not used anywhere it could just get relocated to this module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's break the circular dependency here by removing the import for:
from cloudinit.sources.helpers.azure import report_diagnostic_event
A little refactoring will be required to do so.
…rder Relocate query_vm_id() and helper functions from azure.identity to reporting.handlers to eliminate circular import. Also fix event key format to place vm_id before uuid in order to prevent breaking RdAgent.
5e5a253 to
7b66c56
Compare
|
A request was made outside of this PR to re-order |
|
Hello! Thank you for this proposed change to cloud-init. This pull request is now marked as stale as it has not seen any activity in 14 days. If no activity occurs within the next 7 days, this pull request will automatically close. If you are waiting for code review and you are seeing this message, apologies! Please reply, tagging blackboxsw, and he will ensure that someone takes a look soon. (If the pull request is closed and you would like to continue working on it, please do tag blackboxsw to reopen it.) |
Move vm_id lookup out of HyperVKvpReportingHandler and into azure/kvp.py. The handler now defaults vm_id to ZERO_GUID, and get_kvp_handler() injects the real vm_id via identity.query_vm_id(). This removes ~65 lines of duplicate Azure identity code from cloudinit/reporting/handlers.py and keeps azure/identity.py as the single source of truth for vm_id derivation. Updated tests to reflect the simplified handler init.
9d0e689 to
fa77a7a
Compare
|
Per offline discussion, The current suggestion is to instead have the datasource set vm_id via azure's |
a2a7dcd to
0e516d7
Compare
Allow HyperVKvpReportingHandler to resolve vm_id at encode time via an injected provider. On the default Hyper-V KVP pool path, fall back to DMI system-uuid when no provider is set to avoid ZERO_GUID keys. Azure KVP helper now installs identity.query_vm_id as the provider. Add unit tests for the fallback behavior.
0e516d7 to
8a09dbf
Compare
cloudinit/reporting/handlers.py
Outdated
| ) | ||
|
|
||
| self._vm_id = self.ZERO_GUID | ||
| self._vm_id_provider = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this feels like overkill as opposed to breaking the dependency cycle and querying it directly, let's sync on this to discuss
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per offline discussion:
rather than doing it this way, going to try removing the imports that lead to the circular dependency issue and sort out how to do the necessary imports for the kvp_handler (+ the change made to request it when required)
Include vm_id in KVP telemetry event keys for Azure host-side VM correlation. Break circular import by removing report_diagnostic_event from identity.py - Azure's kvp.py now sets vm_id via identity module when get_kvp_handler() is called.
80da91b to
aa18e0b
Compare
|
Hello! Thank you for this proposed change to cloud-init. This pull request is now marked as stale as it has not seen any activity in 14 days. If no activity occurs within the next 7 days, this pull request will automatically close. If you are waiting for code review and you are seeing this message, apologies! Please reply, tagging blackboxsw, and he will ensure that someone takes a look soon. (If the pull request is closed and you would like to continue working on it, please do tag blackboxsw to reopen it.) |
|
I just removed the stale-pr label, but I haven't taken a look at this yet because CI is still failing. @peytonr18 do you expect to continue working on this PR? |
|
Hi @holmanb, I didn't realize it was failing the CI before I went on holiday. I'll resolve the mypy error and work to get approvals from my team on the PR so that it'll be ready for your approval. Thanks! |
anhvoms
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Proposed Commit Message
Additional Context
The VM ID is now queried during
HyperVKvpReportingHandlerinitialization and appended to each event key.Changes include:
vm_idduringHyperVKvpReportingHandlerinitializationvm_idas instance attribute with fallback tozero-guidstring_event_key_format_parts()to includevm_idin key structureCLOUD_INIT|<incarnation>|<event_type>|<event_name>|<uuid>|<vm_id>[|subevent_index]test_vm_id_fallback_to_zero_guidunit test to verify fallback logic.vm_idin key, wherevm_idis 26bd6c2f-ecc6-4b04-9f79-e500096ee45b:Merge Type