Skip to content

Commit

Permalink
fix(client): fix auto_flush_interval units in LineSenderFromConf (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
puzpuzpuz authored Jun 29, 2024
1 parent 857a531 commit 7cc3203
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 19 deletions.
4 changes: 2 additions & 2 deletions conf_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func confFromStr(conf string) (*lineSenderConfig, error) {
if err != nil {
return nil, NewInvalidConfigStrError("invalid %s value, %q is not a valid int", k, v)
}
senderConf.autoFlushInterval = time.Duration(parsedVal)
senderConf.autoFlushInterval = time.Duration(parsedVal) * time.Millisecond
case "min_throughput", "init_buf_size", "max_buf_size":
parsedVal, err := strconv.Atoi(v)
if err != nil {
Expand All @@ -138,7 +138,7 @@ func confFromStr(conf string) (*lineSenderConfig, error) {
if err != nil {
return nil, NewInvalidConfigStrError("invalid %s value, %q is not a valid int", k, v)
}
timeoutDur := time.Duration(timeout * int(time.Millisecond))
timeoutDur := time.Duration(timeout) * time.Millisecond

switch k {
case "request_timeout":
Expand Down
4 changes: 2 additions & 2 deletions conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func TestHappyCasesFromConf(t *testing.T) {
qdb.WithHttp(),
qdb.WithAddress(addr),
qdb.WithAutoFlushRows(100),
qdb.WithAutoFlushInterval(1000),
qdb.WithAutoFlushInterval(1000 * time.Millisecond),
},
},
{
Expand All @@ -422,7 +422,7 @@ func TestHappyCasesFromConf(t *testing.T) {
qdb.WithHttp(),
qdb.WithAddress(addr),
qdb.WithAutoFlushRows(0),
qdb.WithAutoFlushInterval(1000),
qdb.WithAutoFlushInterval(1000 * time.Millisecond),
},
},
}
Expand Down
18 changes: 4 additions & 14 deletions http_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,13 +462,8 @@ func TestTimeBasedAutoFlushWithRowBasedFlushDisabled(t *testing.T) {
assert.NoError(t, err)
defer srv.Close()

sender, err := qdb.NewLineSender(
ctx,
qdb.WithHttp(),
qdb.WithAddress(srv.Addr()),
qdb.WithAutoFlushRows(0),
qdb.WithAutoFlushInterval(autoFlushInterval),
)
sender, err := qdb.LineSenderFromConf(ctx,
fmt.Sprintf("http::addr=%s;auto_flush_rows=off;auto_flush_interval=%d;", srv.Addr(), autoFlushInterval.Milliseconds()))
assert.NoError(t, err)
defer sender.Close(ctx)

Expand All @@ -494,13 +489,8 @@ func TestRowBasedAutoFlushWithTimeBasedFlushDisabled(t *testing.T) {
assert.NoError(t, err)
defer srv.Close()

sender, err := qdb.NewLineSender(
ctx,
qdb.WithHttp(),
qdb.WithAddress(srv.Addr()),
qdb.WithAutoFlushRows(autoFlushRows),
qdb.WithAutoFlushInterval(0),
)
sender, err := qdb.LineSenderFromConf(ctx,
fmt.Sprintf("http::addr=%s;auto_flush_rows=%d;auto_flush_interval=off;", srv.Addr(), autoFlushRows))
assert.NoError(t, err)
defer sender.Close(ctx)

Expand Down
2 changes: 1 addition & 1 deletion sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func LineSenderFromEnv(ctx context.Context) (LineSender, error) {
// token: bearer token auth (used instead of basic authentication)
// auto_flush: determines if auto-flushing is enabled (values "on" or "off", defaults to "on")
// auto_flush_rows: auto-flushing is triggered above this row count (defaults to 75000). If set, explicitly implies auto_flush=on. Set to 'off' to disable.
//auto_flush_interval auto-flushing is triggered above this time (defaults to 1000 milliseconds). If set, explicitly implies auto_flush=on. Set to 'off' to disable.
// auto_flush_interval: auto-flushing is triggered above this time, in milliseconds (defaults to 1000 milliseconds). If set, explicitly implies auto_flush=on. Set to 'off' to disable.
// request_min_throughput: bytes per second, used to calculate each request's timeout (defaults to 100KiB/s)
// request_timeout: minimum request timeout in milliseconds (defaults to 10 seconds)
// retry_timeout: cumulative maximum millisecond duration spent in retries (defaults to 10 seconds)
Expand Down

0 comments on commit 7cc3203

Please sign in to comment.