-
Notifications
You must be signed in to change notification settings - Fork 665
Fix deserialization of kafka producer json config in the kafka-reporter-plugin. #542
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
Conversation
|
I think this is duplicated with #540? |
|
#540 hasn't fixed this bug. |
|
Didn't you have fixed? #538 I am confused. |
When the value of a JSON config in Kafka is a non-string type, such as {"batch.size":32768}, an error will be thrown when setting properties with the generated map. But such as {"batch.size":"32768"}, it is ok. |
|
Could you provide more details? I am not familiar with this kind of Kafka configuration. |
Kafka's batch.size configuration refers to the size of messages sent by the producer in one batch, i.e., the batch size. By default, the batch.size is 16KB. If the size of a message is smaller than batch.size, the producer will wait for a certain amount of time to try to aggregate more messages before sending them together, in order to improve producer efficiency. Typically, the batch size can be adjusted based on the size of messages sent by the producer to achieve optimal performance. If the messages are small, the batch size can be decreased, and if the messages are large, the batch size can be increased. However, it should be noted that if the batch size is set too large, it can increase the time it takes for messages to be transmitted over the network and increase the risk of message loss. batch.size is usually configured as a numeric value. |
| @Test | ||
| public void testSetPropertiesFromJsonConfig() { | ||
| KafkaProducerManager kafkaProducerManager = new KafkaProducerManager(); | ||
| Properties properties = new Properties(); | ||
|
|
||
| KafkaReporterPluginConfig.Plugin.Kafka.PRODUCER_CONFIG_JSON = "{\"batch.size\":32768}"; | ||
| kafkaProducerManager.setPropertiesFromJsonConfig(properties); | ||
|
|
||
| assertEquals(properties.get("batch.size"), "32768"); | ||
| } | ||
|
|
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.
What does this UT prove? The codes are not shaded ever in the UT scope, right?
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.
Show an example of how a JSON configuration can be correctly set to properties.
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.
What does this UT prove? The codes are not shaded ever in the UT scope, right?
right.
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.
So, the point of this PR is TypeToken, which cast the type accordingly.
But still import com.google.common.reflect.TypeToken; seems not from gson package. Why?
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.
So, the point of this PR is
TypeToken, which cast the type accordingly.But still
import com.google.common.reflect.TypeToken;seems not from gson package. Why?
I have used the wrong TypeToken out of two.
| <pattern>com.google.gson</pattern> | ||
| <shadedPattern>${shade.package}.com.google.common</shadedPattern> | ||
| </relocation> |
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.
com.google.gson -> com.google.common?
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.
fixed
|
Please fix the conflicts as another PR gets merged. |
Fix
When the value of a JSON config in Kafka is a non-string type, such as {"batch.size":32768}, an error will be thrown when setting properties with the generated map.
Because this code does not deserialize the value of JSON into a String type. However, the value required by Properties is of String type.
CHANGESlog.