Skip to content

ROSAENG-14107: new 'hcp-dashboard' sub-command for 'osdctl rhobs'#920

Open
Nikokolas3270 wants to merge 1 commit into
openshift:masterfrom
Nikokolas3270:ROSAENG-14107
Open

ROSAENG-14107: new 'hcp-dashboard' sub-command for 'osdctl rhobs'#920
Nikokolas3270 wants to merge 1 commit into
openshift:masterfrom
Nikokolas3270:ROSAENG-14107

Conversation

@Nikokolas3270

@Nikokolas3270 Nikokolas3270 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Command takes an option argument: the dashboard to open.
The dashboard can be opened in the default browser using the --browser option.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added osdctl rhobs hcp-dashboard command to retrieve and construct HCP Grafana dashboard URLs. Supports optional dashboard name selection, RHOBS cell specification, and direct browser opening via --browser flag.
  • Documentation

    • Added complete documentation for the new hcp-dashboard command, including available dashboards and flag usage.

Command takes an option argument: the dashboard to open.
The dashboard can be opened in the default browser using the --browser option.
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jun 12, 2026
@openshift-ci-robot

openshift-ci-robot commented Jun 12, 2026

Copy link
Copy Markdown

@Nikokolas3270: This pull request references ROSAENG-14107 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Command takes an option argument: the dashboard to open.
The dashboard can be opened in the default browser using the --browser option.

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 openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Walkthrough

This PR introduces a new hcp-dashboard subcommand to osdctl rhobs that resolves Grafana dashboard URLs for HCP clusters. It adds a dashboard definition framework with parameterization, extends RhobsFetcher utilities to support cell-based lookups, refactors Grafana URL generation to use a consistent base URL, and implements the command with optional browser opening.

Changes

HCP Dashboard Feature

Layer / File(s) Summary
Dashboard Definition Framework and RhobsFetcher Structure
cmd/rhobs/requests.go
Introduces grafanaBaseUrl constant, adds exported GrafanaDashboard type with registry of dashboard definitions and per-dashboard validateAndGetParams functions, and exposes IsHostedCluster boolean field on RhobsFetcher struct to distinguish cluster context.
RhobsFetcher Utilities and Region/Shard Parsing
cmd/rhobs/requests.go
Updates CreateRhobsFetcher to populate IsHostedCluster alongside cluster tracking; adds CreateRhobsFetcherFromCell to infer OCM environment from RHOBS cell domain suffixes; adds getRhobsRegionAndShard parser to extract region/shard identifiers from cell names.
Grafana URL Generation Refactoring
cmd/rhobs/requests.go
Refactors GetGrafanaMetricsUrl and logs URL builders to use grafanaBaseUrl + "explore?" + params pattern; adds GetGrafanaDashboardUrl to construct dashboard URLs with encoded template variables; updates filterMetricsResults warning messages for cluster-mismatch scenarios.
HCP Dashboard Command Implementation
cmd/rhobs/hcpDashboard.go
Implements newCmdHcpDashboard with logic to resolve dashboard name (defaulting to a named constant), validate against the dashboard registry, determine RHOBS cells from --rhobs-cell flag or derived from cluster ID, compute the dashboard URL, and either open it in the default browser or print it; registers --rhobs-cell and --browser CLI flags.
Root Command Registration
cmd/rhobs/rootCmd.go
Registers newCmdHcpDashboard() as a subcommand in the rhobs root command.
Command Documentation
docs/README.md, docs/osdctl_rhobs.md, docs/osdctl_rhobs_hcp-dashboard.md
Adds command index entry and dedicated README section documenting dashboard options and flags; adds hcp-dashboard to the RHOBS utilities "SEE ALSO" list; creates a new documentation page describing command purpose, dashboard-name values, flag interactions, and usage examples.

🎯 3 (Moderate) | ⏱️ ~25 minutes


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 1 warning)

Check name Status Explanation Resolution
No-Sensitive-Data-In-Logs ❌ Error cmd/rhobs/requests.go logs sensitive internal info: log.Infoln("RHOBS cell:", f.RhobsCell) and also logs Loki query + time range in QueryLogs/StreamLogs. Remove or redact these Info logs (don’t log full RHOBS cell URL/internal hostnames; log only non-sensitive identifiers). Avoid logging Loki query/time range at info level unless safely sanitized.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (13 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and concisely describes the main change: adding a new 'hcp-dashboard' sub-command to 'osdctl rhobs'. It is specific, focused, and accurately reflects the primary functionality introduced in the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed PR #920 changes only Go command and docs files (no *_test.go / Ginkgo tests), so there are no Ginkgo It/Describe/Context titles to evaluate for dynamic content.
Test Structure And Quality ✅ Passed PR adds hcp-dashboard command/docs only; there are no Ginkgo test files mentioning hcp-dashboard, and cmd/rhobs has no *_test.go using Ginkgo.
Microshift Test Compatibility ✅ Passed PR #920 only changes cmd/rhobs/.go and docs/.md (no new/modified _test.go or Ginkgo e2e tests), so no MicroShift-incompatible e2e APIs were introduced.
Single Node Openshift (Sno) Test Compatibility ✅ Passed PR #920 only changes cmd/rhobs/.go and docs/.md; no new/modified Ginkgo e2e tests are present, so there are no multi-node/HA SNO assumptions to flag.
Topology-Aware Scheduling Compatibility ✅ Passed Verified cmd/rhobs*.go and repo for scheduling-constraint patterns (topologySpreadConstraints, required anti-affinity maxUnavailable:0, control-plane node selectors, arbiter/NoSchedule); none were...
Ote Binary Stdout Contract ✅ Passed PR adds osdctl rhobs hcp-dashboard command; in touched cmd/rhobs files there are no init/main/TestMain/BeforeSuite stdout writes or top-level fmt.Print/klog usage (only command execution prints). N...
Ipv6 And Disconnected Network Test Compatibility ✅ Passed Repo scan shows only 12 Ginkgo test files and none under cmd/rhobs (only mcp_test.go); this PR adds rhobs hcp-dashboard command/docs, not new Ginkgo e2e tests.
No-Weak-Crypto ✅ Passed Scanned cmd/rhobs/*.go for weak-crypto markers (MD5, SHA1, DES/3DES, RC4, Blowfish, ECB) and crypto imports; no matches found.
Container-Privileges ✅ Passed PR changes only touch cmd/rhobs/.go and docs/.md; no YAML/manifest files changed, and searched the changed files for privileged/hostPID/hostNetwork/hostIPC/SYS_ADMIN/allowPrivilegeEscalation—no m...
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci openshift-ci Bot requested review from RaphaelBut and joshbranham June 12, 2026 14:07
@openshift-ci

openshift-ci Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Nikokolas3270

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 12, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
cmd/rhobs/requests.go (1)

507-528: 💤 Low value

Consider validating the RHOBS cell URL format.

The function parses the hostname suffix to infer the OCM environment but doesn't validate that rhobsCell is a well-formed URL (e.g., starts with https://). If a malformed URL is passed, getRhobsCellName() (line 531) may fail with a confusing error downstream.

Also note that fetchers created via this path have IsHostedCluster and isManagementCluster set to false, which will cause cluster-type-specific dashboards (e.g., "hosted-cluster", "management-cluster") to reject them with validation errors. This may be intentional, but consider documenting this constraint.

🛡️ Optional: Add URL scheme validation
 func CreateRhobsFetcherFromCell(rhobsCell string) (*RhobsFetcher, error) {
+	if !strings.HasPrefix(rhobsCell, "https://") {
+		return nil, fmt.Errorf("RHOBS cell URL must start with 'https://': %s", rhobsCell)
+	}
+
 	envName := ""
 
 	if strings.HasSuffix(rhobsCell, ".rhobs.api.openshift.com") {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/rhobs/requests.go` around lines 507 - 528, CreateRhobsFetcherFromCell
currently infers ocmEnvName from the hostname suffix but does not validate
rhobsCell as a well-formed URL; update CreateRhobsFetcherFromCell to parse
rhobsCell using net/url.Parse, ensure it has a non-empty Host and an allowed
scheme (preferably "https"), and return a clear error like "invalid RHOBS cell
URL: must be a valid URL with https scheme" when validation fails; also
explicitly set the fetcher cluster-type flags (IsHostedCluster and
isManagementCluster) on the returned RhobsFetcher to false (and add a short
inline comment documenting that fetchers created from a RHOBS cell URL are
neither hosted nor management clusters) so downstream validation errors are less
confusing.
cmd/rhobs/hcpDashboard.go (1)

44-44: ⚡ Quick win

Consider trimming whitespace after splitting --rhobs-cell values.

strings.Split(rhobsCell, ",") does not trim whitespace. If a user provides --rhobs-cell="url1, url2" (note the space after the comma), the second URL will have a leading space, potentially causing URL parsing or fetcher creation to fail with a confusing error.

✂️ Proposed fix to trim whitespace
-rhobsCells = strings.Split(rhobsCell, ",")
+parts := strings.Split(rhobsCell, ",")
+rhobsCells = make([]string, len(parts))
+for i, part := range parts {
+    rhobsCells[i] = strings.TrimSpace(part)
+}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/rhobs/hcpDashboard.go` at line 44, rhobsCells produced by
strings.Split(rhobsCell, ",") can contain leading/trailing whitespace (e.g.
"url1, url2"); change the post-split handling so each element is
strings.TrimSpace'd and optionally filter out empty entries before use (i.e.,
after splitting rhobsCell, iterate over the resulting slice, call
strings.TrimSpace on each element, and append non-empty trimmed strings back
into rhobsCells) to avoid malformed URLs when creating fetchers or parsing.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/rhobs/hcpDashboard.go`:
- Line 40: Avoid dereferencing cmd.Parent(): replace the parent-flag check with
a direct check of the shared option variable by using commonOptions.clusterId
instead of cmd.Parent().Flags().Changed("cluster-id"); update the validation in
the function containing the conditional (the code using cmd.Parent()) to return
the conflict error when commonOptions.clusterId != "" so you remove the nil
dereference risk and decouple the child command from the parent's flag
internals.
- Around line 69-77: The code redundantly calls CreateRhobsFetcher twice causing
duplicate OCM/cluster/cell resolution and repeated
osdctlConfig.EnsureConfigFile() work; refactor by extracting the shared
initialization into a new helper (e.g., CreateRhobsFetcherContext or
InitRhobsFetchDependencies) that performs OCM connection, cluster/hypershift
resolution, RHOBS cell lookup, and ensures the osdctl config once, and then
change CreateRhobsFetcher (or add NewRhobsFetcherFromContext) to accept that
shared context and only create the specific RhobsFetcher for
RhobsFetchForMetrics and RhobsFetchForLogs; update the call site in
hcpDashboard.go to call the init helper once, then create both metrics and logs
fetchers from the returned context.

In `@cmd/rhobs/requests.go`:
- Around line 540-548: In getRhobsRegionAndShard, handle the two failure cases
separately: first check if err from getRhobsCellName() is non-nil and return
that error; then if lastDashIdx == -1 return a clear error that the returned
rhobsCellName contains no dash (include the actual rhobsCellName in the
message). Reference functions/vars: getRhobsRegionAndShard, getRhobsCellName,
rhobsCellName, lastDashIdx.

---

Nitpick comments:
In `@cmd/rhobs/hcpDashboard.go`:
- Line 44: rhobsCells produced by strings.Split(rhobsCell, ",") can contain
leading/trailing whitespace (e.g. "url1, url2"); change the post-split handling
so each element is strings.TrimSpace'd and optionally filter out empty entries
before use (i.e., after splitting rhobsCell, iterate over the resulting slice,
call strings.TrimSpace on each element, and append non-empty trimmed strings
back into rhobsCells) to avoid malformed URLs when creating fetchers or parsing.

In `@cmd/rhobs/requests.go`:
- Around line 507-528: CreateRhobsFetcherFromCell currently infers ocmEnvName
from the hostname suffix but does not validate rhobsCell as a well-formed URL;
update CreateRhobsFetcherFromCell to parse rhobsCell using net/url.Parse, ensure
it has a non-empty Host and an allowed scheme (preferably "https"), and return a
clear error like "invalid RHOBS cell URL: must be a valid URL with https scheme"
when validation fails; also explicitly set the fetcher cluster-type flags
(IsHostedCluster and isManagementCluster) on the returned RhobsFetcher to false
(and add a short inline comment documenting that fetchers created from a RHOBS
cell URL are neither hosted nor management clusters) so downstream validation
errors are less confusing.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: d2336086-f12b-4620-bdae-4494d6d492bc

📥 Commits

Reviewing files that changed from the base of the PR and between 2cc345e and f022b92.

📒 Files selected for processing (6)
  • cmd/rhobs/hcpDashboard.go
  • cmd/rhobs/requests.go
  • cmd/rhobs/rootCmd.go
  • docs/README.md
  • docs/osdctl_rhobs.md
  • docs/osdctl_rhobs_hcp-dashboard.md

Comment thread cmd/rhobs/hcpDashboard.go
Comment thread cmd/rhobs/hcpDashboard.go
Comment on lines +69 to +77
metricsRhobsFetcher, err = CreateRhobsFetcher(commonOptions.clusterId, RhobsFetchForMetrics, commonOptions.hiveOcmUrl)
if err != nil {
return err
}
logsRhobsFetcher, err = CreateRhobsFetcher(commonOptions.clusterId, RhobsFetchForLogs, commonOptions.hiveOcmUrl)
if err != nil {
return err
}
}

@coderabbitai coderabbitai Bot Jun 12, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check if CreateRhobsFetcher performs network calls or expensive operations

# Find the implementation
ast-grep --pattern $'func CreateRhobsFetcher($$$) $$$'

# Look for HTTP calls, OCM client usage, or heavy operations
rg -n -C5 'func CreateRhobsFetcher|http\.|ocm\.|Get.*Cluster' --type=go -g '**/rhobs/**'

Repository: openshift/osdctl

Length of output: 11631


Avoid redundant OCM/cluster/config initialization when creating metrics vs logs RHOBS fetchers

cmd/rhobs/hcpDashboard.go creates two RhobsFetchers back-to-back (metrics + logs) for the same commonOptions.clusterId, and each call to CreateRhobsFetcher performs expensive setup: it creates a new OCM connection, resolves the same cluster (and hypershift management cluster when applicable), resolves the RHOBS cell, and calls osdctlConfig.EnsureConfigFile() on every invocation. This duplicates network/IO work and config reload—refactor to share/memoize the common parts between the two fetchers.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/rhobs/hcpDashboard.go` around lines 69 - 77, The code redundantly calls
CreateRhobsFetcher twice causing duplicate OCM/cluster/cell resolution and
repeated osdctlConfig.EnsureConfigFile() work; refactor by extracting the shared
initialization into a new helper (e.g., CreateRhobsFetcherContext or
InitRhobsFetchDependencies) that performs OCM connection, cluster/hypershift
resolution, RHOBS cell lookup, and ensures the osdctl config once, and then
change CreateRhobsFetcher (or add NewRhobsFetcherFromContext) to accept that
shared context and only create the specific RhobsFetcher for
RhobsFetchForMetrics and RhobsFetchForLogs; update the call site in
hcpDashboard.go to call the init helper once, then create both metrics and logs
fetchers from the returned context.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, maybe there should be a CreateRhobsFetchers method to mutualise those accesses.
Original code was created with the idea that a cluster has only one rhobs cell... But in reality the one used for logs can differ from the one for metrics

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Look at the CreateRhobsFetcher implementation to understand shared vs diverging parts
ast-grep --pattern $'func CreateRhobsFetcher($$$) ($$$) {
  $$$
}'

# Also check RhobsFetcher struct definition
ast-grep --pattern $'type RhobsFetcher struct {
  $$$
}'

# Check what RhobsFetchForMetrics / RhobsFetchForLogs diverge on
rg -n 'RhobsFetchFor|fetchType|FetchType|metricsCell|logsCell|IsHostedCluster' --type=go

Length of output: 6218



@Nikokolas3270, that context is helpful — the design makes sense since getRhobsCell diverges per usage (metrics vs logs) but everything upstream of it (OCM connection, cluster resolution, MC lookup, config reload) is purely shared work.

A CreateRhobsFetchers function would fit naturally: do all the common init once, call getRhobsCell twice (once for each usage), then return both fetchers. Rough sketch:

// CreateRhobsFetchers creates both a metrics and a logs RhobsFetcher for the
// given cluster, sharing the OCM connection and cluster-resolution work.
func CreateRhobsFetchers(clusterKey string, hiveOcmUrl string) (metricsFetcher, logsFetcher *RhobsFetcher, err error) {
    ocmConn, err := ocmutils.CreateConnection()
    if err != nil {
        return nil, nil, err
    }
    defer ocmConn.Close()

    cluster, err := ocmutils.GetCluster(ocmConn, clusterKey)
    if err != nil {
        return nil, nil, err
    }

    var monitoredClusterId string
    isHcp := cluster.Hypershift().Enabled()
    isMC := false

    if isHcp {
        managementCluster, err := ocmutils.GetManagementCluster(cluster.ID())
        if err != nil {
            return nil, nil, fmt.Errorf("failed to retrieve management cluster for cluster '%s': %v", cluster.ID(), err)
        }
        monitoredClusterId = managementCluster.ID()
    } else {
        monitoredClusterId = cluster.ID()
        isMC, err = ocmutils.IsManagementCluster(cluster.ID())
        if err != nil {
            return nil, nil, fmt.Errorf("failed to determine if cluster '%s' is a management cluster: %v", cluster.ID(), err)
        }
    }

    // Cells CAN differ between metrics and logs — resolve both.
    metricsCell, err := getRhobsCell(monitoredClusterId, ocmConn, RhobsFetchForMetrics, hiveOcmUrl)
    if err != nil {
        return nil, nil, err
    }
    logsCell, err := getRhobsCell(monitoredClusterId, ocmConn, RhobsFetchForLogs, hiveOcmUrl)
    if err != nil {
        return nil, nil, err
    }

    // Reload config once after backplane may have mutated it.
    if err = osdctlConfig.EnsureConfigFile(); err != nil {
        return nil, nil, fmt.Errorf("failed to reload osdctl config: %v", err)
    }

    base := RhobsFetcher{
        clusterId:           cluster.ID(),
        clusterExternalId:   cluster.ExternalID(),
        clusterName:         cluster.Name(),
        IsHostedCluster:     isHcp,
        isManagementCluster: isMC,
        ocmEnvName:          ocmutils.GetCurrentOCMEnv(ocmConn),
    }
    mf := base
    mf.RhobsCell = metricsCell
    lf := base
    lf.RhobsCell = logsCell
    return &mf, &lf, nil
}

hcpDashboard.go lines 69-77 and cellCmd.go lines 20-25 both exhibit the same pattern, so both call sites would benefit from switching to this helper.

Would you like me to open a follow-up GitHub issue to track this refactor, or plan the code changes directly?


✏️ Learnings added
Learnt from: Nikokolas3270
Repo: openshift/osdctl PR: 920
File: cmd/rhobs/hcpDashboard.go:69-77
Timestamp: 2026-06-12T15:13:45.487Z
Learning: In openshift/osdctl cmd/rhobs, the metrics RHOBS cell and logs RHOBS cell for a given cluster can be different. Any helper that creates both a metrics and a logs RhobsFetcher (e.g., a future CreateRhobsFetchers) must call getRhobsCell separately for RhobsFetchForMetrics and RhobsFetchForLogs, even though all other initialization (OCM connection, cluster resolution, management cluster lookup, EnsureConfigFile) is shared and should be done only once.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: Nikokolas3270
Repo: openshift/osdctl PR: 920
File: cmd/rhobs/hcpDashboard.go:40-40
Timestamp: 2026-06-12T15:09:42.380Z
Learning: When implementing osdctl Cobra command logic in cmd/**/*.go, do not infer whether the user explicitly set a CLI flag by checking the derived/resolved option value (e.g., commonOptions.clusterId), especially if a parent command pre-invoke hook auto-populates that value even when the flag is omitted. Instead, detect explicit flag usage via Cobra’s flag API, e.g. use `cmd.Parent().Flags().Changed("cluster-id")` (or `cmd.Flags().Changed(...)` as appropriate for the flag being checked) to determine whether `--cluster-id` was explicitly provided by the user.

Comment thread cmd/rhobs/requests.go
Comment on lines +540 to +548
func (f *RhobsFetcher) getRhobsRegionAndShard() (string, string, error) {
rhobsCellName, err := f.getRhobsCellName()
lastDashIdx := strings.LastIndex(rhobsCellName, "-")
if err != nil || lastDashIdx == -1 {
return "", "", fmt.Errorf("failed to compute RHOBS cell region & shard: %v", err)
}

return rhobsCellName[:lastDashIdx], rhobsCellName[lastDashIdx+1:], nil
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Improve error message when cell name has no dash.

When lastDashIdx == -1 (cell name contains no dash), err may be nil, resulting in a confusing error message: "failed to compute RHOBS cell region & shard: <nil>".

🐛 Proposed fix
 func (f *RhobsFetcher) getRhobsRegionAndShard() (string, string, error) {
 	rhobsCellName, err := f.getRhobsCellName()
+	if err != nil {
+		return "", "", fmt.Errorf("failed to compute RHOBS cell region & shard: %v", err)
+	}
 	lastDashIdx := strings.LastIndex(rhobsCellName, "-")
-	if err != nil || lastDashIdx == -1 {
-		return "", "", fmt.Errorf("failed to compute RHOBS cell region & shard: %v", err)
+	if lastDashIdx == -1 {
+		return "", "", fmt.Errorf("failed to compute RHOBS cell region & shard: cell name '%s' does not contain a dash", rhobsCellName)
 	}
 
 	return rhobsCellName[:lastDashIdx], rhobsCellName[lastDashIdx+1:], nil
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (f *RhobsFetcher) getRhobsRegionAndShard() (string, string, error) {
rhobsCellName, err := f.getRhobsCellName()
lastDashIdx := strings.LastIndex(rhobsCellName, "-")
if err != nil || lastDashIdx == -1 {
return "", "", fmt.Errorf("failed to compute RHOBS cell region & shard: %v", err)
}
return rhobsCellName[:lastDashIdx], rhobsCellName[lastDashIdx+1:], nil
}
func (f *RhobsFetcher) getRhobsRegionAndShard() (string, string, error) {
rhobsCellName, err := f.getRhobsCellName()
if err != nil {
return "", "", fmt.Errorf("failed to compute RHOBS cell region & shard: %v", err)
}
lastDashIdx := strings.LastIndex(rhobsCellName, "-")
if lastDashIdx == -1 {
return "", "", fmt.Errorf("failed to compute RHOBS cell region & shard: cell name '%s' does not contain a dash", rhobsCellName)
}
return rhobsCellName[:lastDashIdx], rhobsCellName[lastDashIdx+1:], nil
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/rhobs/requests.go` around lines 540 - 548, In getRhobsRegionAndShard,
handle the two failure cases separately: first check if err from
getRhobsCellName() is non-nil and return that error; then if lastDashIdx == -1
return a clear error that the returned rhobsCellName contains no dash (include
the actual rhobsCellName in the message). Reference functions/vars:
getRhobsRegionAndShard, getRhobsCellName, rhobsCellName, lastDashIdx.

@openshift-ci

openshift-ci Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

@Nikokolas3270: 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/verify-docs f022b92 link true /test verify-docs

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.

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants