Prechádzať zdrojové kódy

Minor backend fixes (#2696)

Minor backend fixes:
1. InternalTopic.leader fiels filling fix
2. bytesIn/OutPerSec fields set to TopicDTO
3. "subject" property added to SR SchemaDescription
Ilya Kuramshin 2 rokov pred
rodič
commit
b19b9d82e9

+ 6 - 3
kafka-ui-api/src/main/java/com/provectus/kafka/ui/model/InternalTopic.java

@@ -57,9 +57,12 @@ public class InternalTopic {
           partitionDto.inSyncReplicasCount(partition.isr().size());
           partitionDto.replicasCount(partition.replicas().size());
           List<InternalReplica> replicas = partition.replicas().stream()
-              .map(r -> new InternalReplica(r.id(),
-                  partition.leader() != null && partition.leader().id() != r.id(),
-                  partition.isr().contains(r)))
+              .map(r ->
+                  InternalReplica.builder()
+                    .broker(r.id())
+                    .inSync(partition.isr().contains(r))
+                    .leader(partition.leader() != null && partition.leader().id() == r.id())
+                    .build())
               .collect(Collectors.toList());
           partitionDto.replicas(replicas);
 

+ 1 - 0
kafka-ui-api/src/main/java/com/provectus/kafka/ui/serdes/builtin/sr/SchemaRegistrySerde.java

@@ -142,6 +142,7 @@ public class SchemaRegistrySerde implements BuiltInSerde {
             new SchemaDescription(
                 convertSchema(schemaMetadata),
                 Map.of(
+                    "subject", subject,
                     "schemaId", schemaMetadata.getId(),
                     "latestVersion", schemaMetadata.getVersion(),
                     "type", schemaMetadata.getSchemaType() // AVRO / PROTOBUF / JSON

+ 22 - 13
kafka-ui-api/src/test/java/com/provectus/kafka/ui/serdes/builtin/sr/SchemaRegistrySerdeTest.java

@@ -23,6 +23,8 @@ import org.apache.avro.io.Encoder;
 import org.apache.avro.io.EncoderFactory;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
 
 class SchemaRegistrySerdeTest {
 
@@ -36,21 +38,28 @@ class SchemaRegistrySerdeTest {
     serde.configure(List.of("wontbeused"), registryClient, "%s-key", "%s-value");
   }
 
-  @Test
-  void returnsSchemaDescriptionIfSchemaRegisteredInSR() throws RestClientException, IOException {
-    String topic = "test";
-    registryClient.register(topic + "-key", new AvroSchema("{ \"type\": \"int\" }"));
-    registryClient.register(topic + "-value", new AvroSchema("{ \"type\": \"float\" }"));
+  @ParameterizedTest
+  @CsvSource({
+      "test_topic, test_topic-key, KEY",
+      "test_topic, test_topic-value, VALUE"
+  })
+  @SneakyThrows
+  void returnsSchemaDescriptionIfSchemaRegisteredInSR(String topic, String subject, Serde.Target target) {
+    int schemaId = registryClient.register(subject, new AvroSchema("{ \"type\": \"int\" }"));
+    int registeredVersion = registryClient.getLatestSchemaMetadata(subject).getVersion();
 
-    var keySchemaOptional = serde.getSchema(topic, Serde.Target.KEY);
-    assertThat(keySchemaOptional)
-        .map(SchemaDescription::getSchema)
-        .contains("{\"$id\":\"int\",\"$schema\":\"https://json-schema.org/draft/2020-12/schema\",\"type\":\"integer\"}");
+    var schemaOptional = serde.getSchema(topic, target);
+    assertThat(schemaOptional).isPresent();
 
-    var valueSchemaOptional = serde.getSchema(topic, Serde.Target.VALUE);
-    assertThat(valueSchemaOptional)
-        .map(SchemaDescription::getSchema)
-        .contains("{\"$id\":\"float\",\"$schema\":\"https://json-schema.org/draft/2020-12/schema\",\"type\":\"number\"}");
+    SchemaDescription schemaDescription = schemaOptional.get();
+    assertThat(schemaDescription.getSchema())
+        .contains("{\"$id\":\"int\",\"$schema\":\"https://json-schema.org/draft/2020-12/schema\",\"type\":\"integer\"}");
+    assertThat(schemaDescription.getAdditionalProperties())
+        .containsOnlyKeys("subject", "schemaId", "latestVersion", "type")
+        .containsEntry("subject", subject)
+        .containsEntry("schemaId", schemaId)
+        .containsEntry("latestVersion", registeredVersion)
+        .containsEntry("type", "AVRO");
   }
 
   @Test

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

@@ -2035,6 +2035,10 @@ components:
           format: int64
         segmentCount:
           type: integer
+        bytesInPerSec:
+          type: number
+        bytesOutPerSec:
+          type: number
         underReplicatedPartitions:
           type: integer
         cleanUpPolicy: