Skip to content

Agent Mesh

hack: lint with golangci-lint v2.14.0 and deadcode from x/tools v0.50.0

Antonio Ojea406c79023146
diff --git a/hack/lint.sh b/hack/lint.sh
index 853757bf..9636a05c 100755
--- a/hack/lint.sh
+++ b/hack/lint.sh
@@ -21,17 +21,17 @@ set -o pipefail
REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
cd $REPO_ROOT
-docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v2.11.4 golangci-lint run -v
+docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v2.14.0 golangci-lint run -v
# nano-init is a separate module, so ./... above does not reach it.
-docker run --rm -v $(pwd):/app -w /app/cmd/nano-init golangci/golangci-lint:v2.11.4 golangci-lint run -v
+docker run --rm -v $(pwd):/app -w /app/cmd/nano-init golangci/golangci-lint:v2.14.0 golangci-lint run -v
# golangci-lint has no deadcode linter (removed upstream in v1.49) and its
# replacement, "unused", ignores exported identifiers. This catches exported
# code that is unreachable from every binary and test.
# mobile/ is exported to Android over cgo/FFI and development/examples/ is sample code.
DEADCODE_EXCLUDES='^(mobile/|development/examples/)'
-deadcode_report=$(go run golang.org/x/tools/cmd/[email protected] -test ./... | grep -Ev "${DEADCODE_EXCLUDES}" || true)
+deadcode_report=$(go run golang.org/x/tools/cmd/[email protected] -test ./... | grep -Ev "${DEADCODE_EXCLUDES}" || true)
if [[ -n "${deadcode_report}" ]]; then
echo "Dead code detected (unreachable from any binary or test):"
echo "${deadcode_report}"
diff --git a/internal/node/inference_service.go b/internal/node/inference_service.go
index 08659f36..bc862b91 100644
--- a/internal/node/inference_service.go
+++ b/internal/node/inference_service.go
@@ -110,11 +110,10 @@ func (s *InferenceService) trackActive(next http.Handler) http.Handler {
func (s *InferenceService) newInferenceProxy() http.Handler {
return &httputil.ReverseProxy{
- Director: func(req *http.Request) {
- if _, ok := req.Header["User-Agent"]; !ok {
- req.Header.Set("User-Agent", "")
- }
- },
+ // The transport addresses the backend; the proxy itself strips the
+ // inbound Forwarded and X-Forwarded-* headers and blanks a missing
+ // User-Agent.
+ Rewrite: func(*httputil.ProxyRequest) {},
Transport: &inferenceTransport{
backend: s.backendURL,
auth: s.backendAuth,
@@ -132,11 +131,6 @@ type inferenceTransport struct {
func (t *inferenceTransport) RoundTrip(req *http.Request) (*http.Response, error) {
attemptReq := req.Clone(req.Context())
attemptReq.Header.Del("Accept-Encoding") // Prevent gzipped response from breaking token tracking
- // A Director proxy does not manage X-Forwarded-For, and RemoteAddr here is
- // a peer id, so an inbound value would reach the backend as-is.
- attemptReq.Header.Del("X-Forwarded-For")
- attemptReq.Header.Del("X-Forwarded-Host")
- attemptReq.Header.Del("X-Forwarded-Proto")
t.auth.apply(attemptReq.Header)
attemptReq.URL.Scheme = t.backend.Scheme
diff --git a/internal/node/sidecar.go b/internal/node/sidecar.go
index ea6ca1e1..2453083f 100644
--- a/internal/node/sidecar.go
+++ b/internal/node/sidecar.go
@@ -690,16 +690,16 @@ func createEgressProxy(node *SamNode) http.Handler {
transport := libp2phttp.NewTransport(node.Host)
proxy := &httputil.ReverseProxy{
- Director: func(req *http.Request) {
- ctx := allowLimitedEgressConn(req.Context())
- *req = *req.WithContext(ctx)
+ Rewrite: func(pr *httputil.ProxyRequest) {
+ req := pr.Out.WithContext(allowLimitedEgressConn(pr.Out.Context()))
+ pr.Out = req
parts := strings.SplitN(req.URL.Path, "/", 6)
if len(parts) < 5 {
return
}
peerID := parts[2]
- node.prepareEgressPeer(ctx, peerID)
+ node.prepareEgressPeer(req.Context(), peerID)
serviceType := parts[3]
serviceName := parts[4]
upstreamPath := ""
@@ -763,8 +763,8 @@ func createEgressProxy(node *SamNode) http.Handler {
return
}
// The verdict is for the canonical peer, so the dial must name the
- // same form: rewrite the segment the Director will re-parse rather
- // than let a non-canonical spelling travel past the gate.
+ // same form: rewrite the segment the proxy's Rewrite will re-parse
+ // rather than let a non-canonical spelling travel past the gate.
if canonical := pid.String(); route.peerID != canonical {
parts := strings.SplitN(r.URL.Path, "/", 6)
if len(parts) >= 3 {
diff --git a/internal/standalone/standalone_test.go b/internal/standalone/standalone_test.go
index 6db0e728..79782329 100644
--- a/internal/standalone/standalone_test.go
+++ b/internal/standalone/standalone_test.go
@@ -202,4 +202,3 @@ func TestResponseRecorder(t *testing.T) {
t.Fatalf("rec.Header(Content-Length) = %q, want 12", got)
}
}
-
diff --git a/internal/storage/round_trip_test.go b/internal/storage/round_trip_test.go
index 3dfdf67b..23f206b8 100644
--- a/internal/storage/round_trip_test.go
+++ b/internal/storage/round_trip_test.go
@@ -47,7 +47,7 @@ func requireAllFieldsSet(t *testing.T, v any, skip ...string) {
}
val := reflect.ValueOf(v)
- if val.Kind() == reflect.Ptr {
+ if val.Kind() == reflect.Pointer {
val = val.Elem()
}
for i := 0; i < val.NumField(); i++ {
@@ -73,7 +73,7 @@ func requireFieldsRoundTrip(t *testing.T, want, got any, skip ...string) {
w := reflect.ValueOf(want)
g := reflect.ValueOf(got)
- if w.Kind() == reflect.Ptr {
+ if w.Kind() == reflect.Pointer {
w, g = w.Elem(), g.Elem()
}
for i := 0; i < w.NumField(); i++ {