Skip to content

Commit

Permalink
Fix printing of final metrics
Browse files Browse the repository at this point in the history
For short test runs `kafka-producer-performance` may not print any
metrics at all. This is fixed by moving the final call to `printMetrics` just
before closing the producer. Calling `printMetrics` after the producer
is closed does nothing as the producer metrics are unregistered as part
of the close.

Signed-off-by: Adrian Preston <PRESTONA@uk.ibm.com>
  • Loading branch information
prestona authored and dnwe committed Aug 3, 2023
1 parent 1d8f80e commit 4cce955
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tools/kafka-producer-performance/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,6 @@ func main() {

cancel()
<-done

// Print final metrics.
printMetrics(os.Stdout, config.MetricRegistry)
}

func runAsyncProducer(topic string, partition, messageLoad, messageSize int,
Expand All @@ -325,6 +322,8 @@ func runAsyncProducer(topic string, partition, messageLoad, messageSize int,
printErrorAndExit(69, "Failed to create producer: %s", err)
}
defer func() {
// Print final metrics.
printMetrics(os.Stdout, config.MetricRegistry)
if err := producer.Close(); err != nil {
printErrorAndExit(69, "Failed to close producer: %s", err)
}
Expand Down Expand Up @@ -370,6 +369,8 @@ func runSyncProducer(topic string, partition, messageLoad, messageSize, routines
printErrorAndExit(69, "Failed to create producer: %s", err)
}
defer func() {
// Print final metrics.
printMetrics(os.Stdout, config.MetricRegistry)
if err := producer.Close(); err != nil {
printErrorAndExit(69, "Failed to close producer: %s", err)
}
Expand Down

0 comments on commit 4cce955

Please sign in to comment.