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

Fix config related stats for a default writer config #1202

Merged
merged 1 commit into from
Oct 6, 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
14 changes: 7 additions & 7 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -891,13 +891,13 @@ func (w *Writer) Stats() WriterStats {
Retries: stats.retries.snapshot(),
BatchSize: stats.batchSize.snapshot(),
BatchBytes: stats.batchSizeBytes.snapshot(),
MaxAttempts: int64(w.MaxAttempts),
WriteBackoffMin: w.WriteBackoffMin,
WriteBackoffMax: w.WriteBackoffMax,
MaxBatchSize: int64(w.BatchSize),
BatchTimeout: w.BatchTimeout,
ReadTimeout: w.ReadTimeout,
WriteTimeout: w.WriteTimeout,
MaxAttempts: int64(w.maxAttempts()),
WriteBackoffMin: w.writeBackoffMin(),
WriteBackoffMax: w.writeBackoffMax(),
MaxBatchSize: int64(w.batchSize()),
BatchTimeout: w.batchTimeout(),
ReadTimeout: w.readTimeout(),
WriteTimeout: w.writeTimeout(),
RequiredAcks: int64(w.RequiredAcks),
Async: w.Async,
Topic: w.Topic,
Expand Down
86 changes: 86 additions & 0 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ func TestWriter(t *testing.T) {
scenario: "test default configuration values",
function: testWriterDefaults,
},
{
scenario: "test default stats values",
function: testWriterDefaultStats,
},
{
scenario: "test stats values with override config",
function: testWriterOverrideConfigStats,
},
{
scenario: "test write message with writer data",
function: testWriteMessageWithWriterData,
Expand Down Expand Up @@ -944,6 +952,84 @@ func testWriterDefaults(t *testing.T) {
}
}

func testWriterDefaultStats(t *testing.T) {
w := &Writer{}
defer w.Close()

stats := w.Stats()

if stats.MaxAttempts == 0 {
t.Error("Incorrect default MaxAttempts value")
}

if stats.WriteBackoffMin == 0 {
t.Error("Incorrect default WriteBackoffMin value")
}

if stats.WriteBackoffMax == 0 {
t.Error("Incorrect default WriteBackoffMax value")
}

if stats.MaxBatchSize == 0 {
t.Error("Incorrect default MaxBatchSize value")
}

if stats.BatchTimeout == 0 {
t.Error("Incorrect default BatchTimeout value")
}

if stats.ReadTimeout == 0 {
t.Error("Incorrect default ReadTimeout value")
}

if stats.WriteTimeout == 0 {
t.Error("Incorrect default WriteTimeout value")
}
}

func testWriterOverrideConfigStats(t *testing.T) {
w := &Writer{
MaxAttempts: 6,
WriteBackoffMin: 2,
WriteBackoffMax: 4,
BatchSize: 1024,
BatchTimeout: 16,
ReadTimeout: 24,
WriteTimeout: 32,
}
defer w.Close()

stats := w.Stats()

if stats.MaxAttempts != 6 {
t.Error("Incorrect MaxAttempts value")
}

if stats.WriteBackoffMin != 2 {
t.Error("Incorrect WriteBackoffMin value")
}

if stats.WriteBackoffMax != 4 {
t.Error("Incorrect WriteBackoffMax value")
}

if stats.MaxBatchSize != 1024 {
t.Error("Incorrect MaxBatchSize value")
}

if stats.BatchTimeout != 16 {
t.Error("Incorrect BatchTimeout value")
}

if stats.ReadTimeout != 24 {
t.Error("Incorrect ReadTimeout value")
}

if stats.WriteTimeout != 32 {
t.Error("Incorrect WriteTimeout value")
}
}

type staticBalancer struct {
partition int
}
Expand Down