Skip to content

server/apiinternal: use generated DRPC gateway routes#168665

Merged
trunk-io[bot] merged 1 commit into
cockroachdb:masterfrom
shubhamdhama:auto-generate-httproute-info
May 14, 2026
Merged

server/apiinternal: use generated DRPC gateway routes#168665
trunk-io[bot] merged 1 commit into
cockroachdb:masterfrom
shubhamdhama:auto-generate-httproute-info

Conversation

@shubhamdhama
Copy link
Copy Markdown
Contributor

@shubhamdhama shubhamdhama commented Apr 19, 2026

Replace the manually maintained HTTP route tables (~100 entries across
three files) with auto-generated route data from protoc-gen-go-drpc.
The generator reads google.api.http proto annotations and emits
DRPC<Service>GatewayRoutes functions that return []drpc.HTTPRoute,
so adding a new HTTP-annotated RPC no longer requires a corresponding
change in apiinternal.

This also simplifies the package: the three satellite files
(api_internal_status.go, api_internal_admin.go, api_internal_ts.go)
and the per-service struct fields are no longer needed. Route registration
now happens inline in the constructor from generated data.

Fixes: #153047
Epic: none
Release note: None

@shubhamdhama shubhamdhama requested a review from a team April 19, 2026 11:58
@shubhamdhama shubhamdhama requested a review from a team as a code owner April 19, 2026 11:58
@trunk-io
Copy link
Copy Markdown
Contributor

trunk-io Bot commented Apr 19, 2026

😎 Merged successfully - details.

@blathers-crl
Copy link
Copy Markdown

blathers-crl Bot commented Apr 19, 2026

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@shubhamdhama shubhamdhama added the do-not-merge bors won't merge a PR with this label. label Apr 19, 2026
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@shubhamdhama
Copy link
Copy Markdown
Contributor Author

shubhamdhama commented Apr 19, 2026

Remove do-not-merge label once,

@shubhamdhama
Copy link
Copy Markdown
Contributor Author

  • TODO: why some tests who don't have the DRPC gateway coverage aren't causing tests failure.

@shubhamdhama shubhamdhama force-pushed the auto-generate-httproute-info branch from 1bde011 to 604e7a5 Compare May 14, 2026 06:35
@shubhamdhama shubhamdhama removed the do-not-merge bors won't merge a PR with this label. label May 14, 2026
Comment thread pkg/server/apiinternal/api_internal.go Outdated
apiutil.WriteHTTPError(ctx, w, req, err)
return
}
if vars := mux.Vars(req); len(vars) > 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.

This constraint seems to be new in this PR. What changed?

Copy link
Copy Markdown
Contributor Author

@shubhamdhama shubhamdhama May 14, 2026

Choose a reason for hiding this comment

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

It's simply guarding against calling decodePathVars when we don't need to call it to avoid allocating a map. It can be moved within decodePathVars or avoided completely but overall not a behavior change

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.

I've removed it btw as it was unnecessary optimization.

return status.Errorf(codes.InvalidArgument, "failed to decode request body: %v", err)
reqType := fnType.In(1).Elem()
return func(w http.ResponseWriter, req *http.Request) {
newReq := reflect.New(reqType)
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.

Can you add comments around the reflection calls so the code will be easy to follow/read?

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.

done

Replace the manually maintained HTTP route tables (~100 entries across
three files) with auto-generated route data from `protoc-gen-go-drpc`.
The generator reads `google.api.http` proto annotations and emits
`DRPC<Service>GatewayRoutes` functions that return `[]drpc.HTTPRoute`,
so adding a new HTTP-annotated RPC no longer requires a corresponding
change in `apiinternal`.

This also simplifies the package: the three satellite files
(`api_internal_status.go`, `api_internal_admin.go`, `api_internal_ts.go`)
and the per-service struct fields are no longer needed. Route registration
now happens inline in the constructor from generated data.

Fixes: cockroachdb#153047
Epic: none
Release note: None
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@shubhamdhama shubhamdhama force-pushed the auto-generate-httproute-info branch from 604e7a5 to 8e71487 Compare May 14, 2026 10:39
Copy link
Copy Markdown
Contributor

@cthumuluru-crdb cthumuluru-crdb left a comment

Choose a reason for hiding this comment

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

I'm assuming existing tests are sufficient since this is a refactor. If not, please add additional tests. Otherwise the PR looks good to me.

@shubhamdhama
Copy link
Copy Markdown
Contributor Author

TFTR!

/trunk merge

@blathers-crl
Copy link
Copy Markdown

blathers-crl Bot commented May 14, 2026

Detected infrastructure failure on trunk-merge branch (matched: self-hosted runner lost communication with the server). Automatically resubmitting to merge queue (attempt 1 of 2). (run link)

@blathers-crl
Copy link
Copy Markdown

blathers-crl Bot commented May 14, 2026

/trunk merge

@trunk-io trunk-io Bot merged commit 830d20f into cockroachdb:master May 14, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

drpc,server: auto-generate HTTP routes for mux registration

3 participants