Skip to content

feat(cli): add data and warehouse commands on the Metrics API - #122

Merged
filipmyllari merged 2 commits into
spotify:mainfrom
rtiman-spotify:cli-data-foundation
Dec 2, 2026
Merged

filipmyllari merged 2 commits into
spotify:mainfrom
rtiman-spotify:cli-data-foundation

Conversation

@rtiman-spotify

@rtiman-spotify rtiman-spotify commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Why

The CLI talks to Confidence mostly through the MCP server, which wraps the REST APIs. For a CLI that's an extra hop, and it means each new command needs an MCP tool built first. We're moving the CLI to call the Confidence REST APIs directly. This PR is the first step: data commands built on the Metrics API.

Builds on #144 (the core apiRequest changes) and #145 (no telemetry on --dry-run), both merged.

What

New commands, all calling the regional Metrics API with the user's token (or --profile):

  • confidence data fact-tables list | get | create
  • confidence data dimension-tables list | get | create
  • confidence data entities list | get
  • confidence data sql preview [--wait] | status | schema
  • confidence warehouse list | get (in features/warehouse/)

features/data/ is split into api.ts (the client only), resources.ts (paging and gets), operations.ts (one operation per command, plus write-once creates) and request.ts (dry-run, auth, output and errors).

  • Lists: one page by default, or --all up to 1000 pages. A repeated page token fails rather than looping. Table output shows one row per item.
  • Gets: take a qualified --name, and check that the response names the same resource.
  • Creates: the service validates the body. The write is sent exactly once. If the outcome is unknown (dropped connection, 5xx, unreadable response), the CLI says so and names the command to check before retrying.
  • --dry-run: uses dryRunGuard. It prints { request, local } and sends nothing.
  • Errors: every failure prints through one path, with tokens redacted.

The CLI never prints warehouse secrets (Databricks clientSecret, Redshift secretAccessKey), never fetches SQL sample rows, and rejects skipSqlPreview: true on both fact and dimension tables. fact-tables suggest-columns is left out: its RPC isn't exposed on the edge, and the metrics team considers it legacy.

Nested values in data table output stay on one line. This is scoped to the data commands; the shared print is unchanged.

Supersedes #123–#129.

Testing

  • pnpm qa passes.
  • Tests run through runCli, with the Metrics API mocked by shared handlers in testing (metricsReturns, metricsFails, metricsRequests). I broke each safety guard on purpose to confirm a test catches it.
  • Checked live: every list, get, sql status and sql schema command.
  • Creates and sql preview were run live on a managed-warehouse account, which rejects SQL authoring; the CLI showed that rejection correctly. A successful create and preview still need an account with its own warehouse.

🤖 Generated with Claude Code

@bespoyasov bespoyasov left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi! I looked through the code and left a few comments from the technical side but, unfortunately, I don't have access to the board you linked to this PR so I can't judge the functionality itself since I lack the context about the feature.

Would be nice to get a reference with the info, purpose, and the reasons behind the feature. Thanks!

P.S. I think we should avoid linking internal resources in public repos 🙃

Comment thread packages/cli/src/utils/telemetry.ts Resolved
Comment thread packages/core/src/api/client.ts Resolved
Comment thread packages/cli/src/commands/data.ts Resolved
@rtiman-spotify
rtiman-spotify marked this pull request as draft October 20, 2026 07:18
@filipmyllari filipmyllari changed the title refactor(cli): add shared Metrics HTTP command foundation feat(cli): add data and warehouse read commands on the Metrics API Dec 1, 2026
@filipmyllari filipmyllari changed the title feat(cli): add data and warehouse read commands on the Metrics API feat(cli): add data and warehouse commands on the Metrics API Dec 2, 2026
@filipmyllari
filipmyllari marked this pull request as ready for review December 2, 2026 12:12

@bespoyasov bespoyasov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the update! Several points from the previous round are addressed. I left comments on what's still open, plus a few new findings.

General notes:

  • The PR is quite large (39 files, ~2.5k lines) and mixes the core apiRequest rewrite, a global telemetry change, a global table-format change, a new test runner, and 5 command groups. I'd split the cross-cutting changes into separate PRs.
  • CLAUDE.md and the cli skill still don't list the new data command/feature; please, update them.
  • Per the description, successful create and sql preview haven't been verified against a live API yet.

Comment thread packages/cli/src/output/print.ts Resolved

@bespoyasov bespoyasov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Two more findings from an automated (Xirp) review pass.

Comment thread packages/cli/src/features/data/sql.ts Resolved
Comment thread packages/cli/src/features/data/sql.ts Resolved
@filipmyllari
filipmyllari changed the base branch from main to core-api-request December 2, 2026 12:41
@filipmyllari
filipmyllari deleted the branch spotify:core-api-request December 2, 2026 13:20
Adds data fact-tables, dimension-tables, entities and sql commands, plus
warehouse list and get, calling the regional Metrics API directly. Commands
build one operation each; a shared runner handles dry-run, auth, output and
errors. Tests mock the API through shared Metrics MSW handlers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@filipmyllari filipmyllari reopened this Dec 2, 2026
@filipmyllari
filipmyllari changed the base branch from core-api-request to main December 2, 2026 13:21
@filipmyllari
filipmyllari marked this pull request as draft December 2, 2026 13:22
A state the CLI doesn't know is shown as the service sends it instead of
failing, and --wait keeps polling on unset or unknown states until
--timeout, stopping only on COMPLETED, FAILED or CANCELLED.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@filipmyllari
filipmyllari marked this pull request as ready for review December 2, 2026 13:31

@bespoyasov bespoyasov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice!

As a follow-up, let's mention the data onboarding on one of the final screens in the quickstart wizard and its report file?

(Roughly in the same manner as we mention migration from other feature flag providers)

@filipmyllari
filipmyllari merged commit c00d223 into spotify:main Dec 2, 2026
6 checks passed
@github-actions github-actions Bot mentioned this pull request Dec 2, 2026
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.

3 participants