Skip to content

Conversation

@peytonr18
Copy link
Contributor

@peytonr18 peytonr18 commented Oct 30, 2025

Proposed Commit Message

feat(azure): add vm_id to KVP telemetry event keys

Add VM ID to the KVP (Key-Value Pair) event key format to improve
telemetry tracking and debugging capabilities for Azure/Hyper-V
deployments.

Additional Context

The VM ID is now queried during HyperVKvpReportingHandler initialization and appended to each event key.
Changes include:

  • Query vm_id during HyperVKvpReportingHandler initialization
  • Store vm_id as instance attribute with fallback to zero-guid string
  • Update _event_key_format_parts() to include vm_id in key structure
  • Update event key format to:
    CLOUD_INIT|<incarnation>|<event_type>|<event_name>|<uuid>|<vm_id>[|subevent_index]
  • Added test_vm_id_fallback_to_zero_guid unit test to verify fallback logic.
  • Production test shows vm_id in key, where vm_id is 26bd6c2f-ecc6-4b04-9f79-e500096ee45b:
CLOUD_INIT|1762458786|finish|modules-final|b8398a61-459c-4e35-95fd-c3a099396a02|26bd6c2f-ecc6-4b04-9f79-e500096ee45b{"name":"modules-final","type":"finish","ts":"2025-11-06T19:53:30.941724+00:00","result":"SUCCESS","msg":"running modules for final"}

Merge Type

  • Squash merge using "Proposed Commit Message"

@peytonr18 peytonr18 marked this pull request as ready for review November 6, 2025 19:28
)

try:
from cloudinit.sources.azure.identity import query_vm_id
Copy link
Contributor

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?

Copy link
Contributor Author

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!

Copy link
Member

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.

Copy link
Contributor

@cjp256 cjp256 Dec 5, 2025

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.
@peytonr18 peytonr18 force-pushed the probertson-kvp-vm-id branch from 5e5a253 to 7b66c56 Compare November 18, 2025 01:28
@peytonr18
Copy link
Contributor Author

A request was made outside of this PR to re-order uuid and vm_id to ensure RdAgent can distinguish the key, which is the reason for the change in the most recent commit.

@github-actions
Copy link

github-actions bot commented Dec 3, 2025

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.)

@github-actions github-actions bot added stale-pr Pull request is stale; will be auto-closed soon and removed stale-pr Pull request is stale; will be auto-closed soon labels Dec 3, 2025
@holmanb holmanb self-assigned this Dec 8, 2025
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.
@peytonr18 peytonr18 force-pushed the probertson-kvp-vm-id branch from 9d0e689 to fa77a7a Compare December 9, 2025 23:33
@peytonr18
Copy link
Contributor Author

Per offline discussion,
There was concern about pulling the same code in azure.identity.py into the reporter, as well as importing the code from the azure module (which is what was done previously).

The current suggestion is to instead have the datasource set vm_id via azure's get_kvp_handler() method, with the eventual goal of eventually caching the vm_id in a shared location and moving all KVP logic out of the HyperVReportingHandler.

@peytonr18 peytonr18 force-pushed the probertson-kvp-vm-id branch from a2a7dcd to 0e516d7 Compare December 12, 2025 23:19
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.
@peytonr18 peytonr18 force-pushed the probertson-kvp-vm-id branch from 0e516d7 to 8a09dbf Compare December 15, 2025 20:39
)

self._vm_id = self.ZERO_GUID
self._vm_id_provider = None
Copy link
Contributor

@cjp256 cjp256 Dec 15, 2025

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

Copy link
Contributor Author

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.
@peytonr18 peytonr18 force-pushed the probertson-kvp-vm-id branch from 80da91b to aa18e0b Compare December 16, 2025 20:30
@github-actions
Copy link

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.)

@github-actions github-actions bot added the stale-pr Pull request is stale; will be auto-closed soon label Dec 31, 2025
@holmanb holmanb removed the stale-pr Pull request is stale; will be auto-closed soon label Jan 5, 2026
@holmanb
Copy link
Member

holmanb commented Jan 5, 2026

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?

@peytonr18
Copy link
Contributor Author

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!

Copy link
Contributor

@anhvoms anhvoms left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants