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


##########
indexing-service/src/main/java/org/apache/druid/indexing/seekablestream/supervisor/autoscaler/WeightedCostFunction.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.indexing.seekablestream.supervisor.autoscaler;
+
+import org.apache.druid.java.util.common.logger.Logger;
+
+/**
+ * Weighted cost function using compute time as the core metric.
+ * Costs represent actual time in seconds, making them intuitive and 
debuggable.
+ * Uses linear scaling without mode inversions for predictable behavior.
+ */
+public class WeightedCostFunction
+{
+  private static final Logger log = new Logger(WeightedCostFunction.class);
+
+
+  /**
+   * Ideal idle ratio range boundaries.
+   * Idle ratio below MIN indicates tasks are overloaded (scale up needed).
+   * Idle ratio above MAX indicates tasks are underutilized (scale down 
needed).
+   */
+  static final double IDEAL_IDLE_MIN = 0.2;
+  static final double IDEAL_IDLE_MAX = 0.6;
+
+  /**
+   * Checks if the given idle ratio is within the ideal range [{@value 
#IDEAL_IDLE_MIN}, {@value #IDEAL_IDLE_MAX}].
+   * When idle is in this range, optimal utilization has been achieved and no 
scaling is needed.
+   */
+  public static boolean isIdleInIdealRange(double idleRatio)
+  {
+    return idleRatio >= IDEAL_IDLE_MIN && idleRatio <= IDEAL_IDLE_MAX;
+  }
+
+  /**
+   * Computes cost for a given task count using compute time metrics.
+   * <p>
+   * Costs are measured in 'seconds':
+   * <ul>
+   *   <li><b>lagCost</b>: Expected time (seconds) to recover current lag</li>
+   *   <li><b>idleCost</b>: Total compute time (seconds) wasted being idle per 
task duration</li>
+   * </ul>
+   * <p>
+   * Formula: {@code lagWeight * lagRecoveryTime + idleWeight * idlenessCost}.
+   * This approach directly connects costs to operational metricsю
+   *
+   * @return cost score in seconds, or {@link Double#POSITIVE_INFINITY} for 
invalid inputs
+   */
+  public double computeCost(CostMetrics metrics, int proposedTaskCount, 
CostBasedAutoScalerConfig config)
+  {
+    if (metrics == null || config == null || proposedTaskCount <= 0 || 
metrics.getPartitionCount() <= 0) {
+      return Double.POSITIVE_INFINITY;
+    }
+
+    final double avgProcessingRate = metrics.getAvgProcessingRate();
+    final int taskCountDiff = proposedTaskCount - 
metrics.getCurrentTaskCount();

Review Comment:
   ## Unread local variable
   
   Variable 'int taskCountDiff' is never read.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/10602)



-- 
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