mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-29 06:30:51 -08: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"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -73,7 +74,13 @@ func (api *API) HTTPHandler(grpcAddr string) (http.Handler, error) {
|
||||||
enc := new(protoutil.JSONPb)
|
enc := new(protoutil.JSONPb)
|
||||||
mux := runtime.NewServeMux(runtime.WithMarshalerOption(enc.ContentType(), enc))
|
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)
|
err := pb.RegisterAdminHandlerFromEndpoint(ctx, mux, grpcAddr, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue