This is an automated email from the ASF dual-hosted git repository.

davidzollo pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/seatunnel.git


The following commit(s) were added to refs/heads/dev by this push:
     new 4875a82d50 [Bug][Connector-V2][Prometheus] Apply batch_size default in 
loadConfig (#11797)
4875a82d50 is described below

commit 4875a82d504a1c02c13c124f89fc42106912cfb0
Author: surafel <[email protected]>
AuthorDate: Fri Aug 14 06:21:46 2026 +0300

    [Bug][Connector-V2][Prometheus] Apply batch_size default in loadConfig 
(#11797)
---
 .../prometheus/config/PrometheusSinkConfig.java    |  9 +--
 .../prometheus/PrometheusSinkConfigTest.java       | 70 ++++++++++++++++++++++
 2 files changed, 75 insertions(+), 4 deletions(-)

diff --git 
a/seatunnel-connectors-v2/connector-prometheus/src/main/java/org/apache/seatunnel/connectors/seatunnel/prometheus/config/PrometheusSinkConfig.java
 
b/seatunnel-connectors-v2/connector-prometheus/src/main/java/org/apache/seatunnel/connectors/seatunnel/prometheus/config/PrometheusSinkConfig.java
index 2e60b7613e..1505e37647 100644
--- 
a/seatunnel-connectors-v2/connector-prometheus/src/main/java/org/apache/seatunnel/connectors/seatunnel/prometheus/config/PrometheusSinkConfig.java
+++ 
b/seatunnel-connectors-v2/connector-prometheus/src/main/java/org/apache/seatunnel/connectors/seatunnel/prometheus/config/PrometheusSinkConfig.java
@@ -51,10 +51,11 @@ public class PrometheusSinkConfig extends HttpConfig {
         if 
(pluginConfig.getOptional(PrometheusSinkOptions.KEY_TIMESTAMP).isPresent()) {
             
sinkConfig.setKeyTimestamp(pluginConfig.get(PrometheusSinkOptions.KEY_TIMESTAMP));
         }
-        if 
(pluginConfig.getOptional(PrometheusSinkOptions.BATCH_SIZE).isPresent()) {
-            int batchSize = 
checkIntArgument(pluginConfig.get(PrometheusSinkOptions.BATCH_SIZE));
-            sinkConfig.setBatchSize(batchSize);
-        }
+        // Use get() (not getOptional().isPresent()) so the option's declared 
default is applied
+        // when batch_size is not configured; getOptional() does not fall back 
to the default, which
+        // would leave batchSize at 0 and disable the size-based flush trigger.
+        int batchSize = 
checkIntArgument(pluginConfig.get(PrometheusSinkOptions.BATCH_SIZE));
+        sinkConfig.setBatchSize(batchSize);
         if 
(pluginConfig.getOptional(PrometheusSinkOptions.FLUSH_INTERVAL).isPresent()) {
             long flushInterval = 
pluginConfig.get(PrometheusSinkOptions.FLUSH_INTERVAL);
             sinkConfig.setFlushInterval(flushInterval);
diff --git 
a/seatunnel-connectors-v2/connector-prometheus/src/test/java/org/apache/seatunnel/connectors/seatunnel/prometheus/PrometheusSinkConfigTest.java
 
b/seatunnel-connectors-v2/connector-prometheus/src/test/java/org/apache/seatunnel/connectors/seatunnel/prometheus/PrometheusSinkConfigTest.java
new file mode 100644
index 0000000000..5d47be0c51
--- /dev/null
+++ 
b/seatunnel-connectors-v2/connector-prometheus/src/test/java/org/apache/seatunnel/connectors/seatunnel/prometheus/PrometheusSinkConfigTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.prometheus;
+
+import org.apache.seatunnel.api.configuration.ReadonlyConfig;
+import 
org.apache.seatunnel.connectors.seatunnel.prometheus.config.PrometheusSinkConfig;
+import 
org.apache.seatunnel.connectors.seatunnel.prometheus.config.PrometheusSinkOptions;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+class PrometheusSinkConfigTest {
+
+    @Test
+    void shouldApplyBatchSizeDefaultWhenNotConfigured() {
+        Map<String, Object> map = new HashMap<>();
+        map.put("url", "http://localhost:9090/api/v1/write";);
+        map.put("key_label", "c_map");
+        map.put("key_value", "c_double");
+
+        PrometheusSinkConfig config = 
PrometheusSinkConfig.loadConfig(ReadonlyConfig.fromMap(map));
+
+        Assertions.assertEquals(
+                PrometheusSinkOptions.BATCH_SIZE.defaultValue().intValue(), 
config.getBatchSize());
+    }
+
+    @Test
+    void shouldUseConfiguredBatchSize() {
+        Map<String, Object> map = new HashMap<>();
+        map.put("url", "http://localhost:9090/api/v1/write";);
+        map.put("key_label", "c_map");
+        map.put("key_value", "c_double");
+        map.put("batch_size", 5);
+
+        PrometheusSinkConfig config = 
PrometheusSinkConfig.loadConfig(ReadonlyConfig.fromMap(map));
+
+        Assertions.assertEquals(5, config.getBatchSize());
+    }
+
+    @Test
+    void shouldRejectNonPositiveBatchSize() {
+        Map<String, Object> map = new HashMap<>();
+        map.put("url", "http://localhost:9090/api/v1/write";);
+        map.put("key_label", "c_map");
+        map.put("key_value", "c_double");
+        map.put("batch_size", 0);
+
+        Assertions.assertThrows(
+                Exception.class,
+                () -> 
PrometheusSinkConfig.loadConfig(ReadonlyConfig.fromMap(map)));
+    }
+}

Reply via email to