From 63cbc7bc08f3ed2bc5513c61fea38527f641a5d9 Mon Sep 17 00:00:00 2001 From: Oleg Bespalov Date: Thu, 30 Nov 2023 16:29:14 +0100 Subject: [PATCH] Fixes linter issues of the output/influxdb --- output/influxdb/bench_test.go | 3 ++- output/influxdb/config.go | 2 ++ output/influxdb/output.go | 4 ++++ output/influxdb/output_test.go | 7 ++++--- output/influxdb/util.go | 2 ++ output/influxdb/util_test.go | 8 +++++++- 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/output/influxdb/bench_test.go b/output/influxdb/bench_test.go index eee1c127c34..54469fae397 100644 --- a/output/influxdb/bench_test.go +++ b/output/influxdb/bench_test.go @@ -29,7 +29,8 @@ func benchmarkInfluxdb(b *testing.B, t time.Duration) { } rw.WriteHeader(http.StatusNoContent) }, func(tb testing.TB, c *Output) { - b = tb.(*testing.B) + b, _ := tb.(*testing.B) + b.ResetTimer() samples := make(metrics.Samples, 10) diff --git a/output/influxdb/config.go b/output/influxdb/config.go index 35a5dc83bd7..2d34a50615e 100644 --- a/output/influxdb/config.go +++ b/output/influxdb/config.go @@ -14,6 +14,7 @@ import ( "go.k6.io/k6/lib/types" ) +// Config represents a k6's influxdb output configuration. type Config struct { // Connection. Addr null.String `json:"addr" envconfig:"K6_INFLUXDB_ADDR"` @@ -54,6 +55,7 @@ func NewConfig() Config { return c } +// Apply applies a valid config options to the receiver. func (c Config) Apply(cfg Config) Config { if cfg.Addr.Valid { c.Addr = cfg.Addr diff --git a/output/influxdb/output.go b/output/influxdb/output.go index 7171dc359a4..75a08009293 100644 --- a/output/influxdb/output.go +++ b/output/influxdb/output.go @@ -1,3 +1,7 @@ +// Package influxdb provides an output plugin for sending results +// directly to InfluxDB v1. +// for the InfluxDB v2 please see an extension +// https://github.com/grafana/xk6-output-influxdb package influxdb import ( diff --git a/output/influxdb/output_test.go b/output/influxdb/output_test.go index 5ab04e7aaf7..5bd2db0bebf 100644 --- a/output/influxdb/output_test.go +++ b/output/influxdb/output_test.go @@ -55,9 +55,10 @@ func TestBadConcurrentWrites(t *testing.T) { func testOutputCycle(t testing.TB, handler http.HandlerFunc, body func(testing.TB, *Output)) { s := &http.Server{ - Addr: ":", - Handler: handler, - MaxHeaderBytes: 1 << 20, + Addr: ":", + Handler: handler, + MaxHeaderBytes: 1 << 20, + ReadHeaderTimeout: time.Second, } l, err := net.Listen("tcp", "127.0.0.1:0") require.NoError(t, err) diff --git a/output/influxdb/util.go b/output/influxdb/util.go index 07be4e918e5..37478182905 100644 --- a/output/influxdb/util.go +++ b/output/influxdb/util.go @@ -10,6 +10,7 @@ import ( "gopkg.in/guregu/null.v3" ) +// MakeClient returns a new InfluxDB client based on the given Config. func MakeClient(conf Config) (client.Client, error) { if strings.HasPrefix(conf.Addr.String, "udp://") { return client.NewUDPClient(client.UDPConfig{ @@ -37,6 +38,7 @@ func MakeClient(conf Config) (client.Client, error) { return client.NewHTTPClient(clientHTTPConfig) } +// MakeBatchConfig returns a new InfluxDB BatchPointsConfig based on the given func MakeBatchConfig(conf Config) client.BatchPointsConfig { if !conf.DB.Valid || conf.DB.String == "" { conf.DB = null.StringFrom("k6") diff --git a/output/influxdb/util_test.go b/output/influxdb/util_test.go index 374daf9806e..a4ca66ccab4 100644 --- a/output/influxdb/util_test.go +++ b/output/influxdb/util_test.go @@ -10,13 +10,17 @@ import ( ) func TestMakeBatchConfig(t *testing.T) { + t.Parallel() + t.Run("Empty", func(t *testing.T) { + t.Parallel() assert.Equal(t, client.BatchPointsConfig{Database: "k6"}, MakeBatchConfig(Config{}), ) }) t.Run("DB Set", func(t *testing.T) { + t.Parallel() assert.Equal(t, client.BatchPointsConfig{Database: "dbname"}, MakeBatchConfig(Config{DB: null.StringFrom("dbname")}), @@ -25,6 +29,8 @@ func TestMakeBatchConfig(t *testing.T) { } func TestFieldKinds(t *testing.T) { + t.Parallel() + var fieldKinds map[string]FieldKind var err error @@ -36,7 +42,7 @@ func TestFieldKinds(t *testing.T) { _, err = MakeFieldKinds(conf) require.Error(t, err) - // Error case 2 (duplicated fields in bool and float ields) + // Error case 2 (duplicated fields in bool and float fields) conf.TagsAsFields = []string{"vu", "iter", "url", "boolField:bool", "boolField:float"} _, err = MakeFieldKinds(conf) require.Error(t, err)