From 46b84adaaa3a7f3a0b15413ca5084ea2e025fac6 Mon Sep 17 00:00:00 2001 From: Paul Balogh Date: Wed, 8 Feb 2023 23:42:37 -0600 Subject: [PATCH] Change to envconfig fork to enable lookups from map Signed-off-by: Paul Balogh --- go.mod | 4 ++-- go.sum | 11 +++++------ pkg/influxdb/config.go | 8 +++++--- pkg/influxdb/config_test.go | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 3908bca..5bea901 100644 --- a/go.mod +++ b/go.mod @@ -4,10 +4,10 @@ go 1.18 require ( github.com/influxdata/influxdb-client-go/v2 v2.5.1 - github.com/kelseyhightower/envconfig v1.4.0 + github.com/mstoykov/envconfig v1.4.1-0.20220114105314-765c6d8c76f1 github.com/sirupsen/logrus v1.9.0 github.com/stretchr/testify v1.8.0 - go.k6.io/k6 v0.41.0 + go.k6.io/k6 v0.42.0 gopkg.in/guregu/null.v3 v3.3.0 ) diff --git a/go.sum b/go.sum index 7b3e057..f320656 100644 --- a/go.sum +++ b/go.sum @@ -24,8 +24,6 @@ github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 h1:W9WBk7 github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= -github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= -github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= github.com/klauspost/compress v1.15.11 h1:Lcadnb3RKGin4FYM/orgq0qde+nc15E5Cbqg4B9Sx9c= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= @@ -58,6 +56,7 @@ github.com/mccutchen/go-httpbin v1.1.2-0.20190116014521-c5cb2f4802fa h1:lx8ZnNPw github.com/mstoykov/atlas v0.0.0-20220808085829-90340e9998bd h1:x/wQ8/umYu2x0icx5wNNTSK1NlkYVmsgzQ+U6v4ijv0= github.com/mstoykov/atlas v0.0.0-20220808085829-90340e9998bd/go.mod h1:9vRHVuLCjoFfE3GT06X0spdOAO+Zzo4AMjdIwUHBvAk= github.com/mstoykov/envconfig v1.4.1-0.20220114105314-765c6d8c76f1 h1:94EkGmhXrVUEal+uLwFUf4fMXPhZpM5tYxuIsxrCCbI= +github.com/mstoykov/envconfig v1.4.1-0.20220114105314-765c6d8c76f1/go.mod h1:vk/d9jpexY2Z9Bb0uB4Ndesss1Sr0Z9ZiGUrg5o9VGk= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -83,8 +82,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= -go.k6.io/k6 v0.41.0 h1:w/J10BV3MGahDF3UsT3WESNBCpsw7soxj9GaLCGTf4I= -go.k6.io/k6 v0.41.0/go.mod h1:ZrgrR06UZbzZt9u+so/yQhlkJFH5gkJ3qCp1hwq1mEU= +go.k6.io/k6 v0.42.0 h1:TXYyaNPI5GuX2k+r0EDqawdAkdU2Kuxl68GpBbwSkUk= +go.k6.io/k6 v0.42.0/go.mod h1:BY6vVmsNSaetHmPqQ8D6VMJJRptzwevdSpURQmSkrMQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -127,9 +126,9 @@ golang.org/x/time v0.0.0-20220922220347-f3bd1da661af/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08 h1:pc16UedxnxXXtGxHCSUhafAoVHQZ0yXl8ZelMH4EETc= +google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 h1:hrbNEivu7Zn1pxvHk6MBrq9iE22woVILTHqexqBxe6I= google.golang.org/grpc v1.49.0 h1:WTLtQzmQori5FUH25Pq4WT22oCsv8USpQ+F6rqtsmxw= -google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= diff --git a/pkg/influxdb/config.go b/pkg/influxdb/config.go index bd6861a..2261404 100644 --- a/pkg/influxdb/config.go +++ b/pkg/influxdb/config.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "github.com/kelseyhightower/envconfig" + "github.com/mstoykov/envconfig" "go.k6.io/k6/lib/types" "gopkg.in/guregu/null.v3" ) @@ -105,8 +105,10 @@ func GetConsolidatedConfig( } envConfig := Config{} - if err := envconfig.Process("", &envConfig); err != nil { - // TODO: get rid of envconfig and actually use the env parameter... + if err := envconfig.Process("", &envConfig, func(key string) (string, bool) { + v, ok := env[key] + return v, ok + }); err != nil { return result, err } result = result.Apply(envConfig) diff --git a/pkg/influxdb/config_test.go b/pkg/influxdb/config_test.go index 1a0666d..9e74e39 100644 --- a/pkg/influxdb/config_test.go +++ b/pkg/influxdb/config_test.go @@ -2,6 +2,9 @@ package influxdb import ( "testing" + "time" + + "go.k6.io/k6/lib/types" "github.com/stretchr/testify/assert" "gopkg.in/guregu/null.v3" @@ -27,3 +30,32 @@ func TestParseURL(t *testing.T) { }) } } + +func TestGetConsolidatedConfig(t *testing.T) { + t.Parallel() + duration999s, _ := time.ParseDuration("999s") + testdata := map[string]string{ + "K6_INFLUXDB_ADDR": "http://test-url", + "K6_INFLUXDB_ORGANIZATION": "test-org", + "K6_INFLUXDB_BUCKET": "test-bucket", + "K6_INFLUXDB_TOKEN": "test-token", + "K6_INFLUXDB_INSECURE": "true", + "K6_INFLUXDB_PUSH_INTERVAL": duration999s.String(), + "K6_INFLUXDB_CONCURRENT_WRITES": "999", + "K6_INFLUXDB_PRECISION": duration999s.String(), + "K6_INFLUXDB_TAGS_AS_FIELDS": "test-tag-1,test-tag-2,test-tag-3", + } + + check, err := GetConsolidatedConfig(nil, testdata, "http://test-url-override/test-bucket-override") + assert.NoError(t, err) + + assert.Equal(t, null.StringFrom("http://test-url-override"), check.Addr) + assert.Equal(t, null.StringFrom("test-org"), check.Organization) + assert.Equal(t, null.StringFrom("test-bucket-override"), check.Bucket) + assert.Equal(t, null.StringFrom("test-token"), check.Token) + assert.Equal(t, null.BoolFrom(true), check.InsecureSkipTLSVerify) + assert.Equal(t, types.NullDurationFrom(duration999s), check.PushInterval) + assert.Equal(t, null.IntFrom(999), check.ConcurrentWrites) + assert.Equal(t, types.NullDurationFrom(duration999s), check.Precision) + assert.Equal(t, []string{"test-tag-1", "test-tag-2", "test-tag-3"}, check.TagsAsFields) +}