Skip to content

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

ndanilin
Copy link
Contributor

Bug fixes:

  1. Removed duplication of messages from viewAllMessages (I think it's a critical bug).
  2. Added filter by timestamp in searchRecords. Search messages by timestamp didn't work because seekToTimestamp can't guarantee needed result.

New features:

  1. Added JSON API getAllMessages (equivalent of viewAllMessages that returns JSON array of messages).
  2. Added JSON API searchMessages (equivalent of searchMessageForm that returns JSON array of messages). Here I made custom SearchMessageFormForJson 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)

Copy link
Collaborator

@Bert-R Bert-R left a 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.*;
Copy link
Collaborator

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.*;
Copy link
Collaborator

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.*;
Copy link
Collaborator

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.*;
Copy link
Collaborator

Choose a reason for hiding this comment

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

And here

Comment on lines +144 to +158
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));
Copy link
Collaborator

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.

Comment on lines +381 to +394
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);
Copy link
Collaborator

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")
Copy link
Collaborator

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?

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.

2 participants