-
Notifications
You must be signed in to change notification settings - Fork 873
JSON APIs and bug fixes #717
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?
Conversation
…ges (json api for viewAllMessages)
…lh) 2. sorted messages in searchMessages
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.
@ndanilin Thank you for this PR and sorry for the long delay in reviewing it.
It generally looks good. I have added a few comments regarding imports and code duplication. After these are resolved, the PR can be merged. Then we'll bring a release of Kafdrop.
import kafdrop.model.TopicPartitionVO; | ||
import kafdrop.model.TopicVO; | ||
import kafdrop.form.SearchMessageFormForJson; | ||
import kafdrop.model.*; |
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.
In our coding convention, we don't use wildcard imports. Please restore the original specific imports.
|
||
|
||
import kafdrop.util.Serializers; | ||
import kafdrop.util.*; |
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.
Same here
import org.springframework.web.bind.annotation.PostMapping; | ||
import kafdrop.model.CreateMessageVO; | ||
import java.io.File; | ||
import java.util.*; |
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.
And here
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.web.bind.annotation.*; |
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.
And here
final var deserializers = new Deserializers( | ||
getDeserializer(topicName, defaultKeyFormat, "", "", protobufProperties.getParseAnyProto()), | ||
getDeserializer(topicName, defaultFormat, "", "", protobufProperties.getParseAnyProto())); | ||
|
||
final List<MessageVO> messages = new ArrayList<>(); | ||
|
||
for (TopicPartitionVO partition : topic.getPartitions()) { | ||
messages.addAll(messageInspector.getMessages(topicName, | ||
partition.getId(), | ||
partition.getFirstOffset(), | ||
size, | ||
deserializers)); | ||
} | ||
|
||
messages.sort(Comparator.comparing(MessageVO::getTimestamp)); |
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.
This duplicates the lines 102-116 of viewAllMessages
. Extract these into a private method and call that method here instead of duplicating them.
final var deserializers = new Deserializers( | ||
getDeserializer(topicName, searchMessageForm.getKeyFormat(), null, null, | ||
protobufProperties.getParseAnyProto()), | ||
getDeserializer(topicName, searchMessageForm.getFormat(), null, null, | ||
protobufProperties.getParseAnyProto()) | ||
); | ||
|
||
var searchResultsVO = kafkaMonitor.searchMessages( | ||
topicName, | ||
searchMessageForm.getSearchText(), | ||
searchMessageForm.getPartition(), | ||
searchMessageForm.getMaximumCount(), | ||
searchMessageForm.getStartTimestamp(), | ||
deserializers); |
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.
These lines duplicate the lines 325-339 of searchMessageForm
, except that descFile
and msgTypeName
are set to null
. Extract the lines into a method that takes descFile
and msgTypeName
as parameters and call the method here and above.
@@ -28,6 +30,7 @@ public final class MessageVO { | |||
private String message; | |||
private String key; | |||
private Map<String, String> headers; | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") |
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 this format instead of ISO 8601?
Bug fixes:
viewAllMessages
(I think it's a critical bug).searchRecords
. Search messages by timestamp didn't work becauseseekToTimestamp
can't guarantee needed result.New features:
getAllMessages
(equivalent ofviewAllMessages
that returns JSON array of messages).searchMessages
(equivalent ofsearchMessageForm
that returns JSON array of messages). Here I made customSearchMessageFormForJson
and now all fields of form are not required. Also added here search by keys (It might overload this method, but seems very helpful for guaranteed results)