feat: add opt-in support for ProxyFroomEnvironment in logcli (#11742) (#14950)

pull/14971/head
Aaron Delaney 1 year ago committed by GitHub
parent 9fb2f38552
commit c56b95d298
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      cmd/logcli/main.go
  2. 35
      pkg/logcli/client/client.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
}

@ -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 {

Loading…
Cancel
Save