github-advanced-security[bot] commented on code in PR #18302: URL: https://github.com/apache/druid/pull/18302#discussion_r2243421277
########## embedded-tests/src/test/java/org/apache/druid/testing/embedded/docker/IngestionDockerTest.java: ########## @@ -0,0 +1,369 @@ +/* + * 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.testing.embedded.docker; + +import com.google.common.collect.ImmutableList; +import org.apache.druid.common.utils.IdUtils; +import org.apache.druid.data.input.impl.CsvInputFormat; +import org.apache.druid.data.input.impl.DimensionsSpec; +import org.apache.druid.data.input.impl.TimestampSpec; +import org.apache.druid.indexer.TaskState; +import org.apache.druid.indexer.TaskStatusPlus; +import org.apache.druid.indexing.common.task.IndexTask; +import org.apache.druid.indexing.common.task.TaskBuilder; +import org.apache.druid.indexing.common.task.batch.parallel.ParallelIndexSupervisorTask; +import org.apache.druid.indexing.kafka.KafkaIndexTaskModule; +import org.apache.druid.indexing.kafka.simulate.KafkaResource; +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.indexing.overlord.supervisor.SupervisorStatus; +import org.apache.druid.java.util.common.DateTimes; +import org.apache.druid.java.util.common.Intervals; +import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.java.util.common.parsers.CloseableIterator; +import org.apache.druid.query.DruidMetrics; +import org.apache.druid.query.http.SqlTaskStatus; +import org.apache.druid.segment.indexing.DataSchema; +import org.apache.druid.testing.DruidCommand; +import org.apache.druid.testing.embedded.EmbeddedDruidCluster; +import org.apache.druid.testing.embedded.EmbeddedOverlord; +import org.apache.druid.testing.embedded.derby.EmbeddedDerbyMetadataResource; +import org.apache.druid.testing.embedded.emitter.LatchableEmitterModule; +import org.apache.druid.testing.embedded.indexing.MoreResources; +import org.apache.druid.testing.embedded.indexing.Resources; +import org.apache.druid.testing.embedded.junit5.EmbeddedClusterTestBase; +import org.apache.druid.testing.embedded.minio.MinIOStorageResource; +import org.apache.druid.testing.embedded.msq.EmbeddedMSQApis; +import org.apache.druid.testing.embedded.server.EmbeddedEventCollector; +import org.apache.druid.timeline.DataSegment; +import org.apache.kafka.clients.producer.ProducerRecord; +import org.joda.time.DateTime; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ThreadLocalRandom; + +/** + * Runs some basic ingestion tests using {@code DruidContainers}. + * <p> + * This test verifies functionality of Druid Docker images using + * {@link DruidContainerResource}. However, the underlying cluster also uses + * embedded servers either to provide visibility into the cluster state or to + * test backwards compatibility of a given feature. + */ +public class IngestionDockerTest extends EmbeddedClusterTestBase +{ + // Druid Docker containers + protected final DruidContainerResource overlordLeader = + new DruidContainerResource(DruidCommand.OVERLORD).usingTestImage(); + protected final DruidContainerResource coordinator = + new DruidContainerResource(DruidCommand.COORDINATOR).usingTestImage(); + protected final DruidContainerResource historical = + new DruidContainerResource(DruidCommand.HISTORICAL).usingTestImage(); + protected final DruidContainerResource broker = + new DruidContainerResource(DruidCommand.BROKER) + .addProperty("druid.sql.planner.metadataRefreshPeriod", "PT1s") + .usingTestImage(); + protected final DruidContainerResource router = + new DruidContainerResource(DruidCommand.ROUTER).usingTestImage(); + protected final DruidContainerResource middleManager = + new DruidContainerResource(DruidCommand.MIDDLE_MANAGER) + .addProperty("druid.segment.handoff.pollDuration", "PT0.1s") + .usingTestImage(); + + // Follower EmbeddedOverlord to help serialize Task and Supervisor payloads + private final EmbeddedOverlord overlordFollower = + new EmbeddedOverlord().addProperty("druid.plaintextPort", "7090"); + + // Event collector to watch for metric events + private final EmbeddedEventCollector eventCollector = new EmbeddedEventCollector() + .addProperty("druid.emitter", "latching") + .addProperty("druid.server.http.numThreads", "20"); + + private final KafkaResource kafkaServer = new KafkaResource(); + + @Override + public EmbeddedDruidCluster createCluster() + { + return EmbeddedDruidCluster + .withZookeeper() + .useDruidContainers() + // Needed for overlordFollower to recognize the KafkaSupervisor type + .addExtensions(KafkaIndexTaskModule.class, LatchableEmitterModule.class) + .addResource(new EmbeddedDerbyMetadataResource()) + .addResource(new MinIOStorageResource()) + .addResource(kafkaServer) + .addCommonProperty( + "druid.extensions.loadList", + "[\"druid-s3-extensions\", \"druid-kafka-indexing-service\", \"druid-multi-stage-query\"]" + ) + .addCommonProperty("druid.emitter", "http") + .addCommonProperty("druid.emitter.http.recipientBaseUrl", eventCollector.getMetricsUrl()) + .addCommonProperty("druid.emitter.http.flushMillis", "500") + .addResource(coordinator) + .addResource(overlordLeader) + .addResource(middleManager) + .addResource(historical) + .addResource(broker) + .addResource(router) + .addServer(overlordFollower) + .addServer(eventCollector); + } + + @BeforeEach + @AfterEach + public void verifyOverlordLeader() + { + Assertions.assertFalse( + overlordFollower.bindings().overlordLeaderSelector().isLeader() + ); + } + + @Test + public void test_runIndexTask_andKillData() + { + final int numSegments = 10; + + // Run an 'index' task and verify the ingested data + final String taskId = IdUtils.getRandomId(); + final IndexTask task = MoreResources.Task.BASIC_INDEX.get().dataSource(dataSource).withId(taskId); + cluster.callApi().onLeaderOverlord(o -> o.runTask(taskId, task)); + cluster.callApi().waitForTaskToSucceed(taskId, eventCollector.latchableEmitter()); + + verifyUsedSegmentCount(numSegments); + waitForSegmentsToBeQueryable(numSegments); + + cluster.callApi().verifySqlQuery("SELECT COUNT(*) FROM sys.segments WHERE datasource='%s'", dataSource, "10"); + cluster.callApi().verifySqlQuery("SELECT * FROM %s", dataSource, Resources.InlineData.CSV_10_DAYS); + + // Mark all segments as unused and verify state + Assertions.assertEquals( + numSegments, + markSegmentsAsUnused(dataSource) + ); + verifyUsedSegmentCount(0); + eventCollector.latchableEmitter().waitForEventAggregate( + event -> event.hasMetricName("segment/loadQueue/success") + .hasDimension(DruidMetrics.DESCRIPTION, "DROP") + .hasService("druid/coordinator"), + agg -> agg.hasSumAtLeast(numSegments) + ); + cluster.callApi().verifySqlQuery("SELECT * FROM sys.segments WHERE datasource='%s'", dataSource, ""); + + // Kill all unused segments + final String killTaskId = cluster.callApi().onLeaderOverlord( + o -> o.runKillTask(IdUtils.getRandomId(), dataSource, Intervals.ETERNITY, null, null, null) + ); + cluster.callApi().waitForTaskToSucceed(killTaskId, eventCollector.latchableEmitter()); + + eventCollector.latchableEmitter().waitForEventAggregate( + event -> event.hasMetricName("segment/nuked/bytes") + .hasService("druid/overlord"), + agg -> agg.hasCountAtLeast(numSegments) + ); + } + + @Test + public void test_runIndexParallelTask_andCompactData() + { + final int numSegments = 10; Review Comment: ## Unread local variable Variable 'int numSegments' is never read. [Show more details](https://github.com/apache/druid/security/code-scanning/9939) -- 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]
