iliax 1 年之前
父节点
当前提交
4bd70b7952

+ 0 - 1
kafka-ui-api/src/main/java/com/provectus/kafka/ui/config/auth/AbstractAuthSecurityConfig.java

@@ -18,7 +18,6 @@ abstract class AbstractAuthSecurityConfig {
       "/logout",
       "/oauth2/**",
       "/static/**",
-      "/api/clusters/**/prometheus/expose/**",
       "/metrics"
   };
 

+ 0 - 28
kafka-ui-api/src/main/java/com/provectus/kafka/ui/controller/PrometheusExposeController.java

@@ -29,32 +29,4 @@ public class PrometheusExposeController extends AbstractController implements Pr
     );
   }
 
-  @Override
-  public Mono<ResponseEntity<String>> getAllClusterMetrics(String clusterName, ServerWebExchange exchange) {
-    var cluster = getCluster(clusterName);
-    if (!cluster.isExposeMetricsViaPrometheusEndpoint()) {
-      return Mono.empty();
-    }
-    return Mono.just(
-        PrometheusExpose.exposeClusterMetrics(
-            statisticsCache.get(cluster).getMetrics()
-        )
-    );
-  }
-
-  @Override
-  public Mono<ResponseEntity<String>> getBrokerMetrics(String clusterName,
-                                                       Long brokerId,
-                                                       ServerWebExchange exchange) {
-    var cluster = getCluster(clusterName);
-    if (!cluster.isExposeMetricsViaPrometheusEndpoint()) {
-      return Mono.empty();
-    }
-    return Mono.just(
-        PrometheusExpose.exposeBrokerMetrics(
-            statisticsCache.get(cluster).getMetrics(), brokerId.intValue()
-        )
-    );
-  }
-
 }

+ 1 - 1
kafka-ui-api/src/main/java/com/provectus/kafka/ui/service/KafkaClusterFactory.java

@@ -139,7 +139,7 @@ public class KafkaClusterFactory {
 
   private boolean exposeMetricsViaPrometheusEndpoint(ClustersProperties.Cluster clusterProperties) {
     return Optional.ofNullable(clusterProperties.getMetrics())
-        .map(m -> Boolean.TRUE.equals(m.getPrometheusExpose()))
+        .map(m -> m.getPrometheusExpose() == null || m.getPrometheusExpose())
         .orElse(true);
   }
 

+ 2 - 0
kafka-ui-api/src/main/java/com/provectus/kafka/ui/service/graphs/GraphDescriptions.java

@@ -71,6 +71,8 @@ class GraphDescriptions {
           .prometheusQuery("kafka_topic_partition_current_offset{cluster=\"${cluster}\",topic = \"${topic}\"}")
           .params(Set.of("topic"))
           .build()
+
+      //TODO: add
   );
 
 }

+ 13 - 20
kafka-ui-api/src/main/java/com/provectus/kafka/ui/service/metrics/prometheus/PrometheusExpose.java

@@ -1,6 +1,8 @@
 package com.provectus.kafka.ui.service.metrics.prometheus;
 
 import static io.prometheus.client.Collector.MetricFamilySamples;
+import static io.prometheus.client.exporter.common.TextFormat.CONTENT_TYPE_OPENMETRICS_100;
+import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.Iterators;
@@ -19,27 +21,21 @@ import org.springframework.http.ResponseEntity;
 
 public final class PrometheusExpose {
 
-  private static final String CLUSTER_SELECTION_EXPOSE_LBL_NAME = "cluster";
+  private static final String CLUSTER_EXPOSE_LBL_NAME = "cluster";
 
-  private PrometheusExpose() {
-  }
+  private static final HttpHeaders PROMETHEUS_EXPOSE_ENDPOINT_HEADERS;
 
-  public static ResponseEntity<String> exposeAllMetrics(Map<String, Metrics> clustersMetrics) {
-    return constructHttpsResponse(getMetricsForGlobalExpose(clustersMetrics));
+  static {
+    PROMETHEUS_EXPOSE_ENDPOINT_HEADERS = new HttpHeaders();
+    PROMETHEUS_EXPOSE_ENDPOINT_HEADERS.set(CONTENT_TYPE, CONTENT_TYPE_OPENMETRICS_100);
   }
 
-  public static ResponseEntity<String> exposeClusterMetrics(Metrics clusterMetrics) {
-    return constructHttpsResponse(clusterMetrics.getSummarizedMetrics());
+  private PrometheusExpose() {
   }
 
-  public static ResponseEntity<String> exposeBrokerMetrics(Metrics clusterMetrics, int brokerId) {
-    //TODO: discuss - do we need to append broker_id lbl ?
-    return constructHttpsResponse(
-        clusterMetrics
-            .getPerBrokerScrapedMetrics()
-            .getOrDefault(brokerId, List.of())
-            .stream()
-    );
+  public static ResponseEntity<String> exposeAllMetrics(Map<String, Metrics> clustersMetrics) {
+    System.out.println("Exposing metrics:" + clustersMetrics);
+    return constructHttpsResponse(getMetricsForGlobalExpose(clustersMetrics));
   }
 
   private static Stream<MetricFamilySamples> getMetricsForGlobalExpose(Map<String, Metrics> clustersMetrics) {
@@ -56,7 +52,7 @@ public final class PrometheusExpose {
   public static Stream<MetricFamilySamples> prepareMetricsForGlobalExpose(String clusterName, Metrics metrics) {
     return metrics
         .getSummarizedMetrics()
-        .map(mfs -> addLbl(mfs, CLUSTER_SELECTION_EXPOSE_LBL_NAME, clusterName));
+        .map(mfs -> addLbl(mfs, CLUSTER_EXPOSE_LBL_NAME, clusterName));
   }
 
   private static MetricFamilySamples concatSamples(MetricFamilySamples mfs1,
@@ -93,12 +89,9 @@ public final class PrometheusExpose {
   public static ResponseEntity<String> constructHttpsResponse(Stream<MetricFamilySamples> metrics) {
     StringWriter writer = new StringWriter();
     TextFormat.writeOpenMetrics100(writer, Iterators.asEnumeration(metrics.iterator()));
-
-    HttpHeaders responseHeaders = new HttpHeaders();
-    responseHeaders.set(HttpHeaders.CONTENT_TYPE, TextFormat.CONTENT_TYPE_OPENMETRICS_100);
     return ResponseEntity
         .ok()
-        .headers(responseHeaders)
+        .headers(PROMETHEUS_EXPOSE_ENDPOINT_HEADERS)
         .body(writer.toString());
   }
 

+ 0 - 46
kafka-ui-contract/src/main/resources/swagger/kafka-ui-api.yaml

@@ -217,52 +217,6 @@ paths:
               schema:
                 type: string
 
-  /api/clusters/{clusterName}/prometheus/expose/all:
-    get:
-      tags:
-        - PrometheusExpose
-      summary: getAllClusterMetrics
-      operationId: getAllClusterMetrics
-      parameters:
-        - name: clusterName
-          in: path
-          required: true
-          schema:
-            type: string
-      responses:
-        200:
-          description: OK
-          content:
-            application/text:
-              schema:
-                type: string
-
-  /api/clusters/{clusterName}/prometheus/expose/broker/{brokerId}:
-    get:
-      tags:
-        - PrometheusExpose
-      summary: getBrokerMetrics
-      operationId: getBrokerMetrics
-      parameters:
-        - name: clusterName
-          in: path
-          required: true
-          schema:
-            type: string
-        - name: brokerId
-          in: path
-          required: true
-          schema:
-            type: integer
-            format: int64
-      responses:
-        200:
-          description: OK
-          content:
-            application/text:
-              schema:
-                type: string
-
   /api/clusters/{clusterName}/stats:
     get:
       tags: