diff --git a/cmd/logcli/main.go b/cmd/logcli/main.go index e3e4034ce4..0cf8763682 100644 --- a/cmd/logcli/main.go +++ b/cmd/logcli/main.go @@ -484,6 +484,7 @@ func newQueryClient(app *kingpin.Application) client.Client { app.Flag("auth-header", "The authorization header used. Can also be set using LOKI_AUTH_HEADER env var.").Default("Authorization").Envar("LOKI_AUTH_HEADER").StringVar(&client.AuthHeader) app.Flag("proxy-url", "The http or https proxy to use when making requests. Can also be set using LOKI_HTTP_PROXY_URL env var.").Default("").Envar("LOKI_HTTP_PROXY_URL").StringVar(&client.ProxyURL) app.Flag("compress", "Request that Loki compress returned data in transit. Can also be set using LOKI_HTTP_COMPRESSION env var.").Default("false").Envar("LOKI_HTTP_COMPRESSION").BoolVar(&client.Compression) + app.Flag("envproxy", "Use ProxyFromEnvironment to use net/http ProxyFromEnvironment configuration, eg HTTP_PROXY").Default("false").Envar("LOKI_ENV_PROXY").BoolVar(&client.EnvironmentProxy) return client } diff --git a/pkg/logcli/client/client.go b/pkg/logcli/client/client.go index 1ffbfdedf0..f245a9f057 100644 --- a/pkg/logcli/client/client.go +++ b/pkg/logcli/client/client.go @@ -74,21 +74,22 @@ type BackoffConfig struct { // Client contains fields necessary to query a Loki instance type DefaultClient struct { - TLSConfig config.TLSConfig - Username string - Password string - Address string - OrgID string - Tripperware Tripperware - BearerToken string - BearerTokenFile string - Retries int - QueryTags string - NoCache bool - AuthHeader string - ProxyURL string - BackoffConfig BackoffConfig - Compression bool + TLSConfig config.TLSConfig + Username string + Password string + Address string + OrgID string + Tripperware Tripperware + BearerToken string + BearerTokenFile string + Retries int + QueryTags string + NoCache bool + AuthHeader string + ProxyURL string + BackoffConfig BackoffConfig + Compression bool + EnvironmentProxy bool } // Query uses the /api/v1/query endpoint to execute an instant query @@ -306,6 +307,10 @@ func (c *DefaultClient) doRequest(path, query string, quiet bool, out interface{ TLSConfig: c.TLSConfig, } + if c.EnvironmentProxy { + clientConfig.ProxyFromEnvironment = true + } + if c.ProxyURL != "" { prox, err := url.Parse(c.ProxyURL) if err != nil {