zhangyue19921010 commented on a change in pull request #10524:
URL: https://github.com/apache/druid/pull/10524#discussion_r582907601



##########
File path: 
indexing-service/src/main/java/org/apache/druid/indexing/seekablestream/supervisor/autoscaler/DefaultAutoScaler.java
##########
@@ -0,0 +1,244 @@
+/*
+ * 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.commons.collections4.queue.CircularFifoQueue;
+import org.apache.druid.indexing.overlord.supervisor.Supervisor;
+import org.apache.druid.indexing.overlord.supervisor.SupervisorSpec;
+import org.apache.druid.indexing.overlord.supervisor.autoscaler.LagStats;
+import 
org.apache.druid.indexing.overlord.supervisor.autoscaler.SupervisorTaskAutoscaler;
+import 
org.apache.druid.indexing.seekablestream.supervisor.SeekableStreamSupervisor;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.emitter.EmittingLogger;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.ReentrantLock;
+
+public class DefaultAutoScaler implements SupervisorTaskAutoscaler
+{
+  private static final EmittingLogger log = new 
EmittingLogger(DefaultAutoScaler.class);
+  private final String dataSource;
+  private final CircularFifoQueue<Long> lagMetricsQueue;
+  private final ScheduledExecutorService lagComputationExec;
+  private final ScheduledExecutorService allocationExec;
+  private final SupervisorSpec spec;
+  private final SeekableStreamSupervisor supervisor;
+  private final DefaultAutoScalerConfig defaultAutoScalerConfig;
+
+  private static ReentrantLock lock = new ReentrantLock(true);
+
+
+  public DefaultAutoScaler(Supervisor supervisor, String dataSource, 
AutoScalerConfig autoScalerConfig, SupervisorSpec spec)
+  {
+    this.defaultAutoScalerConfig = (DefaultAutoScalerConfig) autoScalerConfig;
+    String supervisorId = StringUtils.format("KafkaSupervisor-%s", dataSource);
+    this.dataSource = dataSource;
+    int slots = (int) 
(defaultAutoScalerConfig.getMetricsCollectionRangeMillis() / 
defaultAutoScalerConfig.getMetricsCollectionIntervalMillis()) + 1;
+    log.debug(" The interval of metrics collection is [%s], [%s] timeRange 
will collect [%s] data points for dataSource [%s].", 
defaultAutoScalerConfig.getMetricsCollectionIntervalMillis(), 
defaultAutoScalerConfig.getMetricsCollectionRangeMillis(), slots, dataSource);
+    this.lagMetricsQueue = new CircularFifoQueue<>(slots);
+    this.allocationExec = 
Execs.scheduledSingleThreaded(StringUtils.encodeForFormat(supervisorId) + 
"-Allocation-%d");

Review comment:
       Sorry. I just found it is necessary to do encoding for supervisorId. 
   If `supervisorID` itself contains special characters `%s` like 
`"dataSource": 
"kafka_transactional_parallelized_indexing_service_test_2ec894f4-3bb4-4909-91ca-8f934e14bc84
 %Россия 한국 中国!?"` mentioned in Job 41, It will throw `Caused by: 
java.util.UnknownFormatConversionException: Conversion = &apos;?&apos;` 
exception without 
encoding(https://travis-ci.com/github/apache/druid/jobs/486176708)
   So I revert this change here. 




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

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