Skip to content

Commit

Permalink
Adds the K6_INFLUXDB_PROXY environment variable support, closes #3418
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanovOleg committed Oct 26, 2023
1 parent 8e2c27a commit edac25a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions output/influxdb/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
type Config struct {
// Connection.
Addr null.String `json:"addr" envconfig:"K6_INFLUXDB_ADDR"`
Proxy null.String `json:"proxy,omitempty" envconfig:"K6_INFLUXDB_PROXY"`
Username null.String `json:"username,omitempty" envconfig:"K6_INFLUXDB_USERNAME"`
Password null.String `json:"password,omitempty" envconfig:"K6_INFLUXDB_PASSWORD"`
Insecure null.Bool `json:"insecure,omitempty" envconfig:"K6_INFLUXDB_INSECURE"`
Expand Down Expand Up @@ -57,6 +58,9 @@ func (c Config) Apply(cfg Config) Config {
if cfg.Addr.Valid {
c.Addr = cfg.Addr
}
if cfg.Proxy.Valid {
c.Proxy = cfg.Proxy
}
if cfg.Username.Valid {
c.Username = cfg.Username
}
Expand Down Expand Up @@ -159,6 +163,8 @@ func ParseURL(text string) (Config, error) {
c.ConcurrentWrites = null.IntFrom(int64(writes))
case "tagsAsFields":
c.TagsAsFields = vs
case "proxy":
c.Proxy = null.StringFrom(vs[0])
default:
return c, fmt.Errorf("unknown query parameter: %s", k)
}
Expand Down
14 changes: 12 additions & 2 deletions output/influxdb/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package influxdb

import (
"fmt"
"net/http"
"net/url"
"strings"

client "github.com/influxdata/influxdb1-client/v2"
Expand All @@ -18,13 +20,21 @@ func MakeClient(conf Config) (client.Client, error) {
if conf.Addr.String == "" {
conf.Addr = null.StringFrom("http://localhost:8086")
}
return client.NewHTTPClient(client.HTTPConfig{
clientHTTPConfig := client.HTTPConfig{
Addr: conf.Addr.String,
Username: conf.Username.String,
Password: conf.Password.String,
UserAgent: "k6",
InsecureSkipVerify: conf.Insecure.Bool,
})
}
if conf.Proxy.Valid && conf.Proxy.String != "" {
parsedProxyURL, err := url.Parse(conf.Proxy.String)
if err != nil {
return nil, err
}
clientHTTPConfig.Proxy = http.ProxyURL(parsedProxyURL)
}
return client.NewHTTPClient(clientHTTPConfig)
}

func MakeBatchConfig(conf Config) client.BatchPointsConfig {
Expand Down

0 comments on commit edac25a

Please sign in to comment.