Skip to content

Commit 29076c8

Browse files
[FLINK-35815][autoscaler] Autoscaler standalone load config from yaml file (#853)
1 parent cb90b10 commit 29076c8

File tree

6 files changed

+102
-1
lines changed

6 files changed

+102
-1
lines changed

docs/content.zh/docs/custom-resource/autoscaler.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ org.apache.flink.autoscaler.standalone.StandaloneAutoscalerEntrypoint \
308308
--autoscaler.standalone.jdbc.username root
309309
```
310310
311+
### Load StandaloneAutoscaler configuration through configuration file
312+
313+
Can specify the running configuration of StandaloneAutoscaler in the configuration file. The config.yaml and
314+
flink-conf.yaml files in the environment variable `FLINK_CONF_DIR` directory will be loaded by default.
315+
NOTE: main parameters will overwrite the configuration in the configuration file
316+
311317
All supported options for autoscaler standalone can be viewed
312318
[here]({{< ref "docs/operations/configuration#autoscaler-standalone-configuration" >}}).
313319

docs/content/docs/custom-resource/autoscaler.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ org.apache.flink.autoscaler.standalone.StandaloneAutoscalerEntrypoint \
308308
--autoscaler.standalone.jdbc.username root
309309
```
310310
311+
### Load StandaloneAutoscaler configuration through configuration file
312+
313+
Can specify the running configuration of StandaloneAutoscaler in the configuration file. The config.yaml and
314+
flink-conf.yaml files in the environment variable `FLINK_CONF_DIR` directory will be loaded by default.
315+
NOTE: main parameters will overwrite the configuration in the configuration file
316+
311317
All supported options for autoscaler standalone can be viewed
312318
[here]({{< ref "docs/operations/configuration#autoscaler-standalone-configuration" >}}).
313319

flink-autoscaler-standalone/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,15 @@ under the License.
215215
</execution>
216216
</executions>
217217
</plugin>
218+
<plugin>
219+
<groupId>org.apache.maven.plugins</groupId>
220+
<artifactId>maven-surefire-plugin</artifactId>
221+
<configuration>
222+
<environmentVariables>
223+
<FLINK_CONF_DIR>src/test/resources</FLINK_CONF_DIR>
224+
</environmentVariables>
225+
</configuration>
226+
</plugin>
218227
</plugins>
219228
</build>
220229

flink-autoscaler-standalone/src/main/java/org/apache/flink/autoscaler/standalone/StandaloneAutoscalerEntrypoint.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.flink.autoscaler.standalone;
1919

2020
import org.apache.flink.annotation.Experimental;
21+
import org.apache.flink.annotation.VisibleForTesting;
2122
import org.apache.flink.api.java.utils.ParameterTool;
2223
import org.apache.flink.autoscaler.JobAutoScaler;
2324
import org.apache.flink.autoscaler.JobAutoScalerContext;
@@ -31,6 +32,7 @@
3132
import org.apache.flink.autoscaler.state.AutoScalerStateStore;
3233
import org.apache.flink.client.program.rest.RestClusterClient;
3334
import org.apache.flink.configuration.Configuration;
35+
import org.apache.flink.configuration.GlobalConfiguration;
3436
import org.apache.flink.runtime.highavailability.nonha.standalone.StandaloneClientHAServices;
3537

3638
import org.slf4j.Logger;
@@ -48,7 +50,7 @@ public class StandaloneAutoscalerEntrypoint {
4850

4951
public static <KEY, Context extends JobAutoScalerContext<KEY>> void main(String[] args)
5052
throws Exception {
51-
var conf = ParameterTool.fromArgs(args).getConfiguration();
53+
var conf = loadConfiguration(args);
5254
LOG.info("The standalone autoscaler is started, configuration: {}", conf);
5355

5456
// Initialize JobListFetcher and JobAutoScaler.
@@ -94,4 +96,10 @@ JobAutoScaler<KEY, Context> createJobAutoscaler(
9496
new RescaleApiScalingRealizer<>(eventHandler),
9597
stateStore);
9698
}
99+
100+
@VisibleForTesting
101+
static Configuration loadConfiguration(String[] args) {
102+
return GlobalConfiguration.loadConfiguration(
103+
ParameterTool.fromArgs(args).getConfiguration());
104+
}
97105
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.flink.autoscaler.standalone;
19+
20+
import org.apache.flink.configuration.Configuration;
21+
22+
import org.junit.jupiter.api.Test;
23+
24+
import java.time.Duration;
25+
26+
import static org.apache.flink.autoscaler.standalone.config.AutoscalerStandaloneOptions.CONTROL_LOOP_INTERVAL;
27+
import static org.apache.flink.autoscaler.standalone.config.AutoscalerStandaloneOptions.CONTROL_LOOP_PARALLELISM;
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
29+
import static org.junit.jupiter.api.Assertions.assertNotNull;
30+
31+
class StandaloneAutoscalerEntrypointTest {
32+
@Test
33+
public void testLoadConfiguration() {
34+
// Test for loading configuration from file.
35+
Configuration conf = StandaloneAutoscalerEntrypoint.loadConfiguration(new String[0]);
36+
assertNotNull(conf);
37+
assertEquals(Duration.ofMinutes(1), conf.get(CONTROL_LOOP_INTERVAL));
38+
assertEquals(20, conf.get(CONTROL_LOOP_PARALLELISM));
39+
// Test for args override
40+
String[] args =
41+
new String[] {
42+
"--autoscaler.standalone.control-loop.interval",
43+
"2min",
44+
"--autoscaler" + ".standalone.control-loop.parallelism",
45+
"10"
46+
};
47+
Configuration confOverride = StandaloneAutoscalerEntrypoint.loadConfiguration(args);
48+
assertNotNull(confOverride);
49+
assertEquals(Duration.ofMinutes(2), confOverride.get(CONTROL_LOOP_INTERVAL));
50+
assertEquals(10, confOverride.get(CONTROL_LOOP_PARALLELISM));
51+
}
52+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
################################################################################
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
################################################################################
18+
19+
autoscaler.standalone.control-loop.interval: 60s
20+
autoscaler.standalone.control-loop.parallelism: 20

0 commit comments

Comments
 (0)