Skip to content

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.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Bert-R it's the same as for "SearchMessageForm" and "SearchMessageFormForJson" (my comment below)

@Bert-R
Copy link
Collaborator

Bert-R commented Jun 20, 2025

@ndanilin Thanks for the import rearrangement! Any chance you get to addressing the other comments soon?

private MessageFormat keyFormat;
@Schema(type = "string", example = "1970-01-01 03:00:00.000")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
@JsonFormat(shape = JsonFormat.Shape.STRING, 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.

@ndanilin Why this format instead of the regular ISO 8601 format?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Bert-R this format was for "SearchMessageForm" before my changes (ed9d1cd). I decided to do the same thing. Should we change it to ISO 8601?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, please change it to the ISO format. That's a better fit for an API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Bert-R
fixed this moment:

  1. APIs work with iso format (input and output)
  2. UI still works with "yyyy-MM-dd HH:mm:ss.SSS" (haven't dealt with ftlh files before it, so check please)

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ndanilin Sorry, that's not what I meant. My comment only applied to the JSON API. Just this change should suffice:

- @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss.SSS")
+ @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", timezone = "UTC")

Copy link
Contributor Author

@ndanilin ndanilin Jul 11, 2025

Choose a reason for hiding this comment

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

@Bert-R sorry to complicate your idea.

  1. canceled a previous commit
  2. replaced the "searchMessages" API with the POST method (because GET doesn't work with @JSON format)
  3. corrected documentation for "searchMessages"
  4. changed @jsonformat to "SearchMessageFormForJson" and "MessageVO", as you said

@Bert-R
Copy link
Collaborator

Bert-R commented Jul 3, 2025

@ndanilin I done the deduplication that I asked for earlier. Can you have a look to see whether the API still matches your expectations?

@ndanilin
Copy link
Contributor Author

ndanilin commented Jul 6, 2025

@Bert-R I'm really sorry that I forgot to push the second part of my changes about code duplication. Thank you so much for your help.
Yes, the API works fine.

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.

I've corrected the imports and wrapped the lines that were longer than our rules. With that the change is OK.

Thanks for the contribution!

@Bert-R Bert-R merged commit 880d4b0 into obsidiandynamics:master Jul 12, 2025
1 check passed
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