Skip to content
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

GroupId Link 404 Fix #643

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ kafka.properties*
kafka.truststore.jks*
kafka.keystore.jks*
/.vs
.java-version
7 changes: 5 additions & 2 deletions src/main/java/kafdrop/controller/ConsumerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

@Tag(name = "consumer-controller", description = "Consumer Controller")
@Controller
@RequestMapping("/consumer")
Expand All @@ -44,7 +47,7 @@ public ConsumerController(KafkaMonitor kafkaMonitor) {

@RequestMapping("/{groupId:.+}")
public String consumerDetail(@PathVariable("groupId") String groupId, Model model) throws ConsumerNotFoundException {
final var consumer = kafkaMonitor.getConsumersByGroup(groupId).stream().findAny();
final var consumer = kafkaMonitor.getConsumersByGroup(new String(Base64.getDecoder().decode(groupId), StandardCharsets.UTF_8)).stream().findAny();

model.addAttribute("consumer", consumer.orElseThrow(() -> new ConsumerNotFoundException(groupId)));
return "consumer-detail";
Expand All @@ -58,7 +61,7 @@ public String consumerDetail(@PathVariable("groupId") String groupId, Model mode
@GetMapping(path = "/{groupId:.+}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody ConsumerVO getConsumer(@PathVariable("groupId") String groupId)
throws ConsumerNotFoundException {
final var consumer = kafkaMonitor.getConsumersByGroup(groupId).stream().findAny();
final var consumer = kafkaMonitor.getConsumersByGroup(new String(Base64.getDecoder().decode(groupId), StandardCharsets.UTF_8)).stream().findAny();

return consumer.orElseThrow(() -> new ConsumerNotFoundException(groupId));
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/kafdrop/model/ConsumerVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,33 @@

import org.apache.commons.lang3.Validate;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;

public final class ConsumerVO implements Comparable<ConsumerVO> {
private final String groupId;

private final String groupIdBase64;
private final Map<String, ConsumerTopicVO> topics = new TreeMap<>();

public ConsumerVO(String groupId) {
Validate.notEmpty("groupId is required");
this.groupId = groupId;
this.groupIdBase64 = new String (Base64.getEncoder().encode(groupId.getBytes(StandardCharsets.UTF_8)));
}

public String getGroupId() {
return groupId;
}

public String getGroupIdBase64() {
return groupIdBase64;
}

public void addTopic(ConsumerTopicVO topic) {
topics.put(topic.getTopic(), topic);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/topic-detail.ftlh
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
<tbody>
<#list consumers![] as c>
<tr>
<td><a href="<@spring.url '/consumer/${c.groupId}'/>">${c.groupId}</a></td>
<td><a href="<@spring.url '/consumer/${c.groupIdBase64}'/>">${c.groupId}</a></td>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of using a base64 encoding, why not just url encode it? In this way it should be handled automatically by spring I suppose. Probably you can use UriComponentsBuilder. In this way you don't need to change src/main/java/kafdrop/controller/ConsumerController.java.

Copy link
Author

Choose a reason for hiding this comment

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

I tried that way as well, however spring.url was again converting it to decoded value, which was ending up with error when you click on consumer group link.

<td>${c.getTopic(topic.name).lag}</td>
</tr>
</#list>
Expand Down