-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Issue 32595 - Kafka Streams Dev UI migration to v2 #36650
Closed
Closed
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0a925e0
First version of Kafka Streams DEV UI portage
dcotfr d205c7b
Kafka Streams DEV UI portage
dcotfr 3244873
Update according to code review
dcotfr ebbb571
Solve invalid text/plain mime type on load
dcotfr 5b01ca7
Merge branch 'quarkusio:main' into issue-32595
dcotfr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...t/src/main/java/io/quarkus/kafka/streams/deployment/devui/KafkaStreamsDevUIProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.quarkus.kafka.streams.deployment.devui; | ||
|
||
import io.quarkus.deployment.IsDevelopment; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.devui.spi.JsonRPCProvidersBuildItem; | ||
import io.quarkus.devui.spi.page.CardPageBuildItem; | ||
import io.quarkus.devui.spi.page.Page; | ||
import io.quarkus.kafka.streams.runtime.devui.KafkaStreamsJsonRPCService; | ||
|
||
public class KafkaStreamsDevUIProcessor { | ||
|
||
@BuildStep(onlyIf = IsDevelopment.class) | ||
public void createPages(BuildProducer<CardPageBuildItem> cardPageProducer) { | ||
|
||
CardPageBuildItem cardPageBuildItem = new CardPageBuildItem(); | ||
|
||
cardPageBuildItem.addPage(Page.webComponentPageBuilder() | ||
.componentLink("qwc-kafka-streams-topology.js") | ||
.title("Topology") | ||
.icon("font-awesome-solid:diagram-project")); | ||
|
||
cardPageProducer.produce(cardPageBuildItem); | ||
} | ||
|
||
@BuildStep(onlyIf = IsDevelopment.class) | ||
public void createJsonRPCService(BuildProducer<JsonRPCProvidersBuildItem> jsonRPCServiceProducer) { | ||
jsonRPCServiceProducer.produce(new JsonRPCProvidersBuildItem(KafkaStreamsJsonRPCService.class)); | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
extensions/kafka-streams/deployment/src/main/resources/dev-ui/qwc-kafka-streams-topology.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { QwcHotReloadElement, html, css } from 'qwc-hot-reload-element'; | ||
import { unsafeHTML } from 'lit/directives/unsafe-html.js'; | ||
import { JsonRpc } from 'jsonrpc'; | ||
|
||
import { Graphviz } from "https://cdn.jsdelivr.net/npm/@hpcc-js/wasm/dist/graphviz.js"; | ||
|
||
import '@vaadin/details'; | ||
import '@vaadin/tabsheet'; | ||
import '@vaadin/tabs'; | ||
import '@vaadin/vertical-layout'; | ||
import 'qui-badge'; | ||
import 'qui-code-block'; | ||
|
||
/** | ||
* This component shows the Kafka Streams Topology | ||
*/ | ||
export class QwcKafkaStreamsTopology extends QwcHotReloadElement { | ||
|
||
jsonRpc = new JsonRpc(this); | ||
|
||
static styles = css` | ||
.codeBlock { | ||
width: 100%; | ||
height: auto; | ||
} | ||
`; | ||
|
||
static properties = { | ||
_topology: {state: true}, | ||
_graphviz: {state: true}, | ||
_tabContent: {state: true} | ||
}; | ||
|
||
constructor() { | ||
super(); | ||
this._topology = null; | ||
this._graphviz = null; | ||
this._tabContent = ''; | ||
} | ||
|
||
connectedCallback() { | ||
super.connectedCallback(); | ||
Graphviz.load().then(r => this._graphviz = r); | ||
this.hotReload() | ||
} | ||
|
||
render() { | ||
if (this._topology) { | ||
return html`<vaadin-tabs @selected-changed="${(e) => this._tabSelectedChanged(e.detail.value)}"> | ||
<vaadin-tab id="graphTab">Graph</vaadin-tab> | ||
<vaadin-tab id="detailsTab">Details</vaadin-tab> | ||
<vaadin-tab id="describeTab">Describe</vaadin-tab> | ||
<vaadin-tab id="graphvizTab">Graphviz</vaadin-tab> | ||
<vaadin-tab id="mermaidTab">Mermaid</vaadin-tab> | ||
</vaadin-tabs> | ||
<vaadin-vertical-layout theme="padding"><p>${this._tabContent}</p></vaadin-vertical-layout>`; | ||
} | ||
|
||
return html`<qwc-no-data message="You do not have any Topology." | ||
link="https://quarkus.io/guides/kafka-streams" | ||
linkText="Learn how to write Kafka Streams"> | ||
</qwc-no-data>`; | ||
} | ||
|
||
hotReload() { | ||
this._topology = null; | ||
this.jsonRpc.getTopology().then(jsonRpcResponse => { | ||
this._topology = jsonRpcResponse.result; | ||
}); | ||
} | ||
|
||
_tabSelectedChanged(n) { | ||
switch(n) { | ||
case 1 : this._selectDetailsTab(); break; | ||
case 2 : this._selectDescribeTab(); break; | ||
case 3 : this._selectGraphvizTab(); break; | ||
case 4 : this._selectMermaidTab(); break; | ||
default : this._selectGraphTab(); | ||
} | ||
} | ||
|
||
_selectGraphTab() { | ||
if (this._graphviz) { | ||
let g = this._graphviz.dot(this._topology.graphviz); | ||
this._tabContent = html`${unsafeHTML(g)}`; | ||
} else { | ||
this._tabContent = html`Graph engine not started.`; | ||
} | ||
} | ||
|
||
_selectDetailsTab() { | ||
this._tabContent = html`<table> | ||
<tr> | ||
<td>Sub-topologies</td><td><qui-badge>${this._topology.subTopologies.length}</qui-badge></td> | ||
<td>${this._topology.subTopologies.map((subTopology) => html`<qui-badge level="contrast" icon="font-awesome-solid:diagram-project" style="margin-right:5px">${subTopology}</qui-badge>`)}</td> | ||
</tr> | ||
<tr> | ||
<td>Sources</td><td><qui-badge>${this._topology.sources.length}</qui-badge></td> | ||
<td>${this._topology.sources.map((source) => html`<qui-badge level="contrast" icon="font-awesome-solid:right-to-bracket" style="margin-right:5px">${source}</qui-badge>`)}</td> | ||
</tr> | ||
<tr> | ||
<td>Sinks</td><td><qui-badge>${this._topology.sinks.length}</qui-badge></td> | ||
<td>${this._topology.sinks.map((sink) => html`<qui-badge level="contrast" icon="font-awesome-solid:right-from-bracket" style="margin-right:5px">${sink}</qui-badge>`)}</td> | ||
</tr> | ||
<tr> | ||
<td>Stores</td><td><qui-badge>${this._topology.stores.length}</qui-badge></td> | ||
<td>${this._topology.stores.map((store) => html`<qui-badge level="contrast" icon="font-awesome-solid:database" style="margin-right:5px">${store}</qui-badge>`)}</td> | ||
</tr> | ||
</table>`; | ||
} | ||
|
||
_selectDescribeTab() { | ||
this._tabContent = html`<qui-code-block mode='text' content='${this._topology.describe}' class="codeBlock"></qui-code-block>`; | ||
} | ||
|
||
_selectGraphvizTab() { | ||
this._tabContent = html`<qui-code-block mode='gv' content='${this._topology.graphviz}' class="codeBlock"></qui-code-block>`; | ||
} | ||
|
||
_selectMermaidTab() { | ||
this._tabContent = html`<qui-code-block mode='mermaid' content='${this._topology.mermaid}' class="codeBlock"></qui-code-block>`; | ||
} | ||
} | ||
customElements.define('qwc-kafka-streams-topology', QwcKafkaStreamsTopology); |
134 changes: 134 additions & 0 deletions
134
...time/src/main/java/io/quarkus/kafka/streams/runtime/devui/KafkaStreamsJsonRPCService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package io.quarkus.kafka.streams.runtime.devui; | ||
|
||
import java.util.Arrays; | ||
import java.util.function.Consumer; | ||
import java.util.function.Predicate; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Stream; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.apache.kafka.streams.Topology; | ||
|
||
import io.smallrye.common.annotation.NonBlocking; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
public class KafkaStreamsJsonRPCService { | ||
@Inject | ||
Topology topology; | ||
|
||
@NonBlocking | ||
public JsonObject getTopology() { | ||
return parseTopologyDescription(topology.describe() != null ? topology.describe().toString() : ""); | ||
} | ||
|
||
JsonObject parseTopologyDescription(String topologyDescription) { | ||
final var res = new JsonObject(); | ||
|
||
final var context = new TopologyParserContext(); | ||
Arrays.stream(topologyDescription.split("\n")) | ||
.map(String::trim) | ||
.forEachOrdered(line -> Stream.of(SUB_TOPOLOGY, SOURCE, PROCESSOR, SINK, RIGHT_ARROW) | ||
.filter(itemParser -> itemParser.test(line)) | ||
.forEachOrdered(itemParser -> itemParser.accept(context))); | ||
|
||
res | ||
.put("describe", topologyDescription) | ||
.put("subTopologies", context.subTopologies) | ||
.put("sources", context.sources) | ||
.put("sinks", context.sinks) | ||
.put("stores", context.stores) | ||
.put("graphviz", context.graphviz.toGraph()) | ||
.put("mermaid", context.mermaid.toGraph()); | ||
|
||
return res; | ||
} | ||
|
||
private interface RawTopologyItemParser extends Predicate<String>, Consumer<TopologyParserContext> { | ||
} | ||
|
||
private static final RawTopologyItemParser SUB_TOPOLOGY = new RawTopologyItemParser() { | ||
private final Pattern subTopologyPattern = Pattern.compile("Sub-topology: (?<subTopology>[0-9]*).*"); | ||
private Matcher matcher; | ||
|
||
@Override | ||
public boolean test(String line) { | ||
matcher = subTopologyPattern.matcher(line); | ||
return matcher.matches(); | ||
} | ||
|
||
@Override | ||
public void accept(TopologyParserContext context) { | ||
context.addSubTopology(matcher.group("subTopology")); | ||
} | ||
}; | ||
|
||
private static final RawTopologyItemParser SOURCE = new RawTopologyItemParser() { | ||
private final Pattern sourcePattern = Pattern | ||
.compile("Source:\\s+(?<source>\\S+)\\s+\\(topics:\\s+\\[(?<topics>.*)\\]\\).*"); | ||
private Matcher matcher; | ||
|
||
@Override | ||
public boolean test(String line) { | ||
matcher = sourcePattern.matcher(line); | ||
return matcher.matches(); | ||
} | ||
|
||
@Override | ||
public void accept(TopologyParserContext context) { | ||
context.addSources(matcher.group("source"), matcher.group("topics").split(",")); | ||
} | ||
}; | ||
|
||
private static final RawTopologyItemParser PROCESSOR = new RawTopologyItemParser() { | ||
private final Pattern processorPattern = Pattern | ||
.compile("Processor:\\s+(?<processor>\\S+)\\s+\\(stores:\\s+\\[(?<stores>.*)\\]\\).*"); | ||
private Matcher matcher; | ||
private String line; | ||
|
||
@Override | ||
public boolean test(String line) { | ||
this.line = line; | ||
matcher = processorPattern.matcher(line); | ||
return matcher.matches(); | ||
} | ||
|
||
@Override | ||
public void accept(TopologyParserContext context) { | ||
context.addStores(matcher.group("stores").split(","), matcher.group("processor"), line.contains("JOIN")); | ||
} | ||
}; | ||
|
||
private static final RawTopologyItemParser SINK = new RawTopologyItemParser() { | ||
private final Pattern sinkPattern = Pattern.compile("Sink:\\s+(?<sink>\\S+)\\s+\\(topic:\\s+(?<topic>.*)\\).*"); | ||
private Matcher matcher; | ||
|
||
@Override | ||
public boolean test(String line) { | ||
matcher = sinkPattern.matcher(line); | ||
return matcher.matches(); | ||
} | ||
|
||
@Override | ||
public void accept(TopologyParserContext context) { | ||
context.addSink(matcher.group("sink"), matcher.group("topic")); | ||
} | ||
}; | ||
|
||
private static final RawTopologyItemParser RIGHT_ARROW = new RawTopologyItemParser() { | ||
private final Pattern rightArrowPattern = Pattern.compile("\\s*-->\\s+(?<targets>.*)"); | ||
private Matcher matcher; | ||
|
||
@Override | ||
public boolean test(String line) { | ||
matcher = rightArrowPattern.matcher(line); | ||
return matcher.matches(); | ||
} | ||
|
||
@Override | ||
public void accept(TopologyParserContext context) { | ||
context.addTargets(matcher.group("targets").split(",")); | ||
} | ||
}; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Here you can use
import { Graphviz } from "@hpcc-js/wasm/graphviz";
and add this to deployment/pom.xml:You can also add above to build parent pom dependency management and reference in the extension pom without the version
This comment was marked as resolved.
Sorry, something went wrong.
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.
Changes done and everything seems Ok when used in sample project.