Skip to content

feat(dashboards): upsert dashboards by the dash0.com/origin label - #401

Open
nicolastakashi wants to merge 4 commits into
mainfrom
380-dashboards-upsert-by-origin
Open

nicolastakashi wants to merge 4 commits into
mainfrom
380-dashboards-upsert-by-origin

Conversation

@nicolastakashi

Copy link
Copy Markdown
Contributor

Fixes #380

Kubernetes drops unknown metadata fields, so a Dashboard kept as a custom resource lost dash0Extensions.id, and every apply created a new dashboard.
The CLI now reads the key from dash0.com/origin, then dash0Extensions.id, then dash0.com/id, the same way in apply, diff, create, update -f, and apply --since.

  • A file with only dash0.com/origin updates the same dashboard on every apply.
  • A file with only dash0Extensions.id works as before.
  • A file with only dash0.com/id, the server UUID from dashboards get -o yaml, updates that dashboard instead of creating a second one.
  • A file whose origin and dash0Extensions.id differ fails validation before any write.
  • apply --since does not report a deletion when a file moves the same value from dash0Extensions.id to dash0.com/origin.

The client's GetID reads dash0.com/id before dash0Extensions.id, so asset.DashboardKeys sets the order the issue asks for, and every reader goes through it.

This needs dash0-api-client-go v1.34.0, which also changes the profiles package, so the first commit migrates to ResolvedConfiguration.
v1.34.0 no longer refreshes the OAuth token during profile lookup, so the client now asks the token provider once when it is built, which keeps the dash0 login hint for a rejected refresh token.

For #376: dashboards preview should derive each preview id from asset.DashboardKey, and EphemeralDashboard should go through the same key and asset.ValidateDashboard.

Follow-up: login and logout still write the OAuth token to Configuration.AuthToken. v1.34.0 keeps it in sync with OAuthState.AccessToken, and the next client-go release won't.

Tests: make lint && make test (unit, integration, e2e) pass. I did not run the roundtrip tests. Each new test fails with the feature files reverted. TestUpdateDashboard_WithOriginFromFile is the exception, because the v1.34.0 bump alone already routes update -f by origin.

nicolastakashi and others added 3 commits November 16, 2026 15:28
v1.34.0 splits profiles.Configuration into the stored schema and a
ResolvedConfiguration that is read through methods. Only a Store builds
one, so tests now get theirs from testutil.ResolvedConfiguration.

The profile lookup no longer refreshes the OAuth token. The client now
asks the token provider once when it is built, so a rejected refresh
token still fails with the "run dash0 login" hint.
apply, diff, create, update -f, and --since read a dashboard's key from
dash0.com/origin, then metadata.dash0Extensions.id, then dash0.com/id.
A dashboard kept as a Kubernetes custom resource loses dash0Extensions,
so it used to become a new dashboard on every apply. An exported file
carries the server UUID in dash0.com/id and now updates the dashboard it
came from. A file whose origin and dash0Extensions.id differ fails
validation before anything is written.

Fixes #380
@nicolastakashi
nicolastakashi marked this pull request as ready for review November 16, 2026 16:23
@nicolastakashi
nicolastakashi requested a review from a team as a code owner November 16, 2026 16:23
@dash0-dev

dash0-dev Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Darkplane AutoMerge

Darkplane AutoMerge did not approve this pull request. Score 55.7 of 100, threshold 75. Blast radius 33, Evidence quality 62 (floor 50), Docs, skill and changelog sync 35 (floor 50), Asset identity and round-trip 85 (floor 50), CLI contract and agent mode 38 (floor 50).

2 criteria scored below their required floors, which reject the run whatever the total.


Evidence

Low Blast radius scored 33.

The change alters dashboard upsert keys in internal/asset/dashboard.go and identifier.go, which affects apply, dashboards create and dashboards update, including apply --since. It also bumps dash0-api-client-go to v1.34.0 (no replace directive) and ports internal/client/client.go to the new ResolvedConfiguration API. That port adds an eager OAuth token fetch in authTokenOption for every command that uses an OAuth profile. Rollback needs a new release, and dashboards written or overwritten under the new key rules in a customer organization may not be restorable.

Fair Evidence quality scored 62.

The strongest test is TestApply_Dashboard_OriginOnly_UpdatesTheSameDashboardOnEveryApply in internal/apply/integration_test.go. It applies twice and asserts both writes are PUTs to the origin path and none is a POST. Sibling tests cover the server-ID-only label, an origin versus dash0Extensions.id mismatch that fails before any request, and the key precedence in identifier_test.go. Gaps: the mock returns 404 on both applies, so a "no changes" second apply and a soft-deleted or restored origin dashboard are untested. I saw no tests for diff or create, and no roundtrip script that uses an origin-keyed dashboard. The author also says TestUpdateDashboard_WithOriginFromFile passes without the feature code.

Low Docs, skill and changelog sync scored 35, below its required floor of 50.

The skill's internal/skill/content/SKILL.md was not updated and now contradicts the change. Its identifier table still lists Dashboard as metadata.dash0Extensions.id, and it still says "never upsert a dashboard by origin". The rest is in sync: docs/commands.md (identifier table, origin prose, example), CLAUDE.md, the dashboards.md skill reference, and .chloggen/380-dashboards-upsert-by-origin.yaml with issue 380 and an enhancement type.

Good Asset identity and round-trip scored 85.

For dashboards, internal/asset/dashboard.go now uses one key, in the order dash0.com/origin, then metadata.dash0Extensions.id, then dash0.com/id. ImportDashboard, PlanDashboard, ExtractIdentifier and dashboards update share it, so the apply upsert (PUT), dry-run plan and apply --since delete use the same identifier. The key is read before the strip clears the dash0.com/id label, a file whose origin and extensions id differ is rejected before any write, and the preflight GET ignores only not-found errors. I couldn't confirm that the API accepts an origin in the dashboard GET, PUT or DELETE path, or that the strip leaves origin handling intact; the roundtrip and idempotency checks passed.

Low CLI contract and agent mode scored 38, below its required floor of 50.

There are no flag, output-column or exit-code changes. But dashboards create, dashboards update -f and apply now fail validation when a dashboard's dash0.com/origin and metadata.dash0Extensions.id differ. A file with only dash0.com/id now updates the existing dashboard instead of creating a new one. Both are behavior changes for existing callers, and .chloggen/380-dashboards-upsert-by-origin.yaml uses change_type: enhancement, not breaking. Client building now also fetches the OAuth token up front, which changes when an auth failure surfaces.

An AI evaluator produced these scores from the diff, the repository history, and the pull request text. The pull request text is author-controlled, so treat the scores as signals rather than proof. Reviewed for commit 32a4d8b.

Was this decision right? Give feedback

When the dash0.com/origin of a dashboard is not found and the file also
carries the dash0.com/id label, apply updates the dashboard at that id,
which then gets the origin. apply --since treats the id as the same
dashboard, so it does not delete it.

The validation error for a mismatched origin and dash0Extensions.id now
tells the user to move the id to the dash0.com/id label.

Also sync the agent skill with the new dashboard keys, list the behavior
changes in the changelog entry, and add tests for create, for a second
apply with no changes, and for restoring a deleted dashboard by origin.

Refs #380
@nicolastakashi

Copy link
Copy Markdown
Contributor Author

Update after the Darkplane run on 32a4d8b. fdc1fde addresses most of it:

  • SKILL.md now lists the new dashboard keys. The pushed version still said "never upsert a dashboard by origin".
  • The changelog subtext now lists the 3 behavior changes. A mismatched dash0.com/origin and dash0Extensions.id fails before any write, but the API already returned a 400 for it, so no file that worked before fails now. A file with only dash0.com/id updates that dashboard. The OAuth token is resolved when a command starts, which keeps the dash0 login hint the same as with client-go v1.33. I kept enhancement for these reasons.
  • New tests: a second apply that finds the dashboard by origin and reports no changes, restoring a deleted dashboard by origin, dashboards create with a mismatched origin, and an exported dashboard that gains an origin (updated at its dash0.com/id, and not deleted by apply --since). The origin-key tests fail when the origin key is turned off.
  • diff routing by origin is covered in internal/diff/upsertkey_characterization_test.go.
  • TestUpdateDashboard_WithOriginFromFile passes on the client-go bump alone, because v1.34 reads the origin. It is there to pin that behavior.

Still needed before this leaves draft:

  • A roundtrip run with an origin-keyed dashboard against a real environment. I have not run the roundtrip tests for this PR, and no roundtrip script uses an origin-only dashboard yet.
  • feat(dashboards): preview dashboards as ephemeral dashboards #376 has to derive each preview id from asset.DashboardKey, so previews use the same origin, then dash0Extensions.id, then dash0.com/id order as apply.
  • Follow-up: login and logout still write the OAuth token to AuthToken. They need to move to OAuthState.AccessToken before the next client-go release drops the synced copy.

This branch has not been deployed

No deployments
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.

Upsert dashboards by the dash0.com/origin label

1 participant