sklaha commented on code in PR #249:
URL: https://github.com/apache/cassandra-sidecar/pull/249#discussion_r2286637556


##########
adapters/adapters-base/src/main/java/org/apache/cassandra/sidecar/adapters/base/jmx/StorageJmxOperations.java:
##########
@@ -198,4 +198,37 @@ public interface StorageJmxOperations
      * Triggers start gossip
      */
     void startGossiping();
+
+    /**
+     * Returns the number of concurrent compactors configured for the node
+     * @return number of concurrent compactors
+     */
+    int getConcurrentCompactors();
+
+    /**
+     * Returns the compaction throughput limit in MiB per second as a double
+     * @return compaction throughput limit
+     */
+    double getCompactionThroughputMbPerSec();
+
+    /**
+     * Returns the compaction throughput limit in MiB per second as a double 
(alternative method name)
+     * @return compaction throughput limit
+     */
+    double getCompactionThroughtputMibPerSecAsDouble();
+
+    /**
+     * Returns current compaction throughput measurements in MiB per second 
for different time windows
+     * @return map of time windows to throughput measurements
+     */
+    Map<String, String> getCurrentCompactionThroughputMebibytesPerSec();
+
+    /**
+     * Returns the current compaction throughput in bytes per second.
+     * This method provides the throughput measurement in bytes per second, 
which is useful
+     * for calculating estimated completion times and remaining work for 
active compactions.
+     * 
+     * @return the current compaction throughput in bytes per second, or 0 if 
throughput cannot be determined
+     */
+    long getCompactionThroughtputBytesPerSec();

Review Comment:
   Added a comment on that.



##########
adapters/adapters-base/src/main/java/org/apache/cassandra/sidecar/adapters/base/jmx/CompactionManagerJmxOperations.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.cassandra.sidecar.adapters.base.jmx;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * An interface that pulls methods from the Cassandra CompactionManager JMX 
proxy
+ */
+public interface CompactionManagerJmxOperations
+{
+    String COMPACTION_MANAGER_OBJ_NAME = 
"org.apache.cassandra.db:type=CompactionManager";
+
+    /**
+     * Returns the number of concurrent compactors configured for the node.
+     * @return number of concurrent compactors
+     */
+    int getCoreCompactorThreads();
+
+    /**
+     * Returns active compactions as a list of compaction info maps
+     * @return list of compaction info maps
+     */
+    List<Map<String, String>> getCompactions();
+
+    /**
+     * Returns compaction throughput in bytes per second
+     * @return compaction throughput in bytes per second
+     */
+    long getCompactionThroughputMbPerSec();
+}

Review Comment:
   I fixed all checkstyle issues.



##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/response/data/ActiveCompactionEntry.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.cassandra.sidecar.common.response.data;
+
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Represents an active compaction entry
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class ActiveCompactionEntry
+{
+    private final String id;
+    private final String keyspace;
+    private final String columnFamily;
+    private final String taskType;
+    private final long completedBytes;
+    private final long totalBytes;
+    private final double percentCompleted;
+    private final List<String> ssTables;
+    private final String targetDirectory;
+
+    /**
+     * Constructs a new {@link ActiveCompactionEntry}.
+     *
+     * @param id               compaction ID
+     * @param keyspace         keyspace name
+     * @param columnFamily     table/column family name
+     * @param taskType         type of compaction task
+     * @param completedBytes   completed compaction in bytes
+     * @param totalBytes       total compaction in bytes
+     * @param percentCompleted percentage of completed compactions
+     * @param ssTables         list of SSTables being compacted
+     * @param targetDirectory  target directory for output
+     */
+    @JsonCreator
+    public ActiveCompactionEntry(@JsonProperty("id") final String id,
+                                 @JsonProperty("keyspace") final String 
keyspace,
+                                 @JsonProperty("columnFamily") final String 
columnFamily,
+                                 @JsonProperty("taskType") final String 
taskType,
+                                 @JsonProperty("completedBytes") final long 
completedBytes,
+                                 @JsonProperty("totalBytes") final long 
totalBytes,
+                                 @JsonProperty("percentCompleted") final 
double percentCompleted,
+                                 @JsonProperty("ssTables") final List<String> 
ssTables,
+                                 @JsonProperty("targetDirectory") final String 
targetDirectory)
+    {
+        this.id = id;
+        this.keyspace = keyspace;
+        this.columnFamily = columnFamily;
+        this.taskType = taskType;
+        this.completedBytes = completedBytes;
+        this.totalBytes = totalBytes;
+        this.percentCompleted = percentCompleted;
+        this.ssTables = ssTables;
+        this.targetDirectory = targetDirectory;
+    }
+
+    @JsonProperty("id")
+    public String id()
+    {
+        return id;
+    }
+
+    @JsonProperty("keyspace")
+    public String keyspace()
+    {
+        return keyspace;
+    }
+
+    @JsonProperty("columnFamily")
+    public String columnFamily()
+    {
+        return columnFamily;
+    }
+
+    @JsonProperty("taskType")
+    public String taskType()
+    {
+        return taskType;
+    }
+
+    @JsonProperty("completedBytes")
+    public long completedBytes()
+    {
+        return completedBytes;
+    }
+
+    @JsonProperty("totalBytes")
+    public long totalBytes()
+    {
+        return totalBytes;
+    }
+
+    @JsonProperty("percentCompleted")
+    public double percentCompleted()
+    {
+        return percentCompleted;
+    }
+
+    @JsonProperty("ssTables")
+    public List<String> ssTables()
+    {
+        return ssTables;
+    }
+
+    @JsonProperty("targetDirectory")
+    public String targetDirectory()
+    {
+        return targetDirectory;
+    }
+}

Review Comment:
   I fixed all checkstyle issues.



##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/response/data/PendingCompactionTasks.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * 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.cassandra.sidecar.common.response.data;
+
+import java.util.Map;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Represents pending compaction tasks by keyspace and table
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class PendingCompactionTasks
+{
+    private final Map<String, Map<String, Integer>> pendingTasksByTable;
+    private final int totalPendingTasks;
+
+    /**
+     * Constructs a new {@link PendingCompactionTasks}.
+     *
+     * @param pendingTasksByTable pending tasks organized by keyspace and table
+     * @param totalPendingTasks   total count of pending tasks
+     */
+    @JsonCreator
+    public PendingCompactionTasks(@JsonProperty("pendingTasksByTable") 
Map<String, Map<String, Integer>> pendingTasksByTable,
+                                  @JsonProperty("totalPendingTasks") int 
totalPendingTasks)
+    {
+        this.pendingTasksByTable = pendingTasksByTable;
+        this.totalPendingTasks = totalPendingTasks;
+    }
+
+    @JsonProperty("pendingTasksByTable")
+    public Map<String, Map<String, Integer>> pendingTasksByTable()
+    {
+        return pendingTasksByTable;
+    }
+
+    @JsonProperty("totalPendingTasks")
+    public int totalPendingTasks()
+    {
+        return totalPendingTasks;
+    }
+}

Review Comment:
   I fixed all checkstyle issues.



##########
integration-tests/src/integrationTest/org/apache/cassandra/sidecar/routes/CompactionStatsIntegrationTest.java:
##########
@@ -0,0 +1,337 @@
+/*
+ * 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.cassandra.sidecar.routes;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import org.junit.jupiter.api.Test;
+
+import io.vertx.core.buffer.Buffer;
+import io.vertx.core.http.HttpResponseExpectation;
+import io.vertx.ext.web.client.HttpResponse;
+import org.apache.cassandra.sidecar.common.response.CompactionStatsResponse;
+import org.apache.cassandra.sidecar.common.response.data.ActiveCompactionEntry;
+import org.apache.cassandra.sidecar.testing.QualifiedName;
+import 
org.apache.cassandra.sidecar.testing.SharedClusterSidecarIntegrationTestBase;
+
+import static org.apache.cassandra.testing.TestUtils.DC1_RF1;
+import static org.apache.cassandra.testing.TestUtils.TEST_KEYSPACE;
+import static org.apache.cassandra.testing.TestUtils.TEST_TABLE_PREFIX;
+import static org.apache.cassandra.testing.utils.AssertionUtils.getBlocking;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Integration tests for the Compaction Statistics API endpoint.
+ * 
+ * <p>Tests the compaction statistics functionality by generating large-scale 
SSTable data across
+ * multiple tables, triggering concurrent compactions, and validating API 
responses in both active
+ * and completed compaction scenarios.</p>
+ * 
+ * <h2>Testing Mechanism</h2>
+ * <ul>
+ *   <li><strong>Data Setup:</strong> Creates 5 tables with 100 SSTables each 
(500 total, 1000 records per SSTable)</li>
+ *   <li><strong>Concurrency:</strong> Triggers compactions simultaneously 
using separate threads</li>
+ *   <li><strong>Active Detection:</strong> Polls API immediately with retry 
logic to catch in-progress compactions</li>
+ *   <li><strong>Comprehensive Validation:</strong> Validates all response 
fields including statistics, rates, 
+ *       pending tasks, and detailed active compaction data when available</li>
+ *   <li><strong>Dual Success:</strong> Test passes whether active compactions 
are captured or completed</li>
+ * </ul>
+ */
+class CompactionStatsIntegrationTest extends 
SharedClusterSidecarIntegrationTestBase
+{
+    private static final String COMPACTION_STATS_ROUTE = 
"/api/v1/cassandra/stats/compaction";
+    private static final List<QualifiedName> TEST_TABLES = new ArrayList<>();
+    private static final int TABLE_COUNT = 5;
+
+    @Override
+    protected void initializeSchemaForTest()
+    {
+        createTestKeyspace(TEST_KEYSPACE, DC1_RF1);
+
+        for (int i = 1; i <= TABLE_COUNT; i++) {
+            TEST_TABLES.add(new QualifiedName(TEST_KEYSPACE, TEST_TABLE_PREFIX 
+ "_compaction_" + i));
+        }
+        
+        // Create test tables for compaction activity
+        for (QualifiedName tableName : TEST_TABLES) {
+            createTestTable(tableName,
+                            "CREATE TABLE %s ( \n" +
+                            "  id int PRIMARY KEY, \n" +
+                            "  data text \n" +
+                            ");");
+        }
+    }

Review Comment:
   I fixed all checkstyle issues.



-- 
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: pr-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org
For additional commands, e-mail: pr-h...@cassandra.apache.org

Reply via email to