Skip to content

Commit

Permalink
Support HTTP proxy env variables (#4769)
Browse files Browse the repository at this point in the history
Support HTTP proxy variables (some docs
https://superuser.com/questions/944958/are-http-proxy-https-proxy-and-no-proxy-environment-variables-standard).

The codebase already supports it, but some places were missed. There
were also two problems:
1. query grpc gateway was connecting to :16686 which is not recognized
by NO_PROXY
2. grpc reporter in agent when used with all-in-one was connecting to
`:14250` also not recognized by NO_PROXY


Example of proxy vars set on OpenShift
```
 - name: HTTP_PROXY
              value: >-
                http://proxy-user1:foo@ec2-32-138-32-212.us-east-2.compute.amazonaws.com:3128
            - name: http_proxy
              value: >-
                http://proxy-user1:foo@ec2-32-138-32-212.us-east-2.compute.amazonaws.com:3128
            - name: HTTPS_PROXY
              value: >-
                http://proxy-user1:foo@ec2-32-138-32-221.us-east-2.compute.amazonaws.com:3128
            - name: https_proxy
              value: >-
                http://proxy-user1:foo@ec2-32-138-32-212.us-east-2.compute.amazonaws.com:3128
            - name: NO_PROXY
              value: >-
                .cluster.local,.svc,.us-east-2.compute.internal,10.0.0.0/16,10.128.0.0/14,127.0.0.1,169.254.169.254,172.30.0.0/16,api-int.rererer.qe.devcluster.openshift.com,localhost,test.no-proxy.com
            - name: no_proxy
              value: >-
                .cluster.local,.svc,.us-east-2.compute.internal,10.0.0.0/16,10.128.0.0/14,127.0.0.1,169.254.169.254,172.30.0.0/16,api-int.rerererer.qe.devcluster.openshift.com,localhost,test.no-proxy.com
```

PR is related to
jaegertracing/jaeger-operator#2330
```
make build-binaries-linux
DOCKER_NAMESPACE=pavolloffay DOCKER_TAG=proxy-3 make docker-images-jaeger-backend
```

---------

Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
  • Loading branch information
pavolloffay committed Sep 22, 2023
1 parent a53ddaf commit af70f26
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/agent/app/reporter/grpc/builder.go
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/jaegertracing/jaeger/pkg/discovery"
"github.com/jaegertracing/jaeger/pkg/discovery/grpcresolver"
"github.com/jaegertracing/jaeger/pkg/metrics"
"github.com/jaegertracing/jaeger/pkg/netutils"
)

// ConnBuilder Struct to hold configurations
Expand Down Expand Up @@ -82,6 +83,7 @@ func (b *ConnBuilder) CreateConnection(logger *zap.Logger, mFactory metrics.Fact
if b.CollectorHostPorts == nil {
return nil, errors.New("at least one collector hostPort address is required when resolver is not available")
}
b.CollectorHostPorts = netutils.FixLocalhost(b.CollectorHostPorts)
if len(b.CollectorHostPorts) > 1 {
r := manual.NewBuilderWithScheme("jaeger-manual")
dialOptions = append(dialOptions, grpc.WithResolvers(r))
Expand Down
2 changes: 2 additions & 0 deletions cmd/query/app/apiv3/grpc_gateway.go
Expand Up @@ -26,12 +26,14 @@ import (
"google.golang.org/grpc/credentials/insecure"

"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
"github.com/jaegertracing/jaeger/pkg/netutils"
"github.com/jaegertracing/jaeger/pkg/tenancy"
"github.com/jaegertracing/jaeger/proto-gen/api_v3"
)

// RegisterGRPCGateway registers api_v3 endpoints into provided mux.
func RegisterGRPCGateway(ctx context.Context, logger *zap.Logger, r *mux.Router, basePath string, grpcEndpoint string, grpcTLS tlscfg.Options, tm *tenancy.Manager) error {
grpcEndpoint = netutils.FixLocalhost([]string{grpcEndpoint})[0]
jsonpb := &runtime.JSONPb{}

muxOpts := []runtime.ServeMuxOption{
Expand Down
1 change: 1 addition & 0 deletions pkg/es/config/config.go
Expand Up @@ -385,6 +385,7 @@ func GetHTTPRoundTripper(c *Configuration, logger *zap.Logger) (http.RoundTrippe
return nil, err
}
return &http.Transport{
Proxy: http.ProxyFromEnvironment,
TLSClientConfig: ctlsConfig,
}, nil
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/netutils/port.go
Expand Up @@ -17,6 +17,7 @@ package netutils
import (
"net"
"strconv"
"strings"
)

// GetPort returns the port of an endpoint address.
Expand All @@ -33,3 +34,16 @@ func GetPort(addr net.Addr) (int, error) {

return parsedPort, nil
}

// FixLocalhost adds explicit localhost to endpoints binding to all interfaces because :port is not recognized by NO_PROXY
// e.g. :8080 becomes localhost:8080
func FixLocalhost(hostports []string) []string {
var fixed []string
for _, e := range hostports {
if strings.HasPrefix(e, ":") {
e = "localhost" + e
}
fixed = append(fixed, e)
}
return fixed
}
6 changes: 6 additions & 0 deletions pkg/netutils/port_test.go
Expand Up @@ -66,3 +66,9 @@ func TestGetPort(t *testing.T) {
}
}
}

func TestFixLocalhost(t *testing.T) {
endpoints := []string{"collector:1111", ":2222"}
fixed := FixLocalhost(endpoints)
assert.Equal(t, []string{"collector:1111", "localhost:2222"}, fixed)
}

0 comments on commit af70f26

Please sign in to comment.