wenjin272 commented on code in PR #1386:
URL: https://github.com/apache/flink-agents/pull/1386#discussion_r4613259585
##########
plan/src/main/java/org/apache/flink/agents/plan/AgentConfiguration.java:
##########
@@ -156,6 +173,9 @@ public <T> T get(ConfigOption<T> option) {
Class<T> targetType = option.getType();
if (targetType.isAssignableFrom(rawValue.getClass())) {
+ if (Duration.class.equals(targetType)) {
Review Comment:
Could we handle duration options in a single branch before the generic
`isAssignableFrom` check?
Currently, a stored string goes through `DurationUtils.parse()`, which
checks microsecond alignment, followed by option-specific validation. A stored
`Duration` only goes through option-specific validation, so it skips the
alignment check.
For example, putting `Duration.ofNanos(500)` into the map returned by
`getConfData()` makes `get(ASYNC_BATCH_TIMEOUT)` accept it, while storing `"500
ns"` makes the same getter reject it. The typed setter already rejects this
value; the inconsistency is in the getter's handling of raw map entries.
Since `DurationUtils.parse(Object)` already supports both strings and
`Duration` objects, we can send both through the same parsing and validation
path. This removes the duplicate duration branches and makes their precision
checks consistent.
##########
python/flink_agents/runtime/flink_runner_context.py:
##########
@@ -397,8 +398,12 @@ def __await__(self) -> Any:
parallelism = self._ctx.config.get(
AgentExecutionOptions.ASYNC_BATCH_PARALLELISM
)
- timeout_ms =
self._ctx.config.get(AgentExecutionOptions.ASYNC_BATCH_TIMEOUT_MS)
- deadline = time.monotonic() + timeout_ms / 1000 if timeout_ms > 0 else
None
+ timeout =
self._ctx.config.get(AgentExecutionOptions.ASYNC_BATCH_TIMEOUT)
+ timeout_seconds = positive_seconds(timeout)
+ deadline = (
+ time.monotonic() + timeout_seconds if timeout_seconds is not None
else None
+ )
+ timeout_label = format_duration(timeout) if deadline is not None else
None
Review Comment:
Could we pass the original `timedelta` as `timeout` and format it only when
constructing the timeout error?
`deadline` already controls execution, while `timeout_label` is only used in
the error message. Passing the duration would preserve its meaning across the
call boundary and avoid formatting it for batches that complete successfully.
##########
python/flink_agents/plan/tests/compatibility/check_java_python_config_options_parity.py:
##########
@@ -110,6 +110,28 @@ def _normalize_java_collection(value: Any) -> Any:
return value
+def _java_enum_name(java_value: Any) -> Any:
Review Comment:
Could we use the declared `python_config_type` to identify enum defaults
instead of probing each value with `getClass().isEnum()` and catching Py4J
errors?
The caller already checks that the Java and Python option types match. For a
Python `Enum` subclass, we can directly convert `java_default.name()` to that
enum; Duration, collections, and primitives can keep their explicit branches.
This would also simplify the fake-gateway tests and let unexpected gateway
errors surface. I checked a version using this approach against the actual
Java/Python configuration parity check, and it passed.
##########
plan/src/main/java/org/apache/flink/agents/plan/AgentConfiguration.java:
##########
@@ -180,6 +208,59 @@ public <T> T get(ConfigOption<T> option) {
}
}
+ private void putValue(String key, Object value) {
Review Comment:
Could we keep the direct map writes instead of introducing `putValue()` here
and `_put()` in Python?
Both helpers only forward an assignment, without normalization or
validation. They add an extra call layer and require changes to all the
existing primitive setters without changing their behavior. Keeping the
duration handling in the relevant paths would make the diff smaller and easier
to follow.
##########
api/src/test/java/org/apache/flink/agents/api/configuration/DurationUtilsTest.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.agents.api.configuration;
+
+import org.apache.flink.agents.api.agents.AgentExecutionOptions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+
+import java.time.Duration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/** Parser and precision coverage shared with the Python duration tests. */
+class DurationUtilsTest {
+
+ @ParameterizedTest
+ @CsvSource({
Review Comment:
Could we move the shared duration parsing cases into one JSON or CSV fixture
consumed by both Java and Python tests?
The same 17 cases are currently maintained separately here and in
`test_duration.py`. A shared table containing the input, expected duration in
microseconds, canonical text, and rejection category would reduce duplication
and make future changes easier to keep consistent.
Each language could retain its own assertions and language-specific edge
cases. Including the expected duration would also ensure every successful case
checks the actual value, rather than only agreement between parsing and
formatting.
##########
python/flink_agents/plan/configuration.py:
##########
@@ -109,29 +128,41 @@ def get(self, option: ConfigOption) -> Any:
option.get_key(), option.get_type(), option.get_default_value()
)
+ def _put(self, key: str, value: Any) -> None:
+ self.conf_data[key] = value
+
@override
def set_str(self, key: str, value: str) -> None:
- self.conf_data[key] = value
+ self._put(key, value)
@override
def set_int(self, key: str, value: int) -> None:
- self.conf_data[key] = value
+ self._put(key, value)
@override
def set_float(self, key: str, value: float) -> None:
- self.conf_data[key] = value
+ self._put(key, value)
@override
def set_bool(self, key: str, value: bool) -> None:
- self.conf_data[key] = value
+ self._put(key, value)
@override
def set(self, option: ConfigOption, value: Any) -> None:
- self.conf_data[option.get_key()] = (
- _serialize_targets(value)
- if option.get_key() == _TRACE_LOG_TARGETS_KEY
- else value
- )
+ if option.get_key() == _TRACE_LOG_TARGETS_KEY:
+ stored = _serialize_targets(value)
+ elif option.get_type() is timedelta:
Review Comment:
Could we share the duration parsing and validation logic between
`get_value_with_type()` and `set()`?
Both paths currently call `parse_duration()`, wrap parsing errors with the
configuration key, and call `validate_consumed_duration()`. The setter then
additionally formats the result for storage.
A small private helper such as `_parse_duration_option(key, value)` could
return the validated `timedelta`. The getter would return that value directly,
while the setter would pass it to `format_duration()` before storing it.
This keeps validation on both read and write paths, while giving us one
place to maintain the parsing, validation, and error handling.
--
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]