Skip to content

Auto-detect organizations for org usage and Prometheus - #347

Open
sdairs wants to merge 2 commits into
codex/issue-340-local-use-errorfrom
codex/issue-337-org-autodetect
Open

Auto-detect organizations for org usage and Prometheus#347
sdairs wants to merge 2 commits into
codex/issue-340-local-use-errorfrom
codex/issue-337-org-autodetect

Conversation

@sdairs

@sdairs sdairs commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • make --org-id optional for cloud org prometheus and cloud org usage
  • resolve an omitted organization through the existing sole-organization auto-detection path
  • update the README and add parsing plus real-binary request-path coverage

Why

These two organization commands required a positional organization ID even though the rest of the cloud surface uses an optional --org-id flag and auto-detects accounts with one organization.

Impact

Users with one organization can now run org prometheus or org usage without looking up and passing its ID. Users with access to multiple organizations can select one with --org-id. The existing required usage date flags are unchanged; date defaults remain a separate follow-up.

Stack

This PR is stacked on #345 and should be reviewed as the delta from codex/issue-340-local-use-error.

Closes #337.

Validation

  • cargo fmt --all --check
  • cargo build -p clickhousectl --all-targets
  • cargo test -p clickhousectl
  • cargo clippy -p clickhousectl --all-targets -- -D warnings

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR aligns cloud org prometheus and cloud org usage with the rest of the cloud CLI surface by making organization selection optional via --org-id, falling back to the existing single-organization auto-detection path when omitted. It also updates documentation and adds both clap parsing and real-binary request-path coverage to prevent regressions.

Changes:

  • Change cloud org prometheus and cloud org usage to accept optional --org-id and auto-detect when not provided.
  • Route org resolution through the shared resolve_org_id(...) helper before calling the underlying CloudClient API methods.
  • Update README examples and add integration tests that assert the binary hits /v1/organizations then the org-specific endpoint when org-id is omitted.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
README.md Updates org command examples to omit org id by default and documents --org-id for multi-org credentials.
crates/clickhousectl/tests/cli_request_shape_test.rs Adds subprocess + wiremock coverage asserting org auto-detection request flow for prometheus/usage.
crates/clickhousectl/src/main.rs Passes optional org id (as_deref()) through to the command handlers.
crates/clickhousectl/src/cloud/commands.rs Resolves org_id via resolve_org_id for prometheus and usage before calling CloudClient methods.
crates/clickhousectl/src/cloud/cli.rs Changes clap surface for org prometheus/org usage to optional --org-id and updates parsing + write-classification tests.
Suppressed comments (1)

crates/clickhousectl/src/cloud/cli.rs:432

  • cloud org usage also drops the old positional <org-id> in favor of only --org-id, which is a breaking change for existing callers. If backward compatibility matters, consider accepting the positional org id as an alias and preferring an explicit --org-id when both are provided (with a clear error on ambiguity).
    /// Get organization usage/billing information
    Usage {
        /// Organization ID (auto-detected if not specified)
        #[arg(long)]
        org_id: Option<String>,


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/clickhousectl/src/cloud/cli.rs
@sdairs
sdairs force-pushed the codex/issue-337-org-autodetect branch from b2660ed to 07fe835 Compare August 3, 2026 18:42
@sdairs
sdairs had a problem deploying to cloud-integration August 3, 2026 18:42 — with GitHub Actions Failure
@sdairs
sdairs had a problem deploying to cloud-integration August 3, 2026 18:50 — with GitHub Actions Failure
@sdairs
sdairs temporarily deployed to cloud-integration August 3, 2026 18:57 — with GitHub Actions Inactive
@sdairs
sdairs marked this pull request as ready for review August 3, 2026 19:34
@sdairs
sdairs requested review from iskakaushik and rndD as code owners August 3, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

org usage/org prometheus require explicit ORG_ID while the rest of the cloud surface auto-detects

2 participants