gyfora commented on code in PR #741: URL: https://github.com/apache/flink-kubernetes-operator/pull/741#discussion_r1452035678
########## flink-autoscaler-plugin-jdbc/src/main/java/org/apache/flink/autoscaler/jdbc/state/JDBCStore.java: ########## @@ -0,0 +1,92 @@ +/* + * 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.jdbc.state; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; + +/** The jdbc store. */ +public class JDBCStore { Review Comment: Should we call it `JdbcStateStore` instead? ########## flink-autoscaler-plugin-jdbc/src/test/java/org/apache/flink/autoscaler/jdbc/state/AbstractJDBCStateInteractorITCase.java: ########## @@ -0,0 +1,93 @@ +/* + * 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.jdbc.state; + +import org.apache.flink.autoscaler.jdbc.testutils.databases.DatabaseTest; +import org.apache.flink.autoscaler.jdbc.testutils.databases.derby.DerbyTestBase; +import org.apache.flink.autoscaler.jdbc.testutils.databases.mysql.MySQL56TestBase; +import org.apache.flink.autoscaler.jdbc.testutils.databases.mysql.MySQL57TestBase; +import org.apache.flink.autoscaler.jdbc.testutils.databases.mysql.MySQL8TestBase; +import org.apache.flink.autoscaler.jdbc.testutils.databases.postgres.PostgreSQLTestBase; + +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.Map; + +import static org.apache.flink.autoscaler.jdbc.state.StateType.COLLECTED_METRICS; +import static org.apache.flink.autoscaler.jdbc.state.StateType.SCALING_HISTORY; +import static org.assertj.core.api.Assertions.assertThat; + +/** The abstract IT case for {@link JDBCStateInteractor}. */ +abstract class AbstractJDBCStateInteractorITCase implements DatabaseTest { Review Comment: `JDBC` -> `Jdbc ` ########## flink-autoscaler-plugin-jdbc/src/main/java/org/apache/flink/autoscaler/jdbc/state/JDBCAutoScalerStateStore.java: ########## @@ -0,0 +1,286 @@ +/* + * 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.jdbc.state; + +import org.apache.flink.annotation.Experimental; +import org.apache.flink.annotation.VisibleForTesting; +import org.apache.flink.autoscaler.JobAutoScalerContext; +import org.apache.flink.autoscaler.ScalingSummary; +import org.apache.flink.autoscaler.ScalingTracking; +import org.apache.flink.autoscaler.metrics.CollectedMetrics; +import org.apache.flink.autoscaler.state.AutoScalerStateStore; +import org.apache.flink.autoscaler.utils.AutoScalerSerDeModule; +import org.apache.flink.configuration.ConfigurationUtils; +import org.apache.flink.runtime.jobgraph.JobVertexID; + +import com.fasterxml.jackson.core.JacksonException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.Nonnull; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.time.Instant; +import java.util.Base64; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.SortedMap; +import java.util.TreeMap; +import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; + +import static org.apache.flink.autoscaler.jdbc.state.StateType.COLLECTED_METRICS; +import static org.apache.flink.autoscaler.jdbc.state.StateType.PARALLELISM_OVERRIDES; +import static org.apache.flink.autoscaler.jdbc.state.StateType.SCALING_HISTORY; +import static org.apache.flink.autoscaler.jdbc.state.StateType.SCALING_TRACKING; + +/** + * The state store which persists its state in JDBC related database. + * + * @param <KEY> The job key. + * @param <Context> The job autoscaler context. + */ +@Experimental +public class JDBCAutoScalerStateStore<KEY, Context extends JobAutoScalerContext<KEY>> Review Comment: Should be ` JdbcAutoScalerStateStore<` ########## flink-autoscaler-plugin-jdbc/src/test/java/org/apache/flink/autoscaler/jdbc/state/CountableJDBCStateInteractor.java: ########## @@ -0,0 +1,81 @@ +/* + * 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.jdbc.state; + +import java.sql.Connection; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; + +import static org.assertj.core.api.Assertions.assertThat; + +/** Countable {@link JDBCStateInteractor}. */ +public class CountableJDBCStateInteractor extends JDBCStateInteractor { Review Comment: JDBC -> Jdbc ########## flink-autoscaler-standalone/src/main/java/org/apache/flink/autoscaler/standalone/config/AutoscalerStandaloneOptions.java: ########## @@ -59,4 +64,47 @@ private static ConfigOptions.OptionBuilder autoscalerStandaloneConfig(String key .withDeprecatedKeys("flinkClusterPort") .withDescription( "The port of flink cluster when the flink-cluster fetcher is used."); + + public static final ConfigOption<StateStoreType> STATE_STORE_TYPE = + autoscalerStandaloneConfig("state-store.type") + .enumType(StateStoreType.class) + .defaultValue(StateStoreType.MEMORY) + .withDescription("The autoscaler state store type."); + + public static final ConfigOption<String> STATE_STORE_JDBC_URL = + autoscalerStandaloneConfig("state-store.jdbc.url") + .stringType() + .noDefaultValue() + .withDescription( + Description.builder() + .text( + "The jdbc url of jdbc state store when %s has been set to %s, such as: %s.", + code(STATE_STORE_TYPE.key()), + code(JDBC.toString()), + code("jdbc:mysql://localhost:3306/flink_autoscaler")) + .linebreak() + .text("This option is required when using JDBC state store.") + .build()); + + public static final ConfigOption<String> STATE_STORE_JDBC_USERNAME = + autoscalerStandaloneConfig("state-store.jdbc.username") + .stringType() + .noDefaultValue() + .withDescription( + Description.builder() + .text( + "The jdbc username of jdbc state store when %s has been set to %s.", + code(STATE_STORE_TYPE.key()), code(JDBC.toString())) + .build()); + + public static final ConfigOption<String> STATE_STORE_JDBC_PASSWORD = + autoscalerStandaloneConfig("state-store.jdbc.password") Review Comment: We need a way to set this from a secret / env. Otherwise this is very hard to be used in production properly ########## flink-autoscaler-plugin-jdbc/src/test/java/org/apache/flink/autoscaler/jdbc/state/JDBCAutoScalerStateStoreTest.java: ########## @@ -0,0 +1,161 @@ +/* + * 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.jdbc.state; + +import org.apache.flink.api.common.JobID; +import org.apache.flink.autoscaler.JobAutoScalerContext; +import org.apache.flink.autoscaler.ScalingSummary; +import org.apache.flink.autoscaler.jdbc.testutils.databases.derby.DerbyTestBase; +import org.apache.flink.autoscaler.metrics.CollectedMetrics; +import org.apache.flink.autoscaler.metrics.EvaluatedScalingMetric; +import org.apache.flink.autoscaler.metrics.ScalingMetric; +import org.apache.flink.autoscaler.state.AbstractAutoScalerStateStoreTest; +import org.apache.flink.autoscaler.state.AutoScalerStateStore; +import org.apache.flink.runtime.jobgraph.JobVertexID; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.time.Instant; +import java.util.HashMap; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +import static org.apache.flink.autoscaler.TestingAutoscalerUtils.createDefaultJobAutoScalerContext; +import static org.apache.flink.autoscaler.jdbc.state.JDBCAutoScalerStateStore.serializeEvaluatedMetrics; +import static org.apache.flink.autoscaler.jdbc.state.JDBCAutoScalerStateStore.serializeScalingHistory; +import static org.apache.flink.autoscaler.metrics.ScalingHistoryUtils.addToScalingHistoryAndStore; +import static org.apache.flink.autoscaler.metrics.ScalingHistoryUtils.getTrimmedScalingHistory; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for {@link JDBCAutoScalerStateStore}. + * + * <p>Note: {@link #testCompressionMigration} and {@link #testDiscardInvalidHistory} are referred + * from {@link KubernetesAutoScalerStateStoreTest}. + */ +class JDBCAutoScalerStateStoreTest Review Comment: JDBC -> Jdbc ########## flink-autoscaler-plugin-jdbc/src/test/java/org/apache/flink/autoscaler/jdbc/state/AbstractJDBCStoreITCase.java: ########## @@ -0,0 +1,303 @@ +/* + * 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.jdbc.state; + +import org.apache.flink.autoscaler.jdbc.testutils.databases.DatabaseTest; +import org.apache.flink.autoscaler.jdbc.testutils.databases.derby.DerbyTestBase; +import org.apache.flink.autoscaler.jdbc.testutils.databases.mysql.MySQL56TestBase; +import org.apache.flink.autoscaler.jdbc.testutils.databases.mysql.MySQL57TestBase; +import org.apache.flink.autoscaler.jdbc.testutils.databases.mysql.MySQL8TestBase; +import org.apache.flink.autoscaler.jdbc.testutils.databases.postgres.PostgreSQLTestBase; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.sql.Connection; +import java.sql.SQLException; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.apache.flink.autoscaler.jdbc.state.StateType.COLLECTED_METRICS; +import static org.apache.flink.autoscaler.jdbc.state.StateType.SCALING_HISTORY; +import static org.apache.flink.autoscaler.jdbc.state.StateType.SCALING_TRACKING; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** The abstract IT case for {@link JDBCStore}. */ +abstract class AbstractJDBCStoreITCase implements DatabaseTest { Review Comment: JDBC -> Jdbc -- 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]
