refactor: migrate gorilla/mux to net/http ServeMux - #408
Conversation
Signed-off-by: Shivansh Sahu <sahushivansh142@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
💤 Files with no reviewable changes (1)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe REST API handler migrated from Gorilla mux to ChangesHTTP routing migration
Estimated code review effort: 1 (Trivial) | ~5 minutes Merge Risk: 🔵 Low · up to The routing migration is otherwise localized, but removing the gorilla/mux module entry while it remains transitively required could cause dependency-resolution or downstream build failures. Retain it as an indirect dependency before merging. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Docstring CoverageExplanation No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1 files. (1 skipped: 1 unsupported.) ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
matthyx
left a comment
There was a problem hiding this comment.
The routing migration itself looks correct: docs.OpenAPIV2Prefix is "/openapi/v2/" (trailing slash), so rtr.Handle("GET "+docs.OpenAPIV2Prefix, ...) still gets Go 1.22 subtree matching, preserving the old PathPrefix(...).Methods("GET") behavior for the swagger/redoc/rapidoc sub-paths. /v1/triggerAction stays an exact-match, all-methods route, matching the previous mux.HandleFunc semantics.
One blocker before this can merge though: go.mod wasn't updated. This PR removes the only usages of github.com/gorilla/mux and go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux in the repo, but both are still listed as direct requires in go.mod. Meanwhile go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp, which is newly imported directly in restapihandler/restapi.go, is still marked // indirect. Please run go mod tidy and commit the resulting go.mod/go.sum — as written, the PR doesn't actually "eliminate the deprecated dependency" it claims to (gorilla/mux stays in the module graph as an explicit dependency), and this will likely fail a go mod tidy --check style CI gate.
Minor nit: there's a stray blank line with trailing whitespace right after rtr := http.NewServeMux() — gofmt/whitespace linters will flag it.
Also worth a note (not blocking, per CodeRabbit): tracing used to wrap the whole router via rtr.Use(otelmux.Middleware(...)), so unmatched/404 requests were traced too. Now otelhttp.NewHandler is only applied per-registered-route, so unmatched paths lose tracing coverage. Bounded risk, but flagging in case that telemetry gap matters for this service.
Signed-off-by: Shivansh Sahu <sahushivansh142@gmail.com>
|
@matthyx ptal at this too |
matthyx
left a comment
There was a problem hiding this comment.
Confirmed the fix: go.mod/go.sum are now properly tidied — gorilla/mux moved to indirect, otelmux removed entirely, otelhttp promoted to direct. The stray whitespace nit is gone too. Routing behavior is unchanged from the previous review (still correct). LGTM, approving.
|
thanks @matthyx !! |
This migrates the operator HTTP API from
gorilla/muxto the standard libraryhttp.ServeMuxwith Go 1.22 routing features. This eliminates the deprecated dependencygithub.com/gorilla/muxand replacesotelmuxwithotelhttpas requested in kubescape/kubescape#3620.Summary by CodeRabbit
/v1/triggerActionendpoint.