-
Notifications
You must be signed in to change notification settings - Fork 484
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
Support Fixed key #123
Support Fixed key #123
Conversation
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.
Overall looks good.
Cache the key_len on conf and change arg to -k
kafkacat.c
Outdated
@@ -350,6 +351,11 @@ static void producer_run (FILE *fp, char **paths, int pathcnt) { | |||
} | |||
} | |||
|
|||
if (!key && conf.fixed_key) { | |||
key = conf.fixed_key; | |||
key_len = (size_t)(strlen(conf.fixed_key)); |
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.
Cache key_len on conf
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.
Good idea. Will do.
kafkacat.c
Outdated
@@ -936,6 +942,7 @@ static void RD_NORETURN usage (const char *argv0, int exitcode, | |||
" -p -1 Use random partitioner\n" | |||
" -D <delim> Delimiter to split input into messages\n" | |||
" -K <delim> Delimiter to split input key and message\n" | |||
" -F <str> Use a fixed key for all messages\n" |
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.
I think -k
would be more intuitive
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.
Agreed. Funny I didn't think of that alternative.
Addresses #88 (comment). I deemed it safe to assume that operational daemonset pods never co-exist on a node. Tests edenhill/kcat#123, as does 53f355a.
I've been running the build from after my review fixes, and see no regressions. |
Thank you for this! |
I use kafkacat in replicated containers, where a useful key is for example the machine that the particular container runs on, which I can get from environment variables. It makes more sense to set this key value at command invocation, than
sed
ing the piped data.I remember nothing of the C we wrote in school, but I gave this a shot. If you like the idea but - as is likely - not the implementaton or the choice of flag, I'm happy to see a rewrite.
I've built this as solsson/kafkacat-fixedkey and tested it briefly for my usecases, including those with per-message keys from stdin.