Skip to content

KAFKA-10525: Emit JSONs with new auto-generated schema#9526

Merged
dajac merged 22 commits intoapache:trunkfrom
anatasiavela:KAFKA-10525
Dec 15, 2020
Merged

KAFKA-10525: Emit JSONs with new auto-generated schema#9526
dajac merged 22 commits intoapache:trunkfrom
anatasiavela:KAFKA-10525

Conversation

@anatasiavela
Copy link
Copy Markdown
Contributor

@anatasiavela anatasiavela commented Oct 29, 2020

Kafka’s request and response traces currently output in a format that is JSON-like and are not easily parsable. There is a new auto-generated schema for each request type that supports outputting JSON payloads for request and response payloads. These can be adapted to provide structured request tracing.

Includes tests that iterate through all the request types and ensure we handle all of them in RequestConvertToJson.

KIP-673

Copy link
Copy Markdown
Member

@dajac dajac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anatasiavela Thanks for the PR. Overall, the PR looks good. I have left some comments/questions.

Comment thread core/src/main/scala/kafka/network/RequestChannel.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread core/src/test/scala/unit/kafka/network/RequestConvertToJsonTest.scala Outdated
Comment thread core/src/test/scala/unit/kafka/network/RequestConvertToJsonTest.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread core/src/main/scala/kafka/server/KafkaApis.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread core/src/test/scala/unit/kafka/network/RequestConvertToJsonTest.scala Outdated
Comment thread core/src/test/scala/unit/kafka/network/RequestConvertToJsonTest.scala Outdated
Copy link
Copy Markdown
Member

@dajac dajac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anatasiavela Thanks for the update. I have left few more comments.

Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread generator/src/main/java/org/apache/kafka/message/JsonConverterGenerator.java Outdated
Copy link
Copy Markdown
Member

@dajac dajac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anatasiavela Thanks for the update! It looks pretty good now. There are few things to fix and to improve but I think that we are on the right track wrt. the overall approach. I have left some more comments.

Comment thread clients/src/main/java/org/apache/kafka/common/requests/ProduceRequest.java Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread core/src/test/scala/unit/kafka/network/RequestConvertToJsonTest.scala Outdated
Comment thread generator/src/main/java/org/apache/kafka/message/JsonConverterGenerator.java Outdated
Comment thread generator/src/main/java/org/apache/kafka/message/JsonConverterGenerator.java Outdated
Comment thread core/src/main/scala/kafka/server/KafkaApis.scala Outdated
Comment thread core/src/main/scala/kafka/server/KafkaApis.scala Outdated
Comment thread core/src/main/scala/kafka/tools/TestRaftRequestHandler.scala Outdated
Copy link
Copy Markdown
Member

@dajac dajac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anatasiavela Thanks for the update. The PR looks good overall. I have left minor suggestions and one question.

Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread core/src/main/scala/kafka/tools/TestRaftRequestHandler.scala Outdated
Comment thread core/src/test/scala/unit/kafka/network/RequestConvertToJsonTest.scala Outdated
Comment thread core/src/test/scala/unit/kafka/network/RequestConvertToJsonTest.scala Outdated
Comment thread core/src/test/scala/unit/kafka/network/RequestConvertToJsonTest.scala Outdated
Comment thread generator/src/main/java/org/apache/kafka/message/JsonConverterGenerator.java Outdated
Comment thread core/src/test/scala/unit/kafka/network/RequestConvertToJsonTest.scala Outdated
Comment thread core/src/test/scala/unit/kafka/network/RequestConvertToJsonTest.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
@dajac
Copy link
Copy Markdown
Member

dajac commented Nov 19, 2020

@anatasiavela Both PRs have been merged so we can proceed with this one.

There is something that we must consider that I was not aware of: https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/common/requests/ProduceRequest.java#L235. When the ProduceRequest is processed in the KafkaApis layer, its internal data is set to null to free up the memory. That means that we won't have it to log the request. We need to take this into account.

Copy link
Copy Markdown
Member

@dajac dajac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anatasiavela Thanks for the updates. I think that we are very close. I have left few small comments and suggestions. Could you also rebase the PR please?

Comment thread core/src/main/scala/kafka/network/RequestChannel.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestChannel.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should name the field %sSizeInBytes. I just looked at the result and having "records":83 in the request log is not super clear to me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do see the issue of it not being super clear, but I don't think we can change the field name from here. Doing %sSizeInBytes would just add the name at the end of the line which would result in a compilation error. Unless you mean to change the field name in the .json file, but it would change the name for both the serialize and non-serialize case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would something like the following work?

buffer.printf("_node.set(\"%sSizeInBytes\", new IntNode(%s.sizeInBytes()));%n",
  target.field().camelCaseName(),
  target.sourceVariable());

Copy link
Copy Markdown
Member

@dajac dajac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anatasiavela Thanks for the updates. The PR looks pretty good. I have left few more minor comments.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would something like the following work?

buffer.printf("_node.set(\"%sSizeInBytes\", new IntNode(%s.sizeInBytes()));%n",
  target.field().camelCaseName(),
  target.sourceVariable());

Comment thread core/src/main/scala/kafka/server/KafkaApis.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestChannel.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestChannel.scala Outdated
Comment thread core/src/main/scala/kafka/network/RequestConvertToJson.scala Outdated
Comment thread core/src/main/scala/kafka/server/KafkaApis.scala Outdated
Comment thread core/src/main/scala/kafka/tools/TestRaftRequestHandler.scala Outdated
Copy link
Copy Markdown
Member

@dajac dajac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for your contribution, @anatasiavela!

@dajac dajac merged commit 1a10c34 into apache:trunk Dec 15, 2020
ijuma added a commit to ijuma/kafka that referenced this pull request Dec 15, 2020
…keys

* apache-github/trunk:
  KAFKA-10776: Add version attribute in RequestsPerSec metrics documentation (apache#9661)
  KAFKA-10854: fix flaky testConnectionRatePerIp test (apache#9752)
  KAFKA-10525: Emit JSONs with new auto-generated schema (KIP-673) (apache#9526)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants