[App Service] az webapp troubleshoot status: provide latest application startup attempt data#33673
[App Service] az webapp troubleshoot status: provide latest application startup attempt data#33673aamos-company wants to merge 22 commits into
az webapp troubleshoot status: provide latest application startup attempt data#33673Conversation
|
Validation for Azure CLI Full Test Starting...
Thanks for your contribution! |
|
Hi @aamos-company, |
|
Validation for Breaking Change Starting...
Thanks for your contribution! |
|
Thank you for your contribution @aamos-company! We will review the pull request and get back to you soon. |
az webapp troubleshoot: provide latest application startup attempt data
There was a problem hiding this comment.
Pull request overview
This PR extends the App Service command module with new runtime-status troubleshooting capabilities by introducing a webapp status command (ARM siteStatus) and a preview webapp troubleshoot status command (ARM siteStatus + SCM startup summary), plus associated help, params, and tests.
Changes:
- Add
az webapp statusto fetch per-instance Site Runtime Status (ARMsiteStatus), including--instancefiltering and table formatting. - Add preview
az webapp troubleshoot statusto combine ARM runtime status with SCM startup summary, rendered as a human-readable report for table output. - Add scenario + mocked tests and a new recording; update HISTORY entry.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/azure-cli/HISTORY.rst | Adds history note for the new az webapp status command. |
| src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_webapp_commands.py | Adds live scenario coverage for az webapp status. |
| src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_webapp_commands_thru_mock.py | Adds mocked unit tests for troubleshoot status, webapp status, and output transform behavior. |
| src/azure-cli/azure/cli/command_modules/appservice/tests/latest/recordings/test_webapp_status.yaml | Adds VCR recording for the new scenario test. |
| src/azure-cli/azure/cli/command_modules/appservice/custom.py | Implements show_webapp_status, troubleshoot_status, formatting, and status-tip logging. |
| src/azure-cli/azure/cli/command_modules/appservice/commands.py | Registers new commands and table transformers. |
| src/azure-cli/azure/cli/command_modules/appservice/_params.py | Adds --instance parameter wiring for webapp status and webapp troubleshoot status. |
| src/azure-cli/azure/cli/command_modules/appservice/_help.py | Adds help for webapp status and the preview webapp troubleshoot group/command. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for item in runtime_items: | ||
| _fetch_startup_summary(item) | ||
|
|
||
| # --- 3. Assemble payload --- |
|
App Service |
az webapp troubleshoot: provide latest application startup attempt dataaz webapp troubleshoot status: provide latest application startup attempt data
- Correlate ARM /siteStatus items with KuduLite startup summaries by machineName first, then fall back to cardinality pairing (one unmatched item + one unmatched startup) for the common single-instance case. - Any KuduLite entries still unmatched surface under a new orphanStartups bucket in the payload; renderer prints them as separate 'Instance X Startup Summary (no matching ARM instance)' cards. - When ARM's machineName and SCM's InstanceId disagree, per-instance header shows 'Instance <machine> Full Status Report (SCM: <scm-id>)'. - _emit_labeled hanging-indent helper wraps long Details / Last Error / Last Error Details / Last Error Timestamp values under the value column. - Switch overview table header + underline to Style.PRIMARY; use - * 76 separators around instance headers; upgrade Hint: label to '▶ Hint:'. - Suppress the 'machine name could not be determined' fallback when we successfully paired via cardinality (inst has a startup even without a machineName). - _help.py: drop ARM /siteStatus implementation detail and reword long-summary to match troubleshoot-config phrasing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: da04b3ec-d5e4-4ab8-aeea-58dd7010ac84
- Remove duplicate/unused top-level 'import os' and 'import sys' (avoid W0404/W0611).
- Remove _log_webapp_status_tip helper and all cross-promotion call sites in
create_webapp, webapp_up, and _poll_deployment_runtime_status; the tip
suggested 'az webapp status' which is out of scope for this PR and (with
the group nesting) would not resolve.
- Pin troubleshoot_status api-version to a validated literal ('2024-11-01')
instead of reading protected client._config.api_version, so the URL doesn't
drift if the SDK bumps its default.
- Update mock tests to assert 2024-11-01 URLs.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: da04b3ec-d5e4-4ab8-aeea-58dd7010ac84
The 'webapp troubleshoot' group scaffolding is owned by this PR; Azure#33709 (config) will drop its duplicate helps entry. Broaden the group summary from the placeholder 'Troubleshoot a web app.' to something that fits both 'status' and the incoming 'config' subcommand. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: da04b3ec-d5e4-4ab8-aeea-58dd7010ac84
Move the ~340-line report renderer and its 12 helpers out of custom.py into a dedicated module (_troubleshoot_status_report.py) with a single public entry point, render_report(payload). custom.py now lazily imports it only on the --report path. No behavioral change; keeps custom.py review-friendly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: da04b3ec-d5e4-4ab8-aeea-58dd7010ac84
transform_troubleshoot_status_output imports _format_dt, _most_recent_startup, and _startup_fetch_failed which have moved from custom.py to _troubleshoot_status_report.py. Point the import at the new module so 'az webapp troubleshoot status -o table' stops failing with 'Table output unavailable.' Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: da04b3ec-d5e4-4ab8-aeea-58dd7010ac84
…o table Match the --report view: use _short_id() for the InstanceId column, format LastErrorTimestamp via _format_dt(), and surface the lastErrorDetails field as its own column whenever the LastError columns are shown. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: da04b3ec-d5e4-4ab8-aeea-58dd7010ac84
Any None/empty value in a shown column now renders as '-' so a healthy instance's LastError/LastErrorDetails or a Kudu fetch failure's Succeeded/Failed/Updated are visually distinct from an accidentally blank row. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: da04b3ec-d5e4-4ab8-aeea-58dd7010ac84
Adds a per-instance `Details` column (from `inst.details`) so the table surfaces the same short state description the report shows. When at least one instance reports a visible error, registers an `atexit` callback that writes the recommended follow-up `az webapp log tail` / `az webapp log startup show` commands to stderr AFTER the table has flushed to stdout, matching the --report hint footer. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: da04b3ec-d5e4-4ab8-aeea-58dd7010ac84
Rename Succeeded/Failed/Updated to Succeeded (last 24h) / Failed (last 24h) / Updated (last 24h) so the columns' 24-hour window is obvious without cross-referencing the report. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: da04b3ec-d5e4-4ab8-aeea-58dd7010ac84
The most-recent-attempt timestamp is redundant on the summary table; keep it in --report / structured output. Also drop the now-unused _format_dt / _most_recent_startup imports. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: da04b3ec-d5e4-4ab8-aeea-58dd7010ac84
… cell Removing the Updated column dropped _format_dt from the transformer's import list, but the LastErrorTimestamp cell still calls _format_dt inside the show_errors branch. When any instance reported a visible error, the transformer raised NameError which knack surfaces as the opaque 'Table output unavailable' message. Re-import _format_dt and add a regression test that drives the transformer with an errored instance so this path is covered. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: da04b3ec-d5e4-4ab8-aeea-58dd7010ac84
- surface SCM transport errors via SummaryFetchStatus when requests.get raises - _params.py: grammar Default to -> Defaults to Adds a regression test covering the SCM RequestException path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: da04b3ec-d5e4-4ab8-aeea-58dd7010ac84
Drop the SCM error details and endpoint URL from the fallback message so the report reads cleanly. The report renderer no longer prefixes with 'Startup summary unavailable:' since the new message is self-describing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: da04b3ec-d5e4-4ab8-aeea-58dd7010ac84
| ]) for r in result] | ||
|
|
||
|
|
||
| def transform_troubleshoot_status_output(result): |
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| """Human-readable report rendering for 'az webapp troubleshoot status --report'. |
…n ARM is empty When /siteStatus returns no instances the report now explains that this is normal for a healthy app and links the two standard follow-up commands. If SCM returned startup summaries anyway, still render them under the orphan block instead of bailing early. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: da04b3ec-d5e4-4ab8-aeea-58dd7010ac84
…ic label Use portal-oriented guidance rather than exposing internal ARM/SCM plumbing. Also drop the '(no matching ARM instance)' qualifier from the orphan startup header. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: da04b3ec-d5e4-4ab8-aeea-58dd7010ac84





Related command
az webapp troubleshoot statusDescription
Introduces the az webapp troubleshoot status command for diagnosing Linux web apps without leaving the terminal.
az webapp troubleshoot statusReports per-instance runtime health and recent startup outcomes for a Linux web app.
Data sources
• Site Runtime Status — ARM
GET .../sites/{name}[/slots/{slot}]/siteStatus[/{instanceId}]?api-version=2024-11-01• Per-instance startup summary — KuduLite
GET https://{scm-host}/api/startuplogs/summary[?instance={id}]• Machine-name ↔ ARM hex id mapping — ARM /instances , so --instance accepts either form.
What it surfaces
• Per-instance State + Details, LastError / LastErrorDetails / LastErrorTimestamp (hidden for Started instances or when there have been no failed startups in the report window), and the last 24h Succeeded / Failed / most-recent-attempt counts.
• Handles KuduLite SummaryFetchStatus failures gracefully (missing startup summary is reported per instance, not silently zeroed).
• Correlates orphan startup entries (instances the log endpoint knows about but ARM no longer lists) so nothing is dropped.
Testing Guide
Images attached in the comments
This checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.