-
Notifications
You must be signed in to change notification settings - Fork 23
Configurable kafka producer parameters #2789
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: development/9.5
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -58,6 +58,7 @@ class BackbeatProducer extends EventEmitter { | |
| maxRequestSize: joi.number().default(KAFKA_PRODUCER_MESSAGE_MAX_BYTES), | ||
| compressionType: joi.string().default(KAFKA_PRODUCER_DEFAULT_COMPRESSION_TYPE), | ||
| requiredAcks: joi.number().default(KAFKA_PRODUCER_DEFAULT_REQUIRED_ACKS), | ||
| producerParams: joi.object().unknown(true).default({}), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, we should define them ? Maybe also factorise them between both (three with kafka params?)?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. discussion ongoing in the other topic |
||
| } | ||
| ); | ||
| } | ||
|
|
@@ -75,7 +76,8 @@ class BackbeatProducer extends EventEmitter { | |
| } | ||
|
|
||
| get producerConfig() { | ||
| const producerParams = { | ||
| const config = { | ||
| ...this._producerParams, | ||
|
DarkIsDude marked this conversation as resolved.
|
||
| 'metadata.broker.list': this._kafkaHosts, | ||
| 'message.max.bytes': this._maxRequestSize, | ||
| 'dr_cb': true, | ||
|
|
@@ -84,10 +86,10 @@ class BackbeatProducer extends EventEmitter { | |
| }; | ||
|
|
||
| if (process.env.RDKAFKA_DEBUG_LOGS) { | ||
| producerParams.debug = process.env.RDKAFKA_DEBUG_LOGS; | ||
| config.debug = process.env.RDKAFKA_DEBUG_LOGS; | ||
| } | ||
|
|
||
| return producerParams; | ||
| return config; | ||
| } | ||
|
|
||
| get topicConfig() { | ||
|
|
@@ -125,13 +127,15 @@ class BackbeatProducer extends EventEmitter { | |
| maxRequestSize, | ||
| compressionType, | ||
| requiredAcks, | ||
| producerParams, | ||
| } = joiResult; | ||
| this._kafkaHosts = kafka.hosts; | ||
| this._topic = topic && withTopicPrefix(topic); | ||
| this._pollIntervalMs = pollIntervalMs; | ||
| this._maxRequestSize = maxRequestSize; | ||
| this._compressionType = compressionType; | ||
| this._requiredAcks = requiredAcks; | ||
| this._producerParams = producerParams; | ||
| } | ||
|
|
||
| connect() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ const joiSchema = joi.object({ | |
| site: joi.string(), | ||
| compressionType: joi.string().default(KAFKA_PRODUCER_DEFAULT_COMPRESSION_TYPE), | ||
| requiredAcks: joi.number().default(KAFKA_PRODUCER_DEFAULT_REQUIRED_ACKS), | ||
| producerParams: joi.object().unknown(true).default({}), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Either forward
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is intentional, the objective is to have config that will later be extensible There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good call from claude, should we define config per producer type or having a global one. What do you mean by
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is we have extensions override the first one when provided. But for now we only have extension for ingestion, and aren't gonna bother doing it for all backbeat extensions. I think its fine as is, but yeah eventually we should update all other backbeat extension to use this global kafka params, else its a bit weird @francoisferrand There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, can you do a follow up ? |
||
| }, | ||
| transport: transportJoi, | ||
| s3: hostPortJoi.optional(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -173,6 +173,10 @@ class IngestionPopulator { | |||||
| maxRequestSize: this.kafkaConfig.maxRequestSize, | ||||||
| compressionType: this.kafkaConfig.compressionType, | ||||||
| requiredAcks: this.kafkaConfig.requiredAcks, | ||||||
| producerParams: { | ||||||
| ...this.kafkaConfig.producerParams, | ||||||
| ...this.ingestionConfig.producerParams, // Extension params override global params | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanna keep this one, i know its more obvious for you but not for me 🧐 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤝 let's go then. You just describe the code but why not |
||||||
| }, | ||||||
| topic, | ||||||
| pollIntervalMs: POLL_INTERVAL_MS, | ||||||
| }); | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,6 +111,39 @@ describe('backbeatProducer', () => { | |
| 'custom-topic', [{ key: 'foo', message: 'bar' }], () => {}); | ||
| }); | ||
|
|
||
| describe('producerParams', () => { | ||
| it('should include extra producerParams in producerConfig', () => { | ||
| const producer = new BackbeatProducer({ | ||
| kafka, | ||
| producerParams: { | ||
| 'queue.buffering.max.kbytes': 1048576, | ||
| 'queue.buffering.max.messages': 200000, | ||
| }, | ||
| }); | ||
| const config = producer.producerConfig; | ||
| assert.strictEqual(config['queue.buffering.max.kbytes'], 1048576); | ||
| assert.strictEqual(config['queue.buffering.max.messages'], 200000); | ||
| }); | ||
|
|
||
| it('should not let producerParams override critical built-in params', () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it be rejected by joi directly by disallow some keys ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's rediscuss after we've finalized joi config, some ongoing discussion on it |
||
| const producer = new BackbeatProducer({ | ||
| kafka, | ||
| producerParams: { | ||
| 'metadata.broker.list': 'attacker:9092', | ||
| 'dr_cb': false, | ||
| }, | ||
| }); | ||
| const config = producer.producerConfig; | ||
| assert.strictEqual(config['metadata.broker.list'], kafka.hosts); | ||
| assert.strictEqual(config['dr_cb'], true); | ||
| }); | ||
|
|
||
| it('should default to empty producerParams when not provided', () => { | ||
| const producer = new BackbeatProducer({ kafka }); | ||
| assert.deepStrictEqual(producer._producerParams, {}); | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| process.env.KAFKA_TOPIC_PREFIX = ''; | ||
| }); | ||
|
|
||
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.
Why should we accept unknown ? Here we don't really define them neither validate them, why ? We should define what is behind object ?
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.
there are dozens of potentials parameters here : https://docs.confluent.io/platform/current/clients/librdkafka/html/md_CONFIGURATION.html
So we went with this to not have to enumerate all, we are only using one or two for now, but wanna be able to use more without having to do another backbeat pr
Honestly debatable though, an ai could write down instantly the ~50 different params available 🤔
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.
@francoisferrand Should we enumerate all params, or enumerate only the ones we use now, or keep it that way.
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.
No enumerate all of them. We use only a few, and we can use only a few. So just them should be enough. The goal of Joi is to validate, here we just skip it. Also we can make sure for example that we don't insert critical one (I remember the host later that is skipped for example).
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.
Rechecked with François, we said the purpose of the ticket is to not bother enumerating all kafka possible options. There is also an associated ticket that we talked about for this sprint which is about using env variables in some kind of "override debugging mode" that will make use of this.
What François was also saying is normally, here, on kafka client creation, if a provided option is wrong, it will be rejected, so we are using librdkafka as some kind of validator (gonna add a test for this though)