-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add Duration-Based Testing and Enhanced TLS Logging #5228
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
base: master
Are you sure you want to change the base?
Changes from all commits
6114915
3407148
3235e05
ac232f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -76,6 +76,7 @@ static int partition_cnt = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| static int eof_cnt = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| static int with_dr = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| static int read_hdrs = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| static int test_duration = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| static void stop(int sig) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -84,6 +85,21 @@ static void stop(int sig) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| run = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @brief Logger callback to capture and display TLS version information | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| static void | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger_cb(const rd_kafka_t *rk, int level, const char *fac, const char *buf) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* Display TLS connection info */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (strstr(fac, "SSLVERIFY") && strstr(buf, "TLS version:")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| fprintf(stderr, "\n[INFO] TLS Connection Established: %s\n\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| buf); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* Print warnings and errors to stderr */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| fprintf(stderr, "%%%d|%s|%s: %s\n", level, rd_kafka_name(rk), fac, buf); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| static long int msgs_wait_cnt = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| static long int msgs_wait_produce_cnt = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| static rd_ts_t t_end; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -594,6 +610,22 @@ print_stats(rd_kafka_t *rk, int mode, int otype, const char *compression) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (otype & _OTYPE_SUMMARY) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* Add time remaining for duration-based tests */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (test_duration > 0 && cnt.t_start > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| rd_ts_t elapsed_us = now - cnt.t_start; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| rd_ts_t duration_us = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| (rd_ts_t)test_duration * 1000 * 1000; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (elapsed_us < duration_us) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| int remaining_secs = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| (int)((duration_us - elapsed_us) / | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000000); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| extra_of += rd_snprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| extra + extra_of, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| sizeof(extra) - extra_of, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ", %ds remaining", remaining_secs); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| printf("%% %" PRIu64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| " messages produced " | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "(%" PRIu64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -607,13 +639,13 @@ print_stats(rd_kafka_t *rk, int mode, int otype, const char *compression) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| "%.02f MB/s, " | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "%" PRIu64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| " produce failures, %i in queue, " | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "%s compression\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "%s compression%s\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| cnt.msgs, cnt.bytes, cnt.msgs_dr_ok, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| cnt.last_offset, cnt.msgs_dr_err, t_total / 1000, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ((cnt.msgs_dr_ok * 1000000) / t_total), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| (float)((cnt.bytes_dr_ok) / (float)t_total), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| cnt.tx_err, rk ? rd_kafka_outq_len(rk) : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| compression); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| compression, extra); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -894,7 +926,7 @@ int main(int argc, char **argv) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| while ((opt = getopt(argc, argv, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "PCG:t:p:b:s:k:c:fi:MDd:m:S:x:" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "R:a:z:o:X:B:eT:Y:qvIur:lA:OwNH:")) != -1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "R:a:z:o:X:B:eT:Y:qvIur:lA:OwNH:E:")) != -1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch (opt) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| case 'G': | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (rd_kafka_conf_set(conf, "group.id", optarg, errstr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1118,12 +1150,32 @@ int main(int argc, char **argv) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| with_dr = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| case 'E': | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| test_duration = atoi(optarg); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (test_duration <= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| fprintf(stderr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "%% Invalid test duration: %s " | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "(must be > 0)\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| optarg); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1153
to
+1162
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| case 'E': | |
| test_duration = atoi(optarg); | |
| if (test_duration <= 0) { | |
| fprintf(stderr, | |
| "%% Invalid test duration: %s " | |
| "(must be > 0)\n", | |
| optarg); | |
| exit(1); | |
| } | |
| break; | |
| case 'E': { | |
| char *endptr = NULL; | |
| long val; | |
| errno = 0; | |
| val = strtol(optarg, &endptr, 10); | |
| if (errno == ERANGE || val > INT_MAX || val <= 0 || endptr == optarg || *endptr != '\0') { | |
| fprintf(stderr, | |
| "%% Invalid test duration: %s " | |
| "(must be a positive integer)\n", | |
| optarg); | |
| exit(1); | |
| } | |
| test_duration = (int)val; | |
| break; | |
| } |
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The 5-second flush timeout is hardcoded with no explanation of why this specific duration was chosen. Consider documenting the rationale for this timeout value or making it configurable, especially since duration-based tests might involve different message volumes that could require different flush timeouts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logger callback always prints all log messages to stderr, which will produce excessive output. This should be conditional based on log level or verbosity settings to avoid flooding the console with debug messages. Consider adding a level check (e.g.,
if (level <= LOG_WARNING)) or respecting the global verbosity setting.