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

wanghailin 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 fbf78721ab [Fix][Connector-V2] Fix prometheus check time can not parse 
double value (#9311)
fbf78721ab is described below

commit fbf78721abc0e0c25c78c87fd0f2a3a990f882ce
Author: 老王 <[email protected]>
AuthorDate: Wed May 21 22:22:42 2025 +0800

    [Fix][Connector-V2] Fix prometheus check time can not parse double value 
(#9311)
---
 .../config/PrometheusSourceParameter.java          | 13 +++--
 .../prometheus/PrometheusParamCheckTest.java       | 68 ++++++++++++++++++++++
 2 files changed, 77 insertions(+), 4 deletions(-)

diff --git 
a/seatunnel-connectors-v2/connector-prometheus/src/main/java/org/apache/seatunnel/connectors/seatunnel/prometheus/config/PrometheusSourceParameter.java
 
b/seatunnel-connectors-v2/connector-prometheus/src/main/java/org/apache/seatunnel/connectors/seatunnel/prometheus/config/PrometheusSourceParameter.java
index d2dadc7660..b9783f2a58 100644
--- 
a/seatunnel-connectors-v2/connector-prometheus/src/main/java/org/apache/seatunnel/connectors/seatunnel/prometheus/config/PrometheusSourceParameter.java
+++ 
b/seatunnel-connectors-v2/connector-prometheus/src/main/java/org/apache/seatunnel/connectors/seatunnel/prometheus/config/PrometheusSourceParameter.java
@@ -23,6 +23,7 @@ import 
org.apache.seatunnel.connectors.seatunnel.http.config.HttpParameter;
 import org.apache.seatunnel.connectors.seatunnel.http.config.HttpRequestMethod;
 import 
org.apache.seatunnel.connectors.seatunnel.prometheus.Exception.PrometheusConnectorException;
 
+import java.time.Instant;
 import java.time.ZonedDateTime;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeParseException;
@@ -76,14 +77,18 @@ public class PrometheusSourceParameter extends 
HttpParameter {
         if (isValidISO8601(time)) {
             return time;
         }
-        throw new PrometheusConnectorException(
-                CommonErrorCode.UNSUPPORTED_DATA_TYPE, "unsupported time 
type");
+        try {
+            Double.parseDouble(time);
+            return time;
+        } catch (NumberFormatException e) {
+            throw new PrometheusConnectorException(
+                    CommonErrorCode.UNSUPPORTED_DATA_TYPE, "unsupported time 
type");
+        }
     }
 
     private boolean isValidISO8601(String dateTimeString) {
         try {
-            DateTimeFormatter formatter = DateTimeFormatter.ISO_INSTANT;
-            ZonedDateTime.parse(dateTimeString, formatter);
+            Instant.parse(dateTimeString);
             return true;
         } catch (DateTimeParseException e) {
             return false;
diff --git 
a/seatunnel-connectors-v2/connector-prometheus/src/test/java/org/apache/seatunnel/connectors/seatunnel/prometheus/PrometheusParamCheckTest.java
 
b/seatunnel-connectors-v2/connector-prometheus/src/test/java/org/apache/seatunnel/connectors/seatunnel/prometheus/PrometheusParamCheckTest.java
new file mode 100644
index 0000000000..33c001902d
--- /dev/null
+++ 
b/seatunnel-connectors-v2/connector-prometheus/src/test/java/org/apache/seatunnel/connectors/seatunnel/prometheus/PrometheusParamCheckTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.PrometheusSourceParameter;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class PrometheusParamCheckTest {
+
+    @Test
+    public void checkTime() {
+        final PrometheusSourceParameter prometheusSourceParameter = new 
PrometheusSourceParameter();
+        Map<String, Object> map1 = new HashMap<>();
+        map1.put("url", "http://localhost:9090";);
+        map1.put("query", "node_cpu_seconds_total");
+        map1.put("query_type", "Range");
+        map1.put("start", "2025-05-13T02:25:23Z");
+        map1.put("end", "2025-05-13T02:25:23.001Z");
+        
prometheusSourceParameter.buildWithConfig(ReadonlyConfig.fromMap(map1));
+
+        Map<String, Object> map2 = new HashMap<>();
+        map2.put("url", "http://localhost:9090";);
+        map2.put("query", "node_cpu_seconds_total");
+        map2.put("query_type", "Range");
+        map2.put("start", "2025-05-13T02:25:23Z");
+        map2.put("end", "2025-05-13T02:25:23.001");
+        Assertions.assertThrows(
+                Exception.class,
+                () -> 
prometheusSourceParameter.buildWithConfig(ReadonlyConfig.fromMap(map2)));
+
+        Map<String, Object> map3 = new HashMap<>();
+        map3.put("url", "http://localhost:9090";);
+        map3.put("query", "node_cpu_seconds_total");
+        map3.put("query_type", "Range");
+        map3.put("start", "1747103123.083");
+        map3.put("end", "1747106723");
+        
prometheusSourceParameter.buildWithConfig(ReadonlyConfig.fromMap(map3));
+
+        Map<String, Object> map4 = new HashMap<>();
+        map4.put("url", "http://localhost:9090";);
+        map4.put("query", "node_cpu_seconds_total");
+        map4.put("query_type", "Range");
+        map4.put("start", "CURRENT_TIMESTAMP");
+        map4.put("end", "CURRENT_TIMESTAMP");
+        
prometheusSourceParameter.buildWithConfig(ReadonlyConfig.fromMap(map4));
+    }
+}

Reply via email to