github-advanced-security[bot] commented on code in PR #18147:
URL: https://github.com/apache/druid/pull/18147#discussion_r2167107098


##########
quidem-ut/src/test/java/org/apache/druid/simulate/indexing/KafkaIngestSelfMetricsSimTest.java:
##########
@@ -0,0 +1,372 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.simulate.indexing;
+
+import org.apache.druid.data.input.impl.DimensionsSpec;
+import org.apache.druid.data.input.impl.JsonInputFormat;
+import org.apache.druid.data.input.impl.TimestampSpec;
+import org.apache.druid.emitter.kafka.KafkaEmitter;
+import org.apache.druid.emitter.kafka.KafkaEmitterModule;
+import org.apache.druid.indexer.granularity.UniformGranularitySpec;
+import org.apache.druid.indexing.compact.CompactionSupervisorSpec;
+import org.apache.druid.indexing.kafka.KafkaIndexTaskModule;
+import org.apache.druid.indexing.kafka.simulate.EmbeddedKafkaServer;
+import org.apache.druid.indexing.kafka.supervisor.KafkaSupervisorIOConfig;
+import org.apache.druid.indexing.kafka.supervisor.KafkaSupervisorSpec;
+import org.apache.druid.indexing.kafka.supervisor.KafkaSupervisorTuningConfig;
+import org.apache.druid.indexing.overlord.Segments;
+import org.apache.druid.java.util.common.granularity.Granularities;
+import org.apache.druid.query.DruidMetrics;
+import org.apache.druid.rpc.UpdateResponse;
+import org.apache.druid.segment.indexing.DataSchema;
+import org.apache.druid.server.coordinator.ClusterCompactionConfig;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import 
org.apache.druid.server.coordinator.InlineSchemaDataSourceCompactionConfig;
+import org.apache.druid.testing.simulate.EmbeddedBroker;
+import org.apache.druid.testing.simulate.EmbeddedCoordinator;
+import org.apache.druid.testing.simulate.EmbeddedDruidCluster;
+import org.apache.druid.testing.simulate.EmbeddedDruidServer;
+import org.apache.druid.testing.simulate.EmbeddedHistorical;
+import org.apache.druid.testing.simulate.EmbeddedIndexer;
+import org.apache.druid.testing.simulate.EmbeddedOverlord;
+import org.apache.druid.testing.simulate.EmbeddedRouter;
+import org.apache.druid.testing.simulate.emitter.LatchableEmitterModule;
+import org.apache.druid.testing.simulate.junit5.IndexingSimulationTestBase;
+import org.joda.time.Period;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Simulation test to emit cluster metrics using a {@link KafkaEmitter} and 
then
+ * ingest them back into the cluster with a {@code KafkaSupervisor}.
+ */
+public class KafkaIngestSelfMetricsSimTest extends IndexingSimulationTestBase
+{
+  private static final String TOPIC = 
IndexingSimulationTestBase.createTestDatasourceName();
+
+  private final EmbeddedBroker broker = new EmbeddedBroker();
+  private final EmbeddedIndexer indexer = new EmbeddedIndexer();
+  private final EmbeddedOverlord overlord = new EmbeddedOverlord();
+  private final EmbeddedHistorical historical = new EmbeddedHistorical();
+  private final EmbeddedCoordinator coordinator = new EmbeddedCoordinator();
+  private EmbeddedKafkaServer kafkaServer;
+
+  @Override
+  public EmbeddedDruidCluster createCluster()
+  {
+    final EmbeddedDruidCluster cluster = 
EmbeddedDruidCluster.withEmbeddedDerbyAndZookeeper();
+
+    kafkaServer = new EmbeddedKafkaServer(cluster.getZookeeper(), 
cluster.getTestFolder(), Map.of())
+    {
+      @Override
+      public void start() throws IOException
+      {
+        super.start();
+        createTopicWithPartitions(TOPIC, 10);
+        cluster.addCommonProperty("druid.emitter.kafka.bootstrap.servers", 
kafkaServer.getBootstrapServerUrl());
+        cluster.addCommonProperty("druid.emitter.kafka.metric.topic", TOPIC);
+        cluster.addCommonProperty("druid.emitter.kafka.alert.topic", TOPIC);
+      }
+
+      @Override
+      public void stop()
+      {
+        deleteTopic(TOPIC);
+        super.stop();
+      }
+    };
+
+    indexer.addProperty("druid.segment.handoff.pollDuration", "PT0.1s");
+    indexer.addProperty("druid.worker.capacity", "10");
+    overlord.addProperty("druid.indexer.task.default.context", 
"{\"useConcurrentLocks\": true}");
+    overlord.addProperty("druid.manager.segments.useIncrementalCache", 
"ifSynced");
+    overlord.addProperty("druid.manager.segments.pollDuration", "PT0.1s");
+    cluster.addExtension(KafkaIndexTaskModule.class)
+           .addExtension(KafkaEmitterModule.class)
+           .addExtension(LatchableEmitterModule.class)
+           .addExtension(QuickUnusedSegmentKillerModule.class)
+           .addCommonProperty("druid.emitter", "composing")
+           .addCommonProperty("druid.emitter.composing.emitters", 
"[\"latching\",\"kafka\"]")
+           .addCommonProperty("druid.monitoring.emissionPeriod", "PT0.1s")
+           .addCommonProperty("druid.monitoring.monitors", 
"[\"org.apache.druid.java.util.metrics.JvmMonitor\"]")
+           .addResource(kafkaServer)
+           .addServer(coordinator)
+           .addServer(overlord)
+           .addServer(indexer)
+           .addServer(broker)
+           .addServer(historical)
+           .addServer(new EmbeddedRouter());
+
+    return cluster;
+  }
+
+  @Test
+  @Timeout(20)
+  public void test_ingest10kRows_ofSelfClusterMetrics_andVerifyValues()
+  {
+    final int maxRowsPerSegment = 1000;
+    final int expectedSegmentsHandedOff = 10;
+
+    final int taskCount = 5;
+    final int taskDurationMillis = 1_000;
+    final int taskCompletionTimeoutMillis = 10_000;
+
+    // Submit and start a supervisor
+    final String supervisorId = dataSource + "_supe";
+    final KafkaSupervisorSpec kafkaSupervisorSpec = createKafkaSupervisor(
+        supervisorId,
+        taskCount,
+        taskDurationMillis,
+        taskCompletionTimeoutMillis,
+        maxRowsPerSegment
+    );
+
+    final Map<String, String> startSupervisorResult = getResult(
+        cluster.leaderOverlord().postSupervisor(kafkaSupervisorSpec)
+    );
+    Assertions.assertEquals(Map.of("id", supervisorId), startSupervisorResult);
+
+    // Wait for segments to be handed off
+    indexer.latchableEmitter().waitForEventAggregate(
+        event -> event.hasMetricName("ingest/handoff/count")
+                      .hasDimension(DruidMetrics.DATASOURCE, 
List.of(dataSource)),
+        agg -> agg.hasSumAtLeast(expectedSegmentsHandedOff)
+    );
+
+    // Verify number of segments and total number of rows in the datasource
+    final int numSegments = Integer.parseInt(
+        runSql("SELECT COUNT(*) FROM sys.segments WHERE datasource = '%s'", 
dataSource)
+    );
+    Assertions.assertTrue(numSegments >= expectedSegmentsHandedOff);
+
+    final int numRows = Integer.parseInt(
+        runSql("SELECT COUNT(*) FROM %s", dataSource)
+    );
+    Assertions.assertTrue(numRows >= expectedSegmentsHandedOff * 
maxRowsPerSegment);
+
+    verifyIngestedMetricCountMatchesEmittedCount("jvm/pool/committed", 
coordinator);
+    verifyIngestedMetricCountMatchesEmittedCount("coordinator/time", 
coordinator);
+
+    // Suspend the supervisor and verify the state
+    getResult(
+        
cluster.leaderOverlord().postSupervisor(kafkaSupervisorSpec.createSuspendedSpec())
+    );
+    Assertions.assertTrue(getSupervisorStatus(supervisorId).isSuspended());
+  }
+
+  @Test
+  @Timeout(120)
+  public void 
test_ingestClusterMetrics_withConcurrentCompactionSupervisor_andSkipKillOfUnusedSegments()
+  {
+    final int maxRowsPerSegment = 1000;
+    final int compactedMaxRowsPerSegment = 5000;
+
+    final int taskCount = 2;
+    final int taskDurationMillis = 1_000;
+    final int taskCompletionTimeoutMillis = 5_000;
+
+    // Submit and start a supervisor
+    final String supervisorId = dataSource + "_supe";
+    final KafkaSupervisorSpec kafkaSupervisorSpec = createKafkaSupervisor(
+        supervisorId,
+        taskCount,
+        taskDurationMillis,
+        taskCompletionTimeoutMillis,
+        maxRowsPerSegment
+    );
+    getResult(cluster.leaderOverlord().postSupervisor(kafkaSupervisorSpec));
+
+    // Wait for some segments to be published
+    overlord.latchableEmitter().waitForEvent(
+        event -> event.hasMetricName("segment/txn/success")
+                      .hasDimension(DruidMetrics.DATASOURCE, dataSource)
+    );
+
+    // Enable compaction supervisors on the Overlord
+    final ClusterCompactionConfig originalCompactionConfig
+        = getResult(cluster.leaderOverlord().getClusterCompactionConfig());
+
+    final ClusterCompactionConfig updatedCompactionConfig
+        = new ClusterCompactionConfig(1.0, 10, null, true, null);
+    final UpdateResponse updateResponse = getResult(
+        
cluster.leaderOverlord().updateClusterCompactionConfig(updatedCompactionConfig)
+    );
+    Assertions.assertTrue(updateResponse.isSuccess());
+
+    // Submit a compaction supervisor for this datasource
+    final CompactionSupervisorSpec compactionSupervisorSpec = new 
CompactionSupervisorSpec(
+        InlineSchemaDataSourceCompactionConfig
+            .builder()
+            .forDataSource(dataSource)
+            .withSkipOffsetFromLatest(Period.seconds(0))
+            .withMaxRowsPerSegment(compactedMaxRowsPerSegment)

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [Builder.withMaxRowsPerSegment](1) should be avoided because it has 
been deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/9272)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to