-
Notifications
You must be signed in to change notification settings - Fork 24
Add filters to Overview page: Filter by Broker, Time, and Topic #2105
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: main
Are you sure you want to change the base?
Changes from all commits
a7ebaf4
df016a9
77f5e04
b37406d
ec3ea97
a5a393e
f0ecb6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -169,9 +169,10 @@ public CompletionStage<Response> describeConfigs( | |
| @ResourcePrivilege(Privilege.GET) | ||
| public CompletionStage<Response> getNodeMetrics( | ||
| @PathParam("clusterId") String clusterId, | ||
| @PathParam("nodeId") String nodeId) { | ||
| @PathParam("nodeId") String nodeId, | ||
| @QueryParam("duration") @DefaultValue("60") int durationMinutes) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the default be |
||
|
|
||
| return nodeService.getNodeMetrics(nodeId) | ||
| return nodeService.getNodeMetrics(nodeId, durationMinutes) | ||
| .thenApply(metrics -> new NodeMetrics.MetricsResponse(nodeId, metrics)) | ||
| .thenApply(Response::ok) | ||
| .thenApply(Response.ResponseBuilder::build); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -124,15 +124,18 @@ CompletionStage<Map<String, List<Metrics.ValueMetric>>> queryValues(String query | |||||||||
| }); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| CompletionStage<Map<String, List<Metrics.RangeMetric>>> queryRanges(String query) { | ||||||||||
| public CompletionStage<Map<String, List<Metrics.RangeMetric>>> queryRanges(String query, int durationMinutes) { | ||||||||||
| PrometheusAPI prometheusAPI = kafkaContext.prometheus(); | ||||||||||
|
|
||||||||||
| return fetchMetrics( | ||||||||||
| () -> { | ||||||||||
| Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS); | ||||||||||
| Instant start = now.minus(30, ChronoUnit.MINUTES); | ||||||||||
| Instant start = now.minus(durationMinutes, ChronoUnit.MINUTES); | ||||||||||
| Instant end = now; | ||||||||||
| return prometheusAPI.queryRange(query, start, end, "25"); | ||||||||||
|
|
||||||||||
| String step = calculateStep(durationMinutes); | ||||||||||
|
|
||||||||||
| return prometheusAPI.queryRange(query, start, end, step); | ||||||||||
| }, | ||||||||||
| (metric, attributes) -> { | ||||||||||
| List<RangeEntry> values = metric.getJsonArray("values") | ||||||||||
|
|
@@ -148,6 +151,16 @@ CompletionStage<Map<String, List<Metrics.RangeMetric>>> queryRanges(String query | |||||||||
| }); | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
| private String calculateStep(int durationMinutes) { | ||||||||||
| if (durationMinutes <= 15) return "15s"; | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a nit on the style. It's shorter on one line, but it may be best to use the same form for everything.
Suggested change
|
||||||||||
| if (durationMinutes <= 60) return "1m"; | ||||||||||
| if (durationMinutes <= 360) return "5m"; | ||||||||||
| if (durationMinutes <= 1440) return "15m"; | ||||||||||
| if (durationMinutes <= 2880) return "30m"; | ||||||||||
| return "2h"; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| <M> CompletionStage<Map<String, List<M>>> fetchMetrics( | ||||||||||
| Supplier<JsonObject> operation, | ||||||||||
| BiFunction<JsonObject, Map<String, String>, M> builder) { | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -524,7 +524,7 @@ private <M extends Metrics.Metric> void extractNodeMetrics( | |
| }); | ||
| } | ||
|
|
||
| public CompletionStage<Metrics> getNodeMetrics(String nodeId) { | ||
| public CompletionStage<Metrics> getNodeMetrics(String nodeId, int durationMinutes) { | ||
| if (kafkaContext.prometheus() == null) { | ||
| logger.warnf("Metrics requested for node %s, but Prometheus is not configured", nodeId); | ||
| return CompletableFuture.completedStage(new Metrics()); | ||
|
|
@@ -534,38 +534,39 @@ public CompletionStage<Metrics> getNodeMetrics(String nodeId) { | |
| String namespace = clusterConfig.getNamespace(); | ||
| String name = clusterConfig.getName(); | ||
|
|
||
| String rangeQuery; | ||
| String rawRangeQuery; | ||
| String valueQuery; | ||
|
|
||
|
|
||
| try ( | ||
| var rangesStream = getClass().getResourceAsStream("/metrics/queries/kafkaCluster_ranges.promql"); | ||
| var valuesStream = getClass().getResourceAsStream("/metrics/queries/kafkaCluster_values.promql") | ||
| ) { | ||
| rangeQuery = new String(rangesStream.readAllBytes(), StandardCharsets.UTF_8) | ||
| rawRangeQuery = new String(rangesStream.readAllBytes(), StandardCharsets.UTF_8) | ||
| .formatted(namespace, name); | ||
| valueQuery = new String(valuesStream.readAllBytes(), StandardCharsets.UTF_8) | ||
| .formatted(namespace, name); | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException(e); | ||
| } | ||
|
|
||
| Metrics nodeMetrics = new Metrics(); | ||
|
|
||
| String promInterval = "5m"; | ||
| if (durationMinutes >= 1440) promInterval = "30m"; | ||
| if (durationMinutes >= 10080) promInterval = "2h"; | ||
|
|
||
| var rangeFuture = metricsService.queryRanges(rangeQuery).toCompletableFuture(); | ||
| final String finalizedQuery = rawRangeQuery.replace("[5m]", "[" + promInterval + "]"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may be better to use the placeholders in the promql templates and pass the interval to the |
||
|
|
||
| logger.debugf("Executing PromQL: %s", finalizedQuery); | ||
|
|
||
| Metrics nodeMetrics = new Metrics(); | ||
| var rangeFuture = metricsService.queryRanges(finalizedQuery, durationMinutes).toCompletableFuture(); | ||
| var valueFuture = metricsService.queryValues(valueQuery).toCompletableFuture(); | ||
|
|
||
| return CompletableFuture.allOf(rangeFuture, valueFuture) | ||
| .thenApply(nothing -> { | ||
| extractNodeMetrics( | ||
| nodeId, | ||
| rangeFuture.join(), | ||
| nodeMetrics.ranges()); | ||
|
|
||
| extractNodeMetrics( | ||
| nodeId, | ||
| valueFuture.join(), | ||
| nodeMetrics.values()); | ||
|
|
||
| extractNodeMetrics(nodeId, rangeFuture.join(), nodeMetrics.ranges()); | ||
| extractNodeMetrics(nodeId, valueFuture.join(), nodeMetrics.values()); | ||
| return nodeMetrics; | ||
| }); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,15 +58,22 @@ export async function getKafkaCluster( | |
| clusterId: string, | ||
| params?: { | ||
| fields?: string; | ||
| duration?: number; // Optional duration | ||
| }, | ||
| ): Promise<ApiResponse<ClusterDetail>> { | ||
| const queryParams = new URLSearchParams({ | ||
| "fields[kafkas]": | ||
| params?.fields ?? | ||
| "name,namespace,creationTimestamp,status,kafkaVersion,nodes,listeners,metrics,conditions,nodePools,cruiseControlEnabled", | ||
| }); | ||
|
|
||
| if (params?.duration) { | ||
| queryParams.append("duration", params.duration.toString()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be explicit about what the duration is for and to match the other params, what do you think about calling it |
||
| } | ||
|
|
||
| return fetchData( | ||
| `/api/kafkas/${clusterId}`, | ||
| new URLSearchParams({ | ||
| "fields[kafkas]": | ||
| params?.fields ?? | ||
| "name,namespace,creationTimestamp,status,kafkaVersion,nodes,listeners,conditions,nodePools,cruiseControlEnabled", | ||
| }), | ||
| queryParams, | ||
| (rawData: any) => ClusterResponse.parse(rawData).data, | ||
| undefined, | ||
| { | ||
|
|
||
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.
Maybe better to add the
@DefaultValueand make the arg anint, then the null checking can be removed elsewhere.