mirror of
https://github.com/prometheus/prometheus
synced 2024-12-27 00:53:12 +00:00
web: avoid proxy to connect to the local gRPC server (#4572)
By default the gRPC client of the REST API gateway relies on the HTTP_PROXY variable to connect to the local gRPC server which isn't desired as the server runs in the same process. This change uses a custom dialer that connects directly to the server's address. Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
parent
94fff219ab
commit
181f07ef26
@ -18,6 +18,7 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -73,7 +74,13 @@ func (api *API) HTTPHandler(grpcAddr string) (http.Handler, error) {
|
||||
enc := new(protoutil.JSONPb)
|
||||
mux := runtime.NewServeMux(runtime.WithMarshalerOption(enc.ContentType(), enc))
|
||||
|
||||
opts := []grpc.DialOption{grpc.WithInsecure()}
|
||||
opts := []grpc.DialOption{
|
||||
grpc.WithInsecure(),
|
||||
// Replace the default dialer that connects through proxy when HTTP_PROXY is set.
|
||||
grpc.WithDialer(func(addr string, _ time.Duration) (net.Conn, error) {
|
||||
return (&net.Dialer{}).DialContext(ctx, "tcp", addr)
|
||||
}),
|
||||
}
|
||||
|
||||
err := pb.RegisterAdminHandlerFromEndpoint(ctx, mux, grpcAddr, opts)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user