feat(hcpctl): add velero backup queries to snapshot gatherer #6813
Kusto has is term-based; HostedClusterNamespace includes hyphens (e.g., ocm-pers-...) and using has can devolve into matching on individual terms, causing unrelated DeleteBackupRequest rows to be included. Use contains to require the full namespace token as a substring of the backup name.
Kusto has_any is term-based; namespace strings like ocm-pers-2abc (with -) may be tokenized and can match unrelated log lines (e.g., just the ocm term), producing false positives. Prefer substring matching for these namespace tokens.
🟡 Changes recommended
The new Velero log/CR queries use Kusto has/has_any with hyphenated namespace tokens, which can produce incorrect (over-broad) matches and should be corrected before merge.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
<details>
<summary>Pull request overview</summary>
This PR extends hcpctl snapshot’s Kusto-backed snapshot gatherer to collect Velero backup health signals (CR history + aggregated component/server logs), so offline snapshot analysis can reason about backup failures without manual cross-correlation.
Changes:
pkg/snapshot/queries/velero (Backups/Schedules/DataUploads/DeleteBackupRequests + logs + serverLogs) plus a mgmtCluster discovery query to scope server logs to the right management cluster(s).</details>
<details>
<summary>File summaries</summary>
| File | Description |
| ---- | ----------- |
| tooling/hcpctl/pkg/snapshot/queries/velero/serverLogs/README.md | Documents the shared (cross-HCP) Velero server log query semantics and triage guidance. |
| tooling/hcpctl/pkg/snapshot/queries/velero/serverLogs/query.kql | Adds KQL to aggregate Velero server warning/error logs, scoped by discovered management cluster list. |
| tooling/hcpctl/pkg/snapshot/queries/velero/schedules/README.md | Documents Schedule CR snapshot intent and triage guidance. |
| tooling/hcpctl/pkg/snapshot/queries/velero/schedules/query.kql | Adds KQL to snapshot Schedule CR state over time for the target HCP. |
| tooling/hcpctl/pkg/snapshot/queries/velero/mgmtCluster/README.md | Documents management-cluster discovery used to scope serverLogs. |
| tooling/hcpctl/pkg/snapshot/queries/velero/mgmtCluster/query.kql | Adds KQL to discover management cluster(s) from Velero Backup CR snapshots. |
| tooling/hcpctl/pkg/snapshot/queries/velero/logs/README.md | Documents aggregated per-HCP Velero component logs query. |
| tooling/hcpctl/pkg/snapshot/queries/velero/logs/query.kql | Adds KQL to aggregate Velero component logs associated with the HCP’s namespaces. |
| tooling/hcpctl/pkg/snapshot/queries/velero/deleteBackupRequests/README.md | Documents DeleteBackupRequest CR snapshots and how to correlate them. |
| tooling/hcpctl/pkg/snapshot/queries/velero/deleteBackupRequests/query.kql | Adds KQL to snapshot DeleteBackupRequest CR state for the HCP. |
| tooling/hcpctl/pkg/snapshot/queries/velero/dataUploads/README.md | Documents DataUpload CR snapshot intent and failure triage hints. |
| tooling/hcpctl/pkg/snapshot/queries/velero/dataUploads/query.kql | Adds KQL to snapshot DataUpload CR state over time for the HCP. |
| tooling/hcpctl/pkg/snapshot/queries/velero/backups/README.md | Documents Backup CR snapshot intent and triage guidance. |
| tooling/hcpctl/pkg/snapshot/queries/velero/backups/query.kql | Adds KQL to snapshot Backup CR phase transitions and failure metadata over time. |
| tooling/hcpctl/pkg/snapshot/queries.go | Introduces ManagementClusterNames, adds Velero query specs (including mgmtCluster discovery) to the query chain. |
| tooling/hcpctl/pkg/snapshot/queries_test.go | Adds unit tests for template rendering, readiness gating, IN-list rendering, and discovery result handling. |
| tooling/hcpctl/pkg/snapshot/gatherer.go | Seeds ManagementClusterNames from the PR-job hint to scope serverLogs. |
</details>
<details>
<summary>Review details</summary>
</details>
---
💡 <a href="/Azure/ARO-HCP/new/main?filename=.github/skills/code-review/SKILL.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add a code-review agent skill</a> or configure MCP servers for context-aware, tailored reviews. <a href="https://docs.github.com/copilot/how-tos/use-copilot-agents/request-a-code-review/use-code-review?tool=webui#mcp-servers-and-agent-skills" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn more in the docs.</a>
tried it out. Is not correct: print "test" contains 'test-ab' returns false
not correct, see above.
/ok-to-test
@tmstff: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:
Test name | Commit | Details | Required | Rerun command
--- | --- | --- | --- | ---
ci/prow/e2e-parallel | 4a5aea6cd3a0485cade670b99e2a3f7a2e59ebbb | link | true | /test e2e-parallel
Full PR test history. Your PR dashboard.
<details>
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.
</details>
<!-- test report -->
/area tooling
The shared-plane query is documented as covering both Velero server and node-agent failures, but this filter drops every node-agent log. Because node-agent is a management-cluster-wide DaemonSet, its errors are part of the cross-HCP signal; include both shared containers here (the HCP-scoped query can continue to cover data-mover logs).
This says the discovery query fills the list from container logs, but velero/mgmtCluster/query.kql reads kubernetesResourceSnapshots and derives the cluster from Velero Backup CRs. Please correct the comment so it does not send future maintainers to the wrong data source.
This test adds a *.windows.net endpoint to the repository. The PR standards prohibit committing URLs in that internal domain, even as test placeholders; use a non-internal placeholder domain instead so the test does not leak or trigger the URL policy.
<!-- ccr-overview-v2 -->
Copilot review overview
🟡 Changes recommended
Moderate query coverage issues and documentation/test corrections remain unresolved.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> · 2 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.png" alt="Low severity" width="62" height="18" align="texttop"></picture>
<details open>
<summary><strong>Open (3)</strong></summary>
</details>
<details>
<summary><strong>Resolved since last review (2)</strong></summary>
has_any is term-based; namespace strings like ocm-pers-2abc (with -) may be tokenized…](#discussion_r3924660378)has is term-based; HostedClusterNamespace includes hyphens (e.g., ocm-pers-...) and…](#discussion_r3924660311)</details>
<!-- ccr-overview-v2 -->
Copilot review overview
🔵 Needs a closer look
Unresolved findings affect shared-plane coverage, management-cluster gating, log ordering, and committed test data.
Review effort: Lite
Findings: 1 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> · 2 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.png" alt="Low severity" width="62" height="18" align="texttop"></picture>
<details open>
<summary><strong>Open (3)</strong></summary>
</details>
Fixed in 87265fac0: changed has -> contains so the hyphenated namespace token (e.g. ocm-pers-2abc) is matched as a full substring of the backup name rather than tokenized into individual terms.
Fixed in 87265fac0: replaced has_any(...) with log contains '...' or log contains '...' (Kusto has no contains_any), so hyphenated namespace tokens match as substrings instead of terms.
Fixed in 87265fac0: now container_name in ('velero', 'node-agent'), so the shared-plane query covers the management-cluster-wide node-agent DaemonSet as documented. README summary updated to mention node-agent explicitly.
Fixed in 87265fac0: corrected the comment — the velero/mgmtCluster discovery query reads the HCP's Velero Backup CR snapshots (kubernetesResourceSnapshots), not container logs.
Fixed in 87265fac0: replaced the *.windows.net placeholder with https://example.kusto.example.com; no other windows.net occurrences in the test file.
The template at logs/query.kql:7 matches both namespace tokens, but this predicate only requires HostedControlPlaneNamespace. When the hosted-cluster namespace is unavailable, rendering produces log contains '', which matches every log line in the Velero namespace and pulls unrelated HCP logs into the snapshot. Require both namespace values before scheduling this query.
<!-- ccr-overview-v2 -->
Copilot review overview
🟡 Changes recommended
Unresolved query-scoping, log aggregation, discovery, test-coverage, and verification findings remain.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture>
<details open>
<summary><strong>Open (1)</strong></summary>
</details>
<details>
<summary><strong>Resolved since last review (3)</strong></summary>
</details>
This seed is not authoritative when the resource group has any ARM traffic: Gather still runs frontendRequests/discoverRequests, and runDiscovery chooses the first request's cluster before falling back to the seed. As a result, from-cluster can emit request-scoped sections and gather a different cluster (or multiple clusters) instead of the requested identity, contrary to the command's documented behavior. Skip request discovery for identity-seeded runs, or make the identity seed take precedence and suppress per-request output.
The identity seed is only used when no request-derived cluster ID was found. As soon as the resource group has any mutating ARM request, the first request's cluster wins, so from-cluster can run Cosmos discovery for a different cluster and violates the documented explicit-seed precedence. Select the identity seed before request-derived discovery (and keep request discovery from overriding it).
The new --query-timeout option is documented as applying to individual Kusto queries, but the subscription/resource-group resolution query always uses a hard-coded two-minute timeout. This makes the first query ignore the user's timeout setting; pass input.QueryTimeout here so resolution follows the same contract as the other gatherer queries.
<!-- ccr-overview-v2 -->
Copilot review overview
🟡 Changes recommended
Explicit seed precedence and management-cluster discovery have unresolved issues that can gather the wrong cluster or omit Velero evidence.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 3 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> · 1 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture>
<details open>
<summary><strong>Open (4)</strong></summary>
</details>
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: <a href="https://github.com/Azure/ARO-HCP/pull/6813#" title="Author self-approved">tmstff</a>
Once this PR has been reviewed and has the lgtm label, please assign janboll for approval. For more information see the Code Review Process.
The full list of commands accepted by this bot can be found here.
<details open>
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
</details>
<!-- META={"approvers":["janboll"]} -->
These registrations still depend on the existing request-driven discovery pipeline: runDiscovery only creates resources from frontend requests (and Cosmos discovery seeded by one of those requests), and gatherPhase is the only place that executes these state/log queries. With an idle cluster, no request means no resource and therefore no mgmtCluster or Velero query runs. The described from-cluster identity seed is not present in GatherInput or the snapshot command, so the idle-cluster scenario this PR claims to fix still produces an empty snapshot; add the seed/CLI path (including manifest provenance) or remove that claim from the PR scope.
When no Backup CR for the HCP exists in the full window—for example, a schedule never created its first backup—this discovery query returns no management-cluster names. The serverLogs, backupStorageLocations, and volumeSnapshotLocations predicates then remain false, so all shared-plane Velero signals are omitted precisely for that idle/failing-schedule case. Management-cluster discovery needs a fallback that does not depend on an existing Backup CR, or the shared queries need another valid seed.
<!-- ccr-overview-v2 -->
Copilot review overview
🟡 Changes recommended
The identity-seeded workflow is missing, and Velero discovery can be skipped without namespace or management-cluster fallbacks.
Review effort: Lite
Findings: 4 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> · 2 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture>
<details open>
<summary><strong>Open (6)</strong></summary>
</details>
tmstff
Why
hcpctl snapshotgathers cluster-state snapshots for offline analysis, but has no visibility into Velero backup health. When a backup fails, there is currently no snapshot signal to reason over — SREs must correlate Velero state by hand.This PR wires the Velero backup signals into the snapshot gatherer as groundwork so the data can subsequently be surfaced to
hcpctl snapshot analyze.Tracked by ARO-29442 (child of Epic ARO-22221 — Backup Operations & Monitoring). This is the deferred "snapshot" step split out of the must-gather work in ARO-28989 / #6791.
What
pkg/snapshot/queries/velero:backups,schedules,dataUploads,deleteBackupRequests,backupStorageLocations,volumeSnapshotLocations,logs,serverLogs, plus amgmtClusterhelper query.This covers the full CR / data set collected by the must-gather Velero queries in #6791: Backups, Schedules, DataUploads, DeleteBackupRequests, BackupStorageLocations, VolumeSnapshotLocations, plus velero server and HCP-scoped component logs.
Design notes
Mirrors the must-gather Velero query design from #6791:
serverLogs,backupStorageLocations, andvolumeSnapshotLocationsare cross-HCP / cluster-scoped by design — the velero server + node-agent and the BSL/VSL config CRs are shared per management cluster and carry no per-HCP ARM resource-id token. These are scoped to the management cluster(s) hosting the HCP viaManagementClusterNames(discovered by themgmtClusterquery) and gated off until that set is known.Scope
Independent of #6791 — touches only
pkg/snapshot(untouched by that PR), so this is based directly onmain.Follow-up
Consuming this data in
hcpctl snapshot analyze(prompt/render + correlation) is the remaining part of ARO-29442. The ARM-request-independentfrom-clusterentrypoint (needed to reach these queries for idle clusters) is split into #7220.🤖 Generated with Claude Code