← Back to Pull requests

feat(hcpctl): add velero backup queries to snapshot gatherer #6813

Open
tmstff opened this pull request with 668 lines diff across 21 files
View on GitHub
tmstff tmstff commented on Sep 03, 2026 12:35 UTC
Author

⚠ Unverified ⚠

> * Completely AI generated, nothing verified so far. Can be taken as basis, but the actual effort (verification) is still missing.

Why

hcpctl snapshot gathers 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

  • Adds eight Velero query specs under pkg/snapshot/queries/velero: backups, schedules, dataUploads, deleteBackupRequests, backupStorageLocations, volumeSnapshotLocations, logs, serverLogs, plus a mgmtCluster helper query.

  • Seeds the management-cluster name(s) in the gatherer so the queries scope correctly.

  • Registers the queries in the snapshot query set, with tests.
  • 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, and volumeSnapshotLocations are 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 via ManagementClusterNames (discovered by the mgmtCluster query) and gated off until that set is known.

  • The remaining HCP-scoped queries pin to the HCP via Backup-CR namespace / resource tokens.
  • Scope

    Independent of #6791 — touches only pkg/snapshot (untouched by that PR), so this is based directly on main.

    Follow-up

    Consuming this data in hcpctl snapshot analyze (prompt/render + correlation) is the remaining part of ARO-29442. The ARM-request-independent from-cluster entrypoint (needed to reach these queries for idle clusters) is split into #7220.

    🤖 Generated with Claude Code

    Diff: 668 lines (+668 / -0) across 21 files Reviewer: tmstff Review duration: 52740m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.91) × (1 − Review Confidence (0.81)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.91 · 668 lines diff across 21 files
    0.91
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.89 · 5 substantive comment(s)
    0.89
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    81%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.389
    Self Review self_review
    0.140
    Mass File Touch mass_file_touch
    0.080
    Real PR Conversation Timeline
    29 items
    Copilot Copilot commented on code on Sep 03, 2026 12:46 UTC
    Code Review
    tooling/hcpctl/pkg/snapshot/queries/velero/deleteBackupRequests/query.kql:1
    @@ -0,0 +1,15 @@
    +cluster('{{ .ClusterURI }}').database('{{ .ServiceDatabase }}').table('kubernetesResourceSnapshots')
    +| where timestamp between ({{ kqlDatetime .PhaseStartTime }} .. {{ kqlDatetime .PhaseEndTime }})
    +{{- if and .ServiceClusterName .ManagementClusterName }}
    +| where cluster in ('{{ .ServiceClusterName }}', '{{ .ManagementClusterName }}')
    +{{- end }}
    +| where objectKind == 'DeleteBackupRequest'
    +| where namespace == 'velero'
    +| where tostring(object.metadata.labels['velero.io/backup-name']) has '{{ .HostedClusterNamespace }}'

    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.

    Copilot Copilot commented on code on Sep 03, 2026 12:46 UTC
    Code Review
    tooling/hcpctl/pkg/snapshot/queries/velero/logs/query.kql:1
    @@ -0,0 +1,16 @@
    +cluster('{{ .ClusterURI }}').database('{{ .ServiceDatabase }}').table('containerLogs')
    +| where timestamp between ({{ kqlDatetime .PhaseStartTime }} .. {{ kqlDatetime .PhaseEndTime }})
    +{{- if and .ServiceClusterName .ManagementClusterName }}
    +| where cluster in ('{{ .ServiceClusterName }}', '{{ .ManagementClusterName }}')
    +{{- end }}
    +| where namespace_name == 'velero'
    +| where log has_any ('{{ .HostedClusterNamespace }}', '{{ .HostedControlPlaneNamespace }}')

    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.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 03, 2026 12:46 UTC
    Reviewer

    🟡 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:

  • Adds a Velero query suite under 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).

  • Wires management-cluster name seeding into the gatherer and registers the new queries into the snapshot query chain.

  • Adds unit tests to ensure templates render, Velero query readiness gating is correct, and mgmt-cluster discovery results are stored.

  • </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>

  • Files reviewed: 17/17 changed files

  • Comments generated: 2

  • Review effort level: Lite

  • </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>

    tmstff tmstff commented on code on Sep 16, 2026 07:35 UTC
    Code Review
    tooling/hcpctl/pkg/snapshot/queries/velero/deleteBackupRequests/query.kql:1
    @@ -0,0 +1,15 @@
    +cluster('{{ .ClusterURI }}').database('{{ .ServiceDatabase }}').table('kubernetesResourceSnapshots')
    +| where timestamp between ({{ kqlDatetime .PhaseStartTime }} .. {{ kqlDatetime .PhaseEndTime }})
    +{{- if and .ServiceClusterName .ManagementClusterName }}
    +| where cluster in ('{{ .ServiceClusterName }}', '{{ .ManagementClusterName }}')
    +{{- end }}
    +| where objectKind == 'DeleteBackupRequest'
    +| where namespace == 'velero'
    +| where tostring(object.metadata.labels['velero.io/backup-name']) has '{{ .HostedClusterNamespace }}'

    tried it out. Is not correct: print "test" contains 'test-ab' returns false

    tmstff tmstff commented on code on Sep 16, 2026 07:36 UTC
    Code Review
    tooling/hcpctl/pkg/snapshot/queries/velero/logs/query.kql:1
    @@ -0,0 +1,16 @@
    +cluster('{{ .ClusterURI }}').database('{{ .ServiceDatabase }}').table('containerLogs')
    +| where timestamp between ({{ kqlDatetime .PhaseStartTime }} .. {{ kqlDatetime .PhaseEndTime }})
    +{{- if and .ServiceClusterName .ManagementClusterName }}
    +| where cluster in ('{{ .ServiceClusterName }}', '{{ .ManagementClusterName }}')
    +{{- end }}
    +| where namespace_name == 'velero'
    +| where log has_any ('{{ .HostedClusterNamespace }}', '{{ .HostedControlPlaneNamespace }}')

    not correct, see above.

    tmstff tmstff commented on Sep 18, 2026 05:13 UTC
    Author

    /ok-to-test

    openshift-ci[bot] openshift-ci[bot] commented on Sep 18, 2026 07:09 UTC
    Bot

    @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 -->

    raelga raelga commented on Sep 22, 2026 10:43 UTC
    Contributor

    /area tooling

    Copilot Copilot commented on code on Sep 25, 2026 11:05 UTC
    Code Review
    tooling/hcpctl/pkg/snapshot/queries/velero/serverLogs/query.kql:1
    @@ -0,0 +1,18 @@
    +cluster('{{ .ClusterURI }}').database('{{ .ServiceDatabase }}').table('containerLogs')
    +| where timestamp between ({{ kqlDatetime .PhaseStartTime }} .. {{ kqlDatetime .PhaseEndTime }})
    +{{- if gt (len .ManagementClusterNames) 0 }}
    +| where cluster in ({{ range $i, $c := .ManagementClusterNames }}{{ if $i }}, {{ end }}'{{ $c }}'{{ end }})
    +{{- end }}
    +| where namespace_name == 'velero'
    +| where container_name == 'velero'

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

    Copilot Copilot commented on code on Sep 25, 2026 11:05 UTC
    Code Review
    tooling/hcpctl/pkg/snapshot/gatherer.go:1
    @@ -276,6 +276,11 @@ func (g *Gatherer) Gather(ctx context.Context, input GatherInput, outputDir stri
     		PhaseStartTime: input.TimeWindow.Start,
     		PhaseEndTime:   input.TimeWindow.End,
     	}
    +	// Seed the management-cluster list from the PR-job hint. When absent, the
    +	// velero/mgmtCluster discovery query fills it from container 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.

    Copilot Copilot commented on code on Sep 25, 2026 11:05 UTC
    Code Review
    tooling/hcpctl/pkg/snapshot/queries_test.go:1
    @@ -0,0 +1,179 @@
    +// Copyright 2025 Microsoft Corporation
    +//
    +// Licensed under the Apache License, Version 2.0 (the "License");
    +// you may not use this file except in compliance with the License.
    +// You may obtain a copy of the License at
    +//
    +//     http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing, software
    +// distributed under the License is distributed on an "AS IS" BASIS,
    +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +// See the License for the specific language governing permissions and
    +// limitations under the License.
    +
    +package snapshot
    +
    +import (
    +	"strings"
    +	"testing"
    +	"time"
    +)
    +
    +// fullQueryData returns a queryData with every field populated, so that every
    +// template renders down a non-empty branch.
    +func fullQueryData() queryData {
    +	now := time.Date(2026, 1, 2, 3, 4, 5, 0, time.UTC)
    +	return queryData{
    +		ClusterURI:                  "https://example.kusto.windows.net",

    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.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 25, 2026 11:05 UTC
    Reviewer

    <!-- 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>

  • <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> [Include node-agent logs in shared-plane query](#discussion_r4103892962) · New

  • <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> [Correct comment describing discovery query data source](#discussion_r4103892995) · New

  • <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> [Replace prohibited internal URL in test](#discussion_r4103893030) · New

  • </details>

    <details>
    <summary><strong>Resolved since last review (2)</strong></summary>

  • <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> [Kusto has_any is term-based; namespace strings like ocm-pers-2abc (with -) may be tokenized…](#discussion_r3924660378)

  • <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> [Kusto has is term-based; HostedClusterNamespace includes hyphens (e.g., ocm-pers-...) and…](#discussion_r3924660311)

  • </details>

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 25, 2026 11:28 UTC
    Reviewer

    <!-- 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>

  • <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> [Include node-agent logs in shared-plane query](#discussion_r4103892962)

  • <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> [Replace prohibited internal URL in test](#discussion_r4103893030)

  • <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> [Correct comment describing discovery query data source](#discussion_r4103892995)

  • </details>

    tmstff tmstff commented on code on Sep 25, 2026 11:42 UTC
    Code Review
    tooling/hcpctl/pkg/snapshot/queries/velero/deleteBackupRequests/query.kql:1
    @@ -0,0 +1,15 @@
    +cluster('{{ .ClusterURI }}').database('{{ .ServiceDatabase }}').table('kubernetesResourceSnapshots')
    +| where timestamp between ({{ kqlDatetime .PhaseStartTime }} .. {{ kqlDatetime .PhaseEndTime }})
    +{{- if and .ServiceClusterName .ManagementClusterName }}
    +| where cluster in ('{{ .ServiceClusterName }}', '{{ .ManagementClusterName }}')
    +{{- end }}
    +| where objectKind == 'DeleteBackupRequest'
    +| where namespace == 'velero'
    +| where tostring(object.metadata.labels['velero.io/backup-name']) has '{{ .HostedClusterNamespace }}'

    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.

    tmstff tmstff commented on code on Sep 25, 2026 11:42 UTC
    Code Review
    tooling/hcpctl/pkg/snapshot/queries/velero/logs/query.kql:1
    @@ -0,0 +1,16 @@
    +cluster('{{ .ClusterURI }}').database('{{ .ServiceDatabase }}').table('containerLogs')
    +| where timestamp between ({{ kqlDatetime .PhaseStartTime }} .. {{ kqlDatetime .PhaseEndTime }})
    +{{- if and .ServiceClusterName .ManagementClusterName }}
    +| where cluster in ('{{ .ServiceClusterName }}', '{{ .ManagementClusterName }}')
    +{{- end }}
    +| where namespace_name == 'velero'
    +| where log has_any ('{{ .HostedClusterNamespace }}', '{{ .HostedControlPlaneNamespace }}')

    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.

    tmstff tmstff commented on code on Sep 25, 2026 11:42 UTC
    Code Review
    tooling/hcpctl/pkg/snapshot/queries/velero/serverLogs/query.kql:1
    @@ -0,0 +1,18 @@
    +cluster('{{ .ClusterURI }}').database('{{ .ServiceDatabase }}').table('containerLogs')
    +| where timestamp between ({{ kqlDatetime .PhaseStartTime }} .. {{ kqlDatetime .PhaseEndTime }})
    +{{- if gt (len .ManagementClusterNames) 0 }}
    +| where cluster in ({{ range $i, $c := .ManagementClusterNames }}{{ if $i }}, {{ end }}'{{ $c }}'{{ end }})
    +{{- end }}
    +| where namespace_name == 'velero'
    +| where container_name == 'velero'

    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.

    tmstff tmstff commented on code on Sep 25, 2026 11:42 UTC
    Code Review
    tooling/hcpctl/pkg/snapshot/gatherer.go:1
    @@ -276,6 +276,11 @@ func (g *Gatherer) Gather(ctx context.Context, input GatherInput, outputDir stri
     		PhaseStartTime: input.TimeWindow.Start,
     		PhaseEndTime:   input.TimeWindow.End,
     	}
    +	// Seed the management-cluster list from the PR-job hint. When absent, the
    +	// velero/mgmtCluster discovery query fills it from container logs.

    Fixed in 87265fac0: corrected the comment — the velero/mgmtCluster discovery query reads the HCP's Velero Backup CR snapshots (kubernetesResourceSnapshots), not container logs.

    tmstff tmstff commented on code on Sep 25, 2026 11:42 UTC
    Code Review
    tooling/hcpctl/pkg/snapshot/queries_test.go:1
    @@ -0,0 +1,179 @@
    +// Copyright 2025 Microsoft Corporation
    +//
    +// Licensed under the Apache License, Version 2.0 (the "License");
    +// you may not use this file except in compliance with the License.
    +// You may obtain a copy of the License at
    +//
    +//     http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing, software
    +// distributed under the License is distributed on an "AS IS" BASIS,
    +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +// See the License for the specific language governing permissions and
    +// limitations under the License.
    +
    +package snapshot
    +
    +import (
    +	"strings"
    +	"testing"
    +	"time"
    +)
    +
    +// fullQueryData returns a queryData with every field populated, so that every
    +// template renders down a non-empty branch.
    +func fullQueryData() queryData {
    +	now := time.Date(2026, 1, 2, 3, 4, 5, 0, time.UTC)
    +	return queryData{
    +		ClusterURI:                  "https://example.kusto.windows.net",

    Fixed in 87265fac0: replaced the *.windows.net placeholder with https://example.kusto.example.com; no other windows.net occurrences in the test file.

    Copilot Copilot commented on code on Sep 25, 2026 11:49 UTC
    Code Review
    tooling/hcpctl/pkg/snapshot/queries.go:1
    @@ -802,6 +834,100 @@ var allQueries = []querySpec{
     		},
     		prerequisites: "HostedControlPlaneNamespace, ResourceType is cluster",
     	},
    +	// --- Velero: backup CRs and component logs (ARO-28989) ---
    +	{
    +		component:    "velero",
    +		queryName:    "backups",
    +		templatePath: "queries/velero/backups/query.kql",
    +		database:     "service",
    +		category:     categoryState,
    +		ready: func(d queryData) bool {
    +			return isClusterType(d) && d.ClusterResourceID != ""
    +		},
    +		prerequisites: "ClusterResourceID, ResourceType is cluster",
    +	},
    +	{
    +		component:    "velero",
    +		queryName:    "schedules",
    +		templatePath: "queries/velero/schedules/query.kql",
    +		database:     "service",
    +		category:     categoryState,
    +		ready: func(d queryData) bool {
    +			return isClusterType(d) && d.ClusterResourceID != ""
    +		},
    +		prerequisites: "ClusterResourceID, ResourceType is cluster",
    +	},
    +	{
    +		component:    "velero",
    +		queryName:    "dataUploads",
    +		templatePath: "queries/velero/dataUploads/query.kql",
    +		database:     "service",
    +		category:     categoryState,
    +		ready: func(d queryData) bool {
    +			return isClusterType(d) && d.HostedControlPlaneNamespace != ""
    +		},
    +		prerequisites: "HostedClusterNamespace, HostedControlPlaneNamespace, ResourceType is cluster",
    +	},
    +	{
    +		component:    "velero",
    +		queryName:    "deleteBackupRequests",
    +		templatePath: "queries/velero/deleteBackupRequests/query.kql",
    +		database:     "service",
    +		category:     categoryState,
    +		ready: func(d queryData) bool {
    +			return isClusterType(d) && d.HostedClusterNamespace != ""
    +		},
    +		prerequisites: "HostedClusterNamespace, ResourceType is cluster",
    +	},
    +	{
    +		component:    "velero",
    +		queryName:    "logs",
    +		templatePath: "queries/velero/logs/query.kql",
    +		database:     "service",
    +		category:     categoryLogs,
    +		ready: func(d queryData) bool {
    +			return isClusterType(d) && d.HostedControlPlaneNamespace != ""

    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.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 25, 2026 11:49 UTC
    Reviewer

    <!-- 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>

  • <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> [Require both namespaces to prevent unscoped log matches](#discussion_r4104193088) · New

  • </details>

    <details>
    <summary><strong>Resolved since last review (3)</strong></summary>

  • <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> [Include node-agent logs in shared-plane query](#discussion_r4103892962)

  • <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> [Replace prohibited internal URL in test](#discussion_r4103893030)

  • <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> [Correct comment describing discovery query data source](#discussion_r4103892995)

  • </details>

    Copilot Copilot commented on code on Sep 25, 2026 13:28 UTC
    Code Review
    tooling/hcpctl/cmd/snapshot/from_cluster_cmd.go:1
    @@ -0,0 +1,299 @@
    +// Copyright 2025 Microsoft Corporation
    +//
    +// Licensed under the Apache License, Version 2.0 (the "License");
    +// you may not use this file except in compliance with the License.
    +// You may obtain a copy of the License at
    +//
    +//     http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing, software
    +// distributed under the License is distributed on an "AS IS" BASIS,
    +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +// See the License for the specific language governing permissions and
    +// limitations under the License.
    +
    +package snapshot
    +
    +import (
    +	"context"
    +	"fmt"
    +	"net/url"
    +	"strings"
    +	"time"
    +
    +	"github.com/go-logr/logr"
    +	"github.com/spf13/cobra"
    +
    +	"github.com/Azure/azure-kusto-go/azkustodata"
    +	azcorearm "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
    +	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
    +
    +	"github.com/Azure/ARO-HCP/tooling/hcpctl/pkg/kusto"
    +	snapshotpkg "github.com/Azure/ARO-HCP/tooling/hcpctl/pkg/snapshot"
    +)
    +
    +// hcpClusterResourceType is the ARM resource type of an HCP cluster, used to
    +// validate an explicit --cluster-resource-id.
    +const hcpClusterResourceType = "Microsoft.RedHatOpenShift/hcpOpenShiftClusters"
    +
    +// RawFromClusterOptions holds the unvalidated CLI options for from-cluster.
    +type RawFromClusterOptions struct {
    +	Kusto                    string
    +	Region                   string
    +	ViaKusto                 string
    +	ViaRegion                string
    +	ServiceDatabase          string
    +	HCPDatabase              string
    +	MonitoringEventsDatabase string
    +	ClusterResourceID        string
    +	Subscription             string
    +	ResourceGroup            string
    +	StartTime                string
    +	EndTime                  string
    +	OutputDir                string
    +	QueryTimeout             time.Duration
    +	Concurrency              int
    +}
    +
    +func defaultFromClusterOptions() *RawFromClusterOptions {
    +	return &RawFromClusterOptions{
    +		ServiceDatabase:          "ServiceLogs",
    +		HCPDatabase:              "HostedControlPlaneLogs",
    +		MonitoringEventsDatabase: "MonitoringEvents",
    +		QueryTimeout:             5 * time.Minute,
    +		OutputDir:                fmt.Sprintf("snapshot-%s", time.Now().Format("20060102-150405")),
    +	}
    +}
    +
    +func bindFromClusterOptions(opts *RawFromClusterOptions, cmd *cobra.Command) error {
    +	cmd.Flags().StringVar(&opts.Kusto, "kusto", opts.Kusto, "Azure Data Explorer cluster name (required)")
    +	cmd.Flags().StringVar(&opts.Region, "region", opts.Region, "Azure Data Explorer cluster region (required)")
    +	cmd.Flags().StringVar(&opts.ViaKusto, "via-kusto", opts.ViaKusto, "Route queries through this reachable ADX cluster instead of connecting to --kusto directly; queries still target --kusto via cross-cluster cluster(). The connecting identity needs viewer rights on --kusto, and the standard databases must exist on this cluster.")
    +	cmd.Flags().StringVar(&opts.ViaRegion, "via-region", opts.ViaRegion, "Region of --via-kusto (defaults to --region)")
    +	cmd.Flags().StringVar(&opts.ServiceDatabase, "service-database", opts.ServiceDatabase, "Kusto database for service logs")
    +	cmd.Flags().StringVar(&opts.HCPDatabase, "hcp-database", opts.HCPDatabase, "Kusto database for hosted control plane logs")
    +	cmd.Flags().StringVar(&opts.MonitoringEventsDatabase, "monitoring-events-database", opts.MonitoringEventsDatabase, "Kusto database for monitoring events (alerts)")
    +	cmd.Flags().StringVar(&opts.ClusterResourceID, "cluster-resource-id", opts.ClusterResourceID, "Full ARM resource id of the HCP cluster to snapshot (mutually exclusive with --subscription/--resource-group)")
    +	cmd.Flags().StringVar(&opts.Subscription, "subscription", opts.Subscription, "Azure subscription id; with --resource-group, resolves the cluster via Cosmos (mutually exclusive with --cluster-resource-id)")
    +	cmd.Flags().StringVar(&opts.ResourceGroup, "resource-group", opts.ResourceGroup, "Azure resource group name (required with --subscription)")
    +	cmd.Flags().StringVar(&opts.StartTime, "start-time", opts.StartTime, "Query start time in RFC3339 format (required)")
    +	cmd.Flags().StringVar(&opts.EndTime, "end-time", opts.EndTime, "Query end time in RFC3339 format (required)")
    +	cmd.Flags().StringVar(&opts.OutputDir, "output-dir", opts.OutputDir, "Directory to write snapshot output")
    +	cmd.Flags().DurationVar(&opts.QueryTimeout, "query-timeout", opts.QueryTimeout, "Timeout for individual Kusto queries")
    +	cmd.Flags().IntVar(&opts.Concurrency, "concurrency", opts.Concurrency, "Maximum number of concurrent Kusto queries (0 = 4*NumCPU)")
    +
    +	for _, flag := range []string{"kusto", "region", "start-time", "end-time"} {
    +		if err := cmd.MarkFlagRequired(flag); err != nil {
    +			return fmt.Errorf("failed to mark %s as required: %w", flag, err)
    +		}
    +	}
    +	return nil
    +}
    +
    +type validatedFromClusterOptions struct {
    +	kustoEndpoint            *url.URL
    +	connectEndpoint          *url.URL
    +	serviceDatabase          string
    +	hcpDatabase              string
    +	monitoringEventsDatabase string
    +	// seedClusterResourceID is set in explicit-id mode; empty in subscription+RG mode.
    +	seedClusterResourceID string
    +	// seedSubscriptionID is always set: parsed from the id in explicit mode, or
    +	// taken from --subscription in resolve mode.
    +	seedSubscriptionID string
    +	resourceGroup      string
    +	startTime          time.Time
    +	endTime            time.Time
    +	outputDir          string
    +	queryTimeout       time.Duration
    +	concurrency        int
    +}
    +
    +func (o *RawFromClusterOptions) validate() (*validatedFromClusterOptions, error) {
    +	// Identity inputs are mutually exclusive: either an explicit cluster resource
    +	// id, or a subscription + resource group to resolve from.
    +	explicitID := o.ClusterResourceID != ""
    +	resolveMode := o.Subscription != "" || o.ResourceGroup != ""
    +	if explicitID && resolveMode {
    +		return nil, fmt.Errorf("--cluster-resource-id is mutually exclusive with --subscription/--resource-group")
    +	}
    +	if !explicitID && !resolveMode {
    +		return nil, fmt.Errorf("one of --cluster-resource-id or --subscription with --resource-group is required")
    +	}
    +
    +	var seedClusterResourceID, seedSubscriptionID, resourceGroup string
    +	if explicitID {
    +		parsed, err := azcorearm.ParseResourceID(o.ClusterResourceID)
    +		if err != nil {
    +			return nil, fmt.Errorf("invalid --cluster-resource-id %q: %w", o.ClusterResourceID, err)
    +		}
    +		if !strings.EqualFold(parsed.ResourceType.String(), hcpClusterResourceType) {
    +			return nil, fmt.Errorf("--cluster-resource-id %q is not an HCP cluster (type %q, want %q)", o.ClusterResourceID, parsed.ResourceType.String(), hcpClusterResourceType)
    +		}
    +		seedClusterResourceID = o.ClusterResourceID
    +		seedSubscriptionID = parsed.SubscriptionID
    +		resourceGroup = parsed.ResourceGroupName
    +	} else {
    +		if o.Subscription == "" {
    +			return nil, fmt.Errorf("--subscription is required with --resource-group")
    +		}
    +		if o.ResourceGroup == "" {
    +			return nil, fmt.Errorf("--resource-group is required with --subscription")
    +		}
    +		seedSubscriptionID = o.Subscription
    +		resourceGroup = o.ResourceGroup
    +	}
    +
    +	kustoEndpoint, err := kusto.KustoEndpoint(o.Kusto, o.Region)
    +	if err != nil {
    +		return nil, err
    +	}
    +
    +	// connectEndpoint is where the Kusto client actually connects. By default it
    +	// is the query target (--kusto), but --via-kusto lets callers route through a
    +	// reachable cluster while queries still target --kusto via cross-cluster
    +	// cluster() references in the query templates.
    +	connectEndpoint := kustoEndpoint
    +	if o.ViaKusto != "" {
    +		viaRegion := o.ViaRegion
    +		if viaRegion == "" {
    +			viaRegion = o.Region
    +		}
    +		connectEndpoint, err = kusto.KustoEndpoint(o.ViaKusto, viaRegion)
    +		if err != nil {
    +			return nil, err
    +		}
    +	} else if o.ViaRegion != "" {
    +		return nil, fmt.Errorf("--via-region requires --via-kusto")
    +	}
    +
    +	startTime, err := time.Parse(time.RFC3339, o.StartTime)
    +	if err != nil {
    +		return nil, fmt.Errorf("invalid --start-time %q: must be RFC3339 format: %w", o.StartTime, err)
    +	}
    +	endTime, err := time.Parse(time.RFC3339, o.EndTime)
    +	if err != nil {
    +		return nil, fmt.Errorf("invalid --end-time %q: must be RFC3339 format: %w", o.EndTime, err)
    +	}
    +	if !startTime.Before(endTime) {
    +		return nil, fmt.Errorf("--start-time must be before --end-time")
    +	}
    +
    +	return &validatedFromClusterOptions{
    +		kustoEndpoint:            kustoEndpoint,
    +		connectEndpoint:          connectEndpoint,
    +		serviceDatabase:          o.ServiceDatabase,
    +		hcpDatabase:              o.HCPDatabase,
    +		monitoringEventsDatabase: o.MonitoringEventsDatabase,
    +		seedClusterResourceID:    seedClusterResourceID,
    +		seedSubscriptionID:       seedSubscriptionID,
    +		resourceGroup:            resourceGroup,
    +		startTime:                startTime,
    +		endTime:                  endTime,
    +		outputDir:                o.OutputDir,
    +		queryTimeout:             o.QueryTimeout,
    +		concurrency:              o.Concurrency,
    +	}, nil
    +}
    +
    +type completedFromClusterOptions struct {
    +	*validatedFromClusterOptions
    +	kustoClient *azkustodata.Client
    +}
    +
    +func (o *validatedFromClusterOptions) complete() (*completedFromClusterOptions, error) {
    +	cred, err := azidentity.NewDefaultAzureCredential(&azidentity.DefaultAzureCredentialOptions{
    +		AdditionallyAllowedTenants:   []string{"*"},
    +		RequireAzureTokenCredentials: true,
    +	})
    +	if err != nil {
    +		return nil, fmt.Errorf("failed to create Azure credential: %w", err)
    +	}
    +	kcsb := azkustodata.NewConnectionStringBuilder(o.connectEndpoint.String())
    +	kcsb = kcsb.WithTokenCredential(cred)
    +	client, err := azkustodata.New(kcsb)
    +	if err != nil {
    +		return nil, fmt.Errorf("failed to create Kusto client: %w", err)
    +	}
    +	return &completedFromClusterOptions{
    +		validatedFromClusterOptions: o,
    +		kustoClient:                 client,
    +	}, nil
    +}
    +
    +func (o *completedFromClusterOptions) run(ctx context.Context) error {
    +	logger := logr.FromContextOrDiscard(ctx)
    +	defer func() {
    +		if err := o.kustoClient.Close(); err != nil {
    +			logger.Error(err, "Failed to close Kusto client")
    +		}
    +	}()
    +
    +	gatherer := snapshotpkg.NewGatherer(o.kustoClient)
    +	input := snapshotpkg.GatherInput{
    +		ClusterURI:               o.kustoEndpoint.String(),
    +		ServiceDatabase:          o.serviceDatabase,
    +		HCPDatabase:              o.hcpDatabase,
    +		MonitoringEventsDatabase: o.monitoringEventsDatabase,
    +		ResourceGroup:            o.resourceGroup,
    +		SeedClusterResourceID:    o.seedClusterResourceID,
    +		SeedSubscriptionID:       o.seedSubscriptionID,

    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.

    Copilot Copilot commented on code on Sep 25, 2026 13:28 UTC
    Code Review
    tooling/hcpctl/pkg/snapshot/gatherer.go:1
    @@ -450,6 +548,12 @@ func (g *Gatherer) runDiscovery(
     			break
     		}
     	}
    +	// Identity-seeded fallback: when no ARM request supplied the seed (from-cluster
    +	// entrypoint, or an idle cluster with no traffic), use the cluster identity
    +	// seeded onto seedData in Gather.
    +	if cosmosDiscoveryData.ClusterResourceID == "" && seedData.ClusterResourceID != "" && seedData.SubscriptionID != "" {
    +		cosmosDiscoveryData = seedData
    +	}

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

    Copilot Copilot commented on code on Sep 25, 2026 13:28 UTC
    Code Review
    tooling/hcpctl/pkg/snapshot/gatherer.go:1
    @@ -364,6 +400,68 @@ func (g *Gatherer) Gather(ctx context.Context, input GatherInput, outputDir stri
     	return manifest, report, nil
     }
     
    +// resolveSeedCluster determines the cluster resource id (and its subscription id)
    +// to seed discovery with when running identity-seeded (from-cluster entrypoint).
    +// It returns ("", "", nil) when no identity seed was provided, in which case the
    +// caller falls back to the ARM-request seeding path (from-resource).
    +//
    +// An explicit SeedClusterResourceID is used directly, with its subscription parsed
    +// from the ARM id. Otherwise, when only SeedSubscriptionID is set, the cluster is
    +// resolved from the resource group via the backend/clusterByResourceGroup query.
    +func (g *Gatherer) resolveSeedCluster(ctx context.Context, input GatherInput, seedData queryData) (clusterResourceID, subscriptionID string, err error) {
    +	if input.SeedClusterResourceID != "" {
    +		sub := input.SeedSubscriptionID
    +		if sub == "" {
    +			parsed, perr := azcorearm.ParseResourceID(input.SeedClusterResourceID)
    +			if perr != nil {
    +				return "", "", fmt.Errorf("invalid SeedClusterResourceID %q: %w", input.SeedClusterResourceID, perr)
    +			}
    +			sub = parsed.SubscriptionID
    +		}
    +		return input.SeedClusterResourceID, sub, nil
    +	}
    +	if input.SeedSubscriptionID == "" {
    +		return "", "", nil
    +	}
    +
    +	// Resolve the cluster from subscription + resource group via Cosmos snapshots.
    +	d := seedData
    +	d.SubscriptionID = input.SeedSubscriptionID
    +	rendered, err := renderQuery("queries/backend/clusterByResourceGroup/query.kql", d)
    +	if err != nil {
    +		return "", "", fmt.Errorf("failed to render clusterByResourceGroup query: %w", err)
    +	}
    +	rows, err := g.executeKQL(ctx, rendered, seedData.ServiceDatabase, 2*time.Minute)

    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.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 25, 2026 13:28 UTC
    Reviewer

    <!-- 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>

  • <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> [Identity seed overridden by request-based cluster discovery](#discussion_r4104983537) · New

  • <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> [Explicit identity seed loses precedence to mutating requests](#discussion_r4104983587) · New

  • <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> [Require both namespaces to prevent unscoped log matches](#discussion_r4104193088)

  • <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> [Subscription resolution ignores the configured query timeout](#discussion_r4104983618) · New

  • </details>

    openshift-ci[bot] openshift-ci[bot] commented on Sep 28, 2026 11:46 UTC
    Bot

    [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:

  • tooling/hcpctl/OWNERS
  • 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"]} -->

    Copilot Copilot commented on code on Sep 28, 2026 11:51 UTC
    Code Review
    tooling/hcpctl/pkg/snapshot/queries.go:1
    @@ -802,6 +834,100 @@ var allQueries = []querySpec{
     		},
     		prerequisites: "HostedControlPlaneNamespace, ResourceType is cluster",
     	},
    +	// --- Velero: backup CRs and component logs (ARO-28989) ---
    +	{
    +		component:    "velero",
    +		queryName:    "backups",
    +		templatePath: "queries/velero/backups/query.kql",

    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.

    Copilot Copilot commented on code on Sep 28, 2026 11:51 UTC
    Code Review
    tooling/hcpctl/pkg/snapshot/queries/velero/mgmtCluster/query.kql:1
    @@ -0,0 +1,6 @@
    +cluster('{{ .ClusterURI }}').database('{{ .ServiceDatabase }}').table('kubernetesResourceSnapshots')
    +| where timestamp between ({{ kqlDatetime .FullStartTime }} .. {{ kqlDatetime .FullEndTime }})
    +| where objectKind == 'Backup'
    +| where namespace == 'velero'
    +| where tostring(object.metadata.annotations['azure.microsoft.com/hcp-cluster-azure-resource-id']) =~ '{{ .ClusterResourceID }}'

    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.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 28, 2026 11:51 UTC
    Reviewer

    <!-- 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>

  • <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> [Idle clusters lack the from-cluster discovery seed](#discussion_r4121808415) · New

  • <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> [Explicit identity seed loses precedence to mutating requests](#discussion_r4104983587)

  • <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> [Identity seed overridden by request-based cluster discovery](#discussion_r4104983537)

  • <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> [Require both namespaces to prevent unscoped log matches](#discussion_r4104193088)

  • <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> [Shared Velero queries lack a fallback without Backup CRs](#discussion_r4121808480) · New

  • <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> [Subscription resolution ignores the configured query timeout](#discussion_r4104983618)

  • </details>

    Reviewers
    Assignees
    tmstff tmstff
    Labels
    risk: low confidence: 81.3% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 91.4% (HIGH) · Higher = larger blast radius
    91.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 81.3% · Lower = rushed or shallow review
    81.3%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.1% · Safe to merge
    17.1%
    Repository