Skip to content

fix: instance health reflects in db state - #461

Merged
GabriellePoncey merged 2 commits into
mainfrom
fix/PLAT-333/db-status-instance-aware
Sep 9, 2026
Merged

fix: instance health reflects in db state#461
GabriellePoncey merged 2 commits into
mainfrom
fix/PLAT-333/db-status-instance-aware

Conversation

@GabriellePoncey

@GabriellePoncey GabriellePoncey commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Updated storedToDtabase to inspect the database's instance and update the database to degraded if instance states indicate this is appropriate. Delete database modified to check "from" state via the stored state rather than etcd to prevent mismatch.

Changes

  • storedToDatabase downgrades an available database to degraded if any of its instances is degraded, failed, unknown, or stopped.
  • database_test.go covers and tests this logic
  • DeleteDatabase now uses GetStoredDatabaseState (raw stored value) instead of db.State (computed) for its state-transition guard

PLAT-333

Updated storedToDtabase to inspect the database's instance and update the database to degraded if instance states indicate this is appropriate. Delete database modified to check "from" state via the stored state rather than etcd to prevent mismatch.

PLAT-333
@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 8c3f9538-334c-4a20-bf22-392ec6469e2c

📥 Commits

Reviewing files that changed from the base of the PR and between bb1254a and ef92a64.

📒 Files selected for processing (3)
  • server/internal/api/apiv1/post_init_handlers.go
  • server/internal/database/database.go
  • server/internal/database/service.go

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Changes

Database lifecycle

Layer / File(s) Summary
Derive effective database state
server/internal/database/database.go, server/internal/database/service.go, server/internal/database/database_test.go
storedToDatabase marks an available database as degraded when an instance is degraded, failed, unknown, or stopped. The conversion preserves the persisted state in RawState. Database creation initializes RawState to DatabaseStateCreating. Tests cover these state combinations.
Use raw state during deletion
server/internal/api/apiv1/post_init_handlers.go
DeleteDatabase uses the loaded database’s RawState as the transition guard before moving the database to deleting.

Priority: ⬇️ Low — Defer this database-state correction because its scope is limited to deriving instance-health status and guarding deletion transitions.

Merge Risk: ⚪ Minimal · up to ef92a

Available databases now report degraded status when an instance is unhealthy, while deletion continues to guard transitions using persisted state. The change includes coverage for the supported state combinations and is ready to merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: database state now reflects instance health. It follows the repository's Conventional Commits format.
Description check ✅ Passed The description explains the database state changes, DeleteDatabase behavior, and added test coverage. It is mostly complete, but it does not include the template's explicit Testing, Checklist, or Not…
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/PLAT-333/db-status-instance-aware

A rabbit checks each instance state
Raw state keeps the record straight
Available databases may degrade
Creating ones keep their own state
Deletion follows the stored trail
Tests check each hopping detail

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

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 duplication

Metric Results
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.


prevState := db.State
// Use the raw stored state as the guard for this transition.
prevState, err := s.dbSvc.GetStoredDatabaseState(ctx, db.DatabaseID)

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.

Looks good.
Minor: DeleteDatabase now calls GetStoredDatabaseState (post_init_handlers.go:479), which re-reads the same StoredDatabase record already fetched by GetDatabase just above. We could avoid the extra database round trip by carrying the raw stored state on Database (for example, a RawState field populated in storedToDatabase) and using db.RawState here instead. Not blocking.

Add a RawState field to Database, read that state in DeleteDatabase efficiently.

@tsivaprasad tsivaprasad 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.

Looks good.
Thanks

@GabriellePoncey
GabriellePoncey merged commit d0e3189 into main Sep 9, 2026
5 checks passed
@GabriellePoncey
GabriellePoncey deleted the fix/PLAT-333/db-status-instance-aware branch September 9, 2026 14:07
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.

2 participants