1996fanrui commented on code in PR #751: URL: https://github.com/apache/flink-kubernetes-operator/pull/751#discussion_r1448858318
########## flink-autoscaler/src/main/java/org/apache/flink/autoscaler/resources/ResourceCheck.java: ########## @@ -0,0 +1,29 @@ +/* + * 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.flink.autoscaler.resources; + +/** An interface for checking the available capacity of the underlying resources. */ +public interface ResourceCheck { + + /** Simulates scheduling the provided number of resources. */ Review Comment: It's better to add some comments to explain the return value. ########## flink-autoscaler/src/main/java/org/apache/flink/autoscaler/resources/ResourceCheck.java: ########## @@ -0,0 +1,29 @@ +/* + * 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.flink.autoscaler.resources; + +/** An interface for checking the available capacity of the underlying resources. */ +public interface ResourceCheck { + + /** Simulates scheduling the provided number of resources. */ + boolean trySchedule( + int currentInstances, + int newInstances, Review Comment: ```suggestion int currentNumberOfTms, int newNumberOfTms, ``` How about it? Instance is not specific. ########## flink-autoscaler/src/main/java/org/apache/flink/autoscaler/RestApiMetricsCollector.java: ########## @@ -103,6 +106,42 @@ protected Map<FlinkMetric, AggregatedMetric> queryAggregatedVertexMetrics( } } + @Override + @SneakyThrows + protected Map<FlinkMetric, Metric> queryJmMetrics(Context ctx) { + Map<String, FlinkMetric> metrics = + Map.of( + "numRegisteredTaskManagers", FlinkMetric.NUM_TASK_MANAGERS, + "taskSlotsTotal", FlinkMetric.NUM_TASK_SLOTS_TOTAL, + "taskSlotsAvailable", FlinkMetric.NUM_TASK_SLOTS_AVAILABLE); Review Comment: All old metrics are queried and filter them via the `predicate` before. These new metrics don't use the old solution. They are queried directly, and don't use the `predicate`. Could we abstract the FlinkMetric for them? We can define 2 types metrics: QueryableMetric and PredicatableMetric. WDYT? ########## flink-autoscaler/src/main/java/org/apache/flink/autoscaler/resources/ResourceRequirements.java: ########## @@ -0,0 +1,32 @@ +/* + * 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.flink.autoscaler.resources; + +/** Interface to extract resource requirements. */ +public interface ResourceRequirements { + + /** The required number of CPU for TaskManager nodes, if available, otherwise 0. */ + default double getTaskManagerCpu() { + return 0; + } + + /** The required number of CPU for TaskManager nodes, if available, otherwise 0. */ + default double getTaskManagerMemory() { Review Comment: Could we use `MemorySize`? We don't know the unit if using double. Also , could we don't use a interface? Saving the `taskmanager.memory.flink.size` to conf can work as well. But flink doesn't have the unify option for cpu of taskmanager. [1] https://nightlies.apache.org/flink/flink-docs-master/docs/deployment/config/#taskmanager-memory-flink-size -- 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]
