[Not For Review]: Decouple Health Reporting from Provisioning #271
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR decouples the health reporting logic from the provisioning process, enabling independent retry capabilities and more flexible failure handling. Previously, provisioning and health reporting were tightly coupled—if reporting failed, the entire provisioning would be marked as failed. Now, provisioning writes state files that can be reported separately, allowing retries without re-provisioning.
Changes
Core Library Changes
libazureinit/src/error.rsAlreadyReportederror variant for idempotent reportingNoProvisioningStateerror when no state files existInvalidStateFileerror for malformed state fileslibazureinit/src/health.rsreport_ready_from_state()- Reports provisioning success by reading from.provisionedstate filereport_failure_from_state()- Reports provisioning failure by reading from.failedstate fileload_state_file()- Loads config and state file with proper locking and validationlibazureinit/src/status.rsmark_provisioning_failure()- Creates.failedstate file with encoded error reporthas_been_reported()- Checks if state file has been reported (contains "REPORTED" marker)mark_reported()- Appends "REPORTED" marker to state file after successful reportget_provisioning_dir()public for external accessmark_provisioning_complete()with file locking for thread safetylibazureinit/src/lib.rsreport_ready_from_state(),report_failure_from_state()mark_provisioning_failure(),mark_reported()statusmodule publicCLI Changes (
src/main.rs)New
reportSubcommandNew
--reportFlagazure-init --report # Provision AND report in one stepUpdated Provisioning Flow
{vm_id}.provisionedfile with success report (no immediate Azure reporting){vm_id}.failedfile with error report (no immediate Azure reporting)Updated
cleanCommand.provisionedand.failedfilesTest Changes (
tests/cli.rs)setup_clean_test()to create both.provisionedand.failedfileshelp_shows_report_command()- Verifies report command in help textreport_help_shows_subcommands()- Verifies report subcommands existreport_auto_fails_without_state_files()- Verifies graceful failurereport_ready_fails_without_provisioned_file()- Verifies error handlingreport_failure_fails_without_failed_file()- Verifies error handlingFlow Diagram
New Provisioning and Reporting Flow
Usage Examples
Scenario 1: Decouple Provisioning and Reporting (Recommended)
Scenario 2: Provision and Report Together
# Single command does both (legacy-style behavior) azure-init --reportScenario 3: Manual Report Commands
Scenario 4: Clean State Files
Breaking Changes
The default behavior (running
azure-initalone) maintains backward compatibility:--reportflag orreportsubcommandUsers relying on immediate health reporting should:
--reportflag to existing commands, ORazure-init report autoRelated Issues
Closes #263