Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes linter issues of the output/influxdb #3481

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion output/influxdb/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions output/influxdb/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions output/influxdb/output.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
7 changes: 4 additions & 3 deletions output/influxdb/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions output/influxdb/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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")
Expand Down
8 changes: 7 additions & 1 deletion output/influxdb/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")}),
Expand All @@ -25,6 +29,8 @@ func TestMakeBatchConfig(t *testing.T) {
}

func TestFieldKinds(t *testing.T) {
t.Parallel()

var fieldKinds map[string]FieldKind
var err error

Expand All @@ -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)
Expand Down