Skip to content

Add doctl insights dashboard commands - #2102

Merged
RohithSangati merged 5 commits into
digitalocean:mainfrom
adityasingh-beep:adityasingh/COBS-1892-Implement-doctl-Insights-dashboard-commands
Nov 6, 2026
Merged

RohithSangati merged 5 commits into
digitalocean:mainfrom
adityasingh-beep:adityasingh/COBS-1892-Implement-doctl-Insights-dashboard-commands

Conversation

@adityasingh-beep

@adityasingh-beep adityasingh-beep commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds doctl insights dashboard with list, get, create, update, delete, and schema, backed by the Insights dashboards API added in godo #1201 (OpenAPI: digitalocean/openapi#1298).

Related: COBS-1892 (parent COBS-1866)

Design

A dashboard is defined by a Perses JSON document that the API owns; doctl does not model it.

  • schema prints the JSON Schema the document must satisfy, passed through from the API verbatim.
  • create / update read the document from --spec-file (JSON or YAML, or - for stdin) and send it as written, so a file that validates locally reaches the server byte-for-byte. Anything that is not a single JSON object is rejected before the request is made.
  • JSON output embeds spec as an object rather than the string-encoded form the API transports, so get --output json | jq .dashboard.spec round-trips back into --spec-file unchanged.
  • name and description are server-derived from spec.display; update is a full replace.
  • list supports --page, --per-page (max 200), --sort (name | created_at | updated_at, omitted = newest first) and --sort-direction (asc | desc, requires --sort, matching server behaviour).
  • Page/per-page validation is factored into insightsPageOptions and reused by insights resource list.
  • API errors are passed through unchanged (no doctl-side parsing).

Dependency

Requires godo v1.236.0 (contains #1201), which main already pins. This PR adds no dependency or vendor changes.

Testing

  • make gofmt_check, go vet, make check_focused clean.
  • make test_unit: all insights tests pass (102); the only failure is the pre-existing TestRegistryLogout, which requires a native keychain (macOS local-run artefact, passes in CI on Linux).
  • do/mocks/InsightsService.go regenerated with mockgen v0.6.0 (byte-identical to generator output).
  • Validated end to end against stage2: create → get → list → update → delete, and 409 on duplicate spec.display.name.

adityasingh-beep and others added 3 commits November 5, 2026 11:04
Add the six dashboard methods from godo v1.236.0 to do.InsightsService
as context.TODO() pass-throughs, with the mock regenerated by
mockgen v0.6.0.

Related: COBS-1892
Add doctl insights dashboard (list, get, create, update, delete,
schema) backed by the Insights dashboards API.

A dashboard is defined by a Perses JSON document that the API owns;
doctl does not model it. `schema` prints the JSON Schema the document
must satisfy. `create` and `update` read the document from --spec-file
(JSON or YAML, or - for stdin) and send it as written, so a file that
validates locally reaches the server byte-for-byte. JSON output embeds
`spec` as an object, so `get --output json | jq .dashboard.spec` round-
trips back into --spec-file unchanged.

Page/per-page validation is factored into insightsPageOptions and
reused by the resource list command.

API errors are passed through unchanged.

Related: COBS-1892
Co-authored-by: Cursor <cursoragent@cursor.com>
Cover flag validation, spec file reading (JSON, YAML, stdin, rejection
of non-object documents), request construction against the mocked
InsightsService, the shared page option helper, and text and JSON
display of dashboards and pagination.

Related: COBS-1892
Co-authored-by: Cursor <cursoragent@cursor.com>
@adityasingh-beep
adityasingh-beep force-pushed the adityasingh/COBS-1892-Implement-doctl-Insights-dashboard-commands branch from 0ea75df to 4af6b6a Compare November 5, 2026 05:36
@adityasingh-beep
adityasingh-beep marked this pull request as ready for review November 5, 2026 05:36

@dmamidala-glitch dmamidala-glitch 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.

approved.

Comment thread commands/insights_request.go Outdated
if len(spec) == 0 {
return nil, errInsightsDashboardSpecNotObject
}
if spec[0] != '{' {

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.

Valid flow-style YAML can start with {, for example {kind: Dashboard}. This skips YAML conversion and is incorrectly parsed as JSON. Could we preserve the input when json.Valid(spec) succeeds; otherwise convert it with yaml.YAMLToJSON? Please add a regression test.

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.

Good catch, thanks! You're right, {kind: Dashboard} was getting treated as JSON and blowing up. Fixed in 9f14c73 — it now checks json.Valid like you suggested, and I added a test for the flow-style case.

One small extra: while poking at this I noticed YAMLToJSON quietly ignores anything after the first document, so something like cat a.json b.json | ... --spec-file - would've silently sent just a.json. Added a quick single-document check and a couple of tests so that can't slip through.

adityasingh-beep and others added 2 commits November 5, 2026 11:32
readInsightsDashboardSpec chose the parser by the first byte, so
flow-style YAML such as {kind: Dashboard} was sent to the JSON decoder
and rejected. Decide on json.Valid instead: valid JSON objects pass
through byte-for-byte, everything else is converted from YAML.

yaml.YAMLToJSON only converts the first document and silently drops the
rest, so decode with the underlying yaml.v2 parser first and require
exactly one document. This keeps rejecting concatenated JSON objects and
now also rejects multi-document YAML.

Addresses review feedback on digitalocean#2102.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

@dmamidala-glitch dmamidala-glitch 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.

LGTM

@RohithSangati
RohithSangati merged commit 594c5e8 into digitalocean:main Nov 6, 2026
6 checks passed
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

⌂ 换网址