Skip to content

fix: allow longer instance ids in api#395

Merged
jason-lynch merged 1 commit into
mainfrom
fix/instance-id-endpoints
Jun 3, 2026
Merged

fix: allow longer instance ids in api#395
jason-lynch merged 1 commit into
mainfrom
fix/instance-id-endpoints

Conversation

@jason-lynch

@jason-lynch jason-lynch commented Jun 2, 2026

Copy link
Copy Markdown
Member

Summary

Fixes an issue where valid instance IDs are rejected by our API validation. Instance IDs are an aggregate that includes database ID, node name, and a hash of the host ID. When the database ID is the maximum allowable length for an Identifier, its instance IDs will exceed the maximum length for an Identifier. This commit switches to using strings with longer limits to avoid this issue.

Testing

This PR fixes this test case:

# create a database with a max length id
cp1-req create-database <<EOF | cp-follow-task             
{
  "id": "a37e2ed1-bb81-49cb-872b-2bdb7fff3bbc",
  "spec": {
    "database_name": "storefront",
    "database_users": [
      {
        "username": "admin",
        "password": "password",
        "db_owner": true,
        "attributes": ["SUPERUSER", "LOGIN"]
      }
    ],
    "port": 0,
    "nodes": [
      { "name": "n1", "host_ids": ["host-1"] }
    ]
  }
}
EOF

# attempt to stop the n1 instance
# on main, this would return a validation error
cp1-req stop-instance a37e2ed1-bb81-49cb-872b-2bdb7fff3bbc \
    a37e2ed1-bb81-49cb-872b-2bdb7fff3bbc-n1-689qacsi

@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9c4d85e6-d1a0-4b19-ad70-0e2378a25eb6

📥 Commits

Reviewing files that changed from the base of the PR and between e7aa4d7 and 6528c9d.

⛔ Files ignored due to path filters (10)
  • api/apiv1/gen/control_plane/service.go is excluded by !**/gen/**
  • api/apiv1/gen/http/cli/control_plane/cli.go is excluded by !**/gen/**
  • api/apiv1/gen/http/control_plane/client/cli.go is excluded by !**/gen/**
  • api/apiv1/gen/http/control_plane/client/encode_decode.go is excluded by !**/gen/**
  • api/apiv1/gen/http/control_plane/server/encode_decode.go is excluded by !**/gen/**
  • api/apiv1/gen/http/control_plane/server/types.go is excluded by !**/gen/**
  • api/apiv1/gen/http/openapi.json is excluded by !**/gen/**
  • api/apiv1/gen/http/openapi.yaml is excluded by !**/gen/**
  • api/apiv1/gen/http/openapi3.json is excluded by !**/gen/**
  • api/apiv1/gen/http/openapi3.yaml is excluded by !**/gen/**
📒 Files selected for processing (2)
  • api/apiv1/design/api.go
  • e2e/database_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • api/apiv1/design/api.go

📝 Walkthrough

Walkthrough

API schema changes replace Identifier with g.String for instance control endpoints and add MinLength(1)/MaxLength(63) to instance identifier fields; an e2e test passes InstanceID as a raw string in the RestartInstance payload.

Changes

Instance identifier schema + test

Layer / File(s) Summary
API schema: instance id -> g.String with length constraints
api/apiv1/design/api.go
switchover-database-node adds MinLength(1)/MaxLength(63) for candidate_instance_id; restart-instance, stop-instance, and start-instance change instance_id from Identifier to g.String and add MinLength(1)/MaxLength(63) constraints.
E2E: pass raw InstanceID in RestartInstance payload
e2e/database_test.go
DatabaseFixture.RestartInstance now sets InstanceID from options.InstanceID directly (removed controlplane.Identifier(...) wrapper) when calling d.client.RestartInstance.

Poem

🐰 I nudge the schema, soft and spry,
Strings trimmed tidy, limits set high—
Tests now pass the ID as-is,
A little hop, a cleaner biz 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: modifying API validation to allow longer instance IDs.
Description check ✅ Passed The description includes a clear summary, specific testing instructions with reproduction steps, and proper Conventional Commits format, but lacks explicit coverage of all template sections.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/instance-id-endpoints

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codacy-production

codacy-production Bot commented Jun 2, 2026

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
api/apiv1/design/api.go (1)

731-741: ⚡ Quick win

Consider a shared InstanceID type instead of repeating the inline constraints.

The same g.String + MinLength(1) + MaxLength(63) block is duplicated across restart-instance, stop-instance, and start-instance, and the related candidate_instance_id (line 382) is a bare g.String with no constraints. Defining a single InstanceID type in common.go (mirroring Identifier) would centralize the limit, keep the three endpoints in sync, and let candidate_instance_id reuse it. Note this also drops Identifier's charset rules for instance_id; since these values are used directly as storage keys that's acceptable, but a dedicated type documents the looser contract explicitly.

♻️ Sketch of a shared type in common.go
var InstanceID = g.Type("InstanceID", g.String, func() {
	g.Description("An instance identifier: database_id + node name + host hash. 1-63 characters.")
	g.MinLength(1)
	g.MaxLength(63)
	g.Example("68f50878-44d2-4524-a823-e31bd478706d-n1-689qacsi")
})

Then each endpoint becomes:

-			g.Attribute("instance_id", g.String, func() {
-				g.Description("The ID of the instance to restart.")
-				g.Example("68f50878-44d2-4524-a823-e31bd478706d-n1-689qacsi")
-				g.MinLength(1)
-				g.MaxLength(63)
-			})
+			g.Attribute("instance_id", InstanceID, func() {
+				g.Description("The ID of the instance to restart.")
+			})

Remember to run make -C api generate after any design change.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@api/apiv1/design/api.go` around lines 731 - 741, The repeated inline instance
ID constraints should be consolidated into a shared InstanceID type in
common.go: define a g.Type named InstanceID (string) with Description,
MinLength(1), MaxLength(63) and Example, then replace the inline g.String +
MinLength/MaxLength usages in the restart-instance, stop-instance, and
start-instance payloads (and the candidate_instance_id declaration) to reference
InstanceID instead of duplicating constraints; ensure Identifier remains
unchanged if needed, update usages to the new InstanceID symbol, and run make -C
api generate after the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@api/apiv1/design/api.go`:
- Around line 731-741: The repeated inline instance ID constraints should be
consolidated into a shared InstanceID type in common.go: define a g.Type named
InstanceID (string) with Description, MinLength(1), MaxLength(63) and Example,
then replace the inline g.String + MinLength/MaxLength usages in the
restart-instance, stop-instance, and start-instance payloads (and the
candidate_instance_id declaration) to reference InstanceID instead of
duplicating constraints; ensure Identifier remains unchanged if needed, update
usages to the new InstanceID symbol, and run make -C api generate after the
change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 113820c7-b850-41f4-844e-1fd2f141d759

📥 Commits

Reviewing files that changed from the base of the PR and between 58766e1 and e7aa4d7.

⛔ Files ignored due to path filters (10)
  • api/apiv1/gen/control_plane/service.go is excluded by !**/gen/**
  • api/apiv1/gen/http/cli/control_plane/cli.go is excluded by !**/gen/**
  • api/apiv1/gen/http/control_plane/client/cli.go is excluded by !**/gen/**
  • api/apiv1/gen/http/control_plane/client/encode_decode.go is excluded by !**/gen/**
  • api/apiv1/gen/http/control_plane/server/encode_decode.go is excluded by !**/gen/**
  • api/apiv1/gen/http/control_plane/server/types.go is excluded by !**/gen/**
  • api/apiv1/gen/http/openapi.json is excluded by !**/gen/**
  • api/apiv1/gen/http/openapi.yaml is excluded by !**/gen/**
  • api/apiv1/gen/http/openapi3.json is excluded by !**/gen/**
  • api/apiv1/gen/http/openapi3.yaml is excluded by !**/gen/**
📒 Files selected for processing (1)
  • api/apiv1/design/api.go

@jason-lynch jason-lynch force-pushed the fix/instance-id-endpoints branch 2 times, most recently from c393827 to 9e14940 Compare June 2, 2026 19:17
Fixes an issue where valid instance IDs are rejected by our API
validation. Instance IDs are an aggregate that includes database ID,
node name, and a hash of the host ID. When the database ID is the
maximum allowable length for an Identifier, its instance IDs will
exceed the maximum length for an Identifier. This commit switches to
using strings with longer limits to avoid this issue.
@jason-lynch jason-lynch force-pushed the fix/instance-id-endpoints branch from 9e14940 to 6528c9d Compare June 2, 2026 19:34
@jason-lynch jason-lynch marked this pull request as ready for review June 2, 2026 21:01
@jason-lynch jason-lynch merged commit dd1ca23 into main Jun 3, 2026
3 checks passed
@jason-lynch jason-lynch deleted the fix/instance-id-endpoints branch June 3, 2026 11:55
tsivaprasad pushed a commit that referenced this pull request Jun 4, 2026
Fixes an issue where valid instance IDs are rejected by our API
validation. Instance IDs are an aggregate that includes database ID,
node name, and a hash of the host ID. When the database ID is the
maximum allowable length for an Identifier, its instance IDs will
exceed the maximum length for an Identifier. This commit switches to
using strings with longer limits to avoid this issue.
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