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

mikexue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/eventmesh.git


The following commit(s) were added to refs/heads/master by this push:
     new d3f688dd0 [ISSUE #4415] Add Promethus source connector (#4493)
d3f688dd0 is described below

commit d3f688dd09d51e4dee275cae1d334f4c6138ae59
Author: willimpo <[email protected]>
AuthorDate: Mon Oct 23 00:30:28 2023 +0800

    [ISSUE #4415] Add Promethus source connector (#4493)
    
    * Add Promethus source connector
    
    * Add Promethus source connector
    
    * Add Promethus source connector
    
    * Add Promethus source connector
    
    * Add Promethus source connector
    
    * Add Promethus source connector
    
    * Add Promethus source connector
    
    * Add Promethus source connector
---
 build.gradle                                       |   2 +
 .../eventmesh-connector-prometheus/build.gradle    |  25 +++
 .../gradle.properties                              |  18 ++
 .../prometheus/config/PrometheusServerConfig.java  |  33 ++++
 .../prometheus/model/QueryPrometheusReq.java       |  32 ++++
 .../prometheus/model/QueryPrometheusRsp.java       |  29 ++++
 .../connector/prometheus/model/ResponseData.java   |  31 ++++
 .../prometheus/server/PrometheusConnectServer.java |  39 +++++
 .../source/config/PrometheusSourceConfig.java      |  30 ++++
 .../source/config/SourceConnectorConfig.java       |  40 +++++
 .../connector/PrometheusSourceConnector.java       | 192 +++++++++++++++++++++
 .../src/main/resources/server-config.yml           |  19 ++
 .../src/main/resources/source-config.yml           |  35 ++++
 settings.gradle                                    |   1 +
 tools/dependency-check/known-dependencies.txt      |   1 +
 15 files changed, 527 insertions(+)

diff --git a/build.gradle b/build.gradle
index 718e71366..432d410ca 100644
--- a/build.gradle
+++ b/build.gradle
@@ -565,6 +565,8 @@ subprojects {
             dependency "com.alibaba:fastjson:1.2.83"
 
             dependency "software.amazon.awssdk:s3:2.20.29"
+            dependency "com.github.rholder:guava-retrying:2.0.0"
+
         }
     }
 }
diff --git a/eventmesh-connectors/eventmesh-connector-prometheus/build.gradle 
b/eventmesh-connectors/eventmesh-connector-prometheus/build.gradle
new file mode 100644
index 000000000..d92797a8c
--- /dev/null
+++ b/eventmesh-connectors/eventmesh-connector-prometheus/build.gradle
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+dependencies {
+    implementation project(":eventmesh-openconnect:eventmesh-openconnect-java")
+    implementation 'org.apache.httpcomponents:httpclient'
+    implementation 'com.github.rholder:guava-retrying'
+    implementation 'com.alibaba:fastjson'
+    compileOnly 'org.projectlombok:lombok'
+    annotationProcessor 'org.projectlombok:lombok'
+}
\ No newline at end of file
diff --git 
a/eventmesh-connectors/eventmesh-connector-prometheus/gradle.properties 
b/eventmesh-connectors/eventmesh-connector-prometheus/gradle.properties
new file mode 100644
index 000000000..d3e3811f5
--- /dev/null
+++ b/eventmesh-connectors/eventmesh-connector-prometheus/gradle.properties
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+pluginType=connector
+pluginName=prometheus
\ No newline at end of file
diff --git 
a/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/config/PrometheusServerConfig.java
 
b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/config/PrometheusServerConfig.java
new file mode 100644
index 000000000..3222e2821
--- /dev/null
+++ 
b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/config/PrometheusServerConfig.java
@@ -0,0 +1,33 @@
+/*
+ * 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.eventmesh.connector.prometheus.config;
+
+import org.apache.eventmesh.openconnect.api.config.Config;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class PrometheusServerConfig extends Config {
+
+    private boolean sourceEnable;
+
+    private boolean sinkEnable;
+
+}
diff --git 
a/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/model/QueryPrometheusReq.java
 
b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/model/QueryPrometheusReq.java
new file mode 100644
index 000000000..cdc1190af
--- /dev/null
+++ 
b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/model/QueryPrometheusReq.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.eventmesh.connector.prometheus.model;
+
+import lombok.Data;
+
+@Data
+public class QueryPrometheusReq {
+
+    private String query;
+
+    private Long start;
+
+    private Long end;
+
+    private String step;
+}
diff --git 
a/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/model/QueryPrometheusRsp.java
 
b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/model/QueryPrometheusRsp.java
new file mode 100644
index 000000000..25a114767
--- /dev/null
+++ 
b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/model/QueryPrometheusRsp.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.eventmesh.connector.prometheus.model;
+
+import lombok.Data;
+
+@Data
+public class QueryPrometheusRsp {
+
+    private String status;
+
+    private ResponseData data;
+
+}
diff --git 
a/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/model/ResponseData.java
 
b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/model/ResponseData.java
new file mode 100644
index 000000000..73e7a45b7
--- /dev/null
+++ 
b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/model/ResponseData.java
@@ -0,0 +1,31 @@
+/*
+ * 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.eventmesh.connector.prometheus.model;
+
+import java.util.List;
+
+import lombok.Data;
+
+@Data
+public class ResponseData {
+
+    private String resultType;
+
+    private List<String> result;
+
+}
diff --git 
a/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/server/PrometheusConnectServer.java
 
b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/server/PrometheusConnectServer.java
new file mode 100644
index 000000000..88f6c5572
--- /dev/null
+++ 
b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/server/PrometheusConnectServer.java
@@ -0,0 +1,39 @@
+/*
+ * 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.eventmesh.connector.prometheus.server;
+
+import org.apache.eventmesh.connector.prometheus.config.PrometheusServerConfig;
+import 
org.apache.eventmesh.connector.prometheus.source.connector.PrometheusSourceConnector;
+import org.apache.eventmesh.openconnect.Application;
+import org.apache.eventmesh.openconnect.util.ConfigUtil;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class PrometheusConnectServer {
+
+    public static void main(String[] args) throws Exception {
+
+        PrometheusServerConfig serverConfig = 
ConfigUtil.parse(PrometheusServerConfig.class, "server-config.yml");
+
+        if (serverConfig.isSourceEnable()) {
+            Application prometheusSourceApp = new Application();
+            prometheusSourceApp.run(PrometheusSourceConnector.class);
+        }
+    }
+}
diff --git 
a/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/source/config/PrometheusSourceConfig.java
 
b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/source/config/PrometheusSourceConfig.java
new file mode 100644
index 000000000..292b7e62f
--- /dev/null
+++ 
b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/source/config/PrometheusSourceConfig.java
@@ -0,0 +1,30 @@
+/*
+ * 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.eventmesh.connector.prometheus.source.config;
+
+import org.apache.eventmesh.openconnect.api.config.SourceConfig;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class PrometheusSourceConfig extends SourceConfig {
+
+    public SourceConnectorConfig connectorConfig;
+}
diff --git 
a/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/source/config/SourceConnectorConfig.java
 
b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/source/config/SourceConnectorConfig.java
new file mode 100644
index 000000000..7e8b7ba93
--- /dev/null
+++ 
b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/source/config/SourceConnectorConfig.java
@@ -0,0 +1,40 @@
+/*
+ * 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.eventmesh.connector.prometheus.source.config;
+
+import lombok.Data;
+
+@Data
+public class SourceConnectorConfig {
+
+    private String connectorName;
+
+    private String connectorId;
+
+    private String address;
+
+    private String api;
+
+    private Long initTime;
+
+    private String query;
+
+    private Integer interval;
+
+    private String step;
+}
\ No newline at end of file
diff --git 
a/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/source/connector/PrometheusSourceConnector.java
 
b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/source/connector/PrometheusSourceConnector.java
new file mode 100644
index 000000000..b5bd85fc1
--- /dev/null
+++ 
b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/source/connector/PrometheusSourceConnector.java
@@ -0,0 +1,192 @@
+/*
+ * 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.eventmesh.connector.prometheus.source.connector;
+
+import org.apache.eventmesh.connector.prometheus.model.QueryPrometheusReq;
+import org.apache.eventmesh.connector.prometheus.model.QueryPrometheusRsp;
+import 
org.apache.eventmesh.connector.prometheus.source.config.PrometheusSourceConfig;
+import org.apache.eventmesh.openconnect.api.config.Config;
+import org.apache.eventmesh.openconnect.api.connector.ConnectorContext;
+import org.apache.eventmesh.openconnect.api.connector.SourceConnectorContext;
+import org.apache.eventmesh.openconnect.api.source.Source;
+import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord;
+import org.apache.eventmesh.openconnect.offsetmgmt.api.data.RecordOffset;
+import org.apache.eventmesh.openconnect.offsetmgmt.api.data.RecordPartition;
+
+import org.apache.http.HttpStatus;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.util.EntityUtils;
+
+import java.nio.charset.StandardCharsets;
+import java.text.MessageFormat;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.github.rholder.retry.Attempt;
+import com.github.rholder.retry.RetryListener;
+import com.github.rholder.retry.Retryer;
+import com.github.rholder.retry.RetryerBuilder;
+import com.github.rholder.retry.StopStrategies;
+import com.github.rholder.retry.WaitStrategies;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class PrometheusSourceConnector implements Source {
+
+    private static final int MAX_RETRY_TIME = 3;
+
+    private static final int FIXED_WAIT_SECOND = 1;
+
+    private final Retryer<Boolean> retryer =
+        RetryerBuilder.<Boolean>newBuilder()
+            .retryIfException()
+            .retryIfResult(res -> !res)
+            .withWaitStrategy(WaitStrategies.fixedWait(FIXED_WAIT_SECOND, 
TimeUnit.SECONDS))
+            .withStopStrategy(StopStrategies.stopAfterAttempt(MAX_RETRY_TIME))
+            .withRetryListener(
+                new RetryListener() {
+                    @Override
+                    public <V> void onRetry(Attempt<V> attempt) {
+                        long times = attempt.getAttemptNumber();
+                        log.warn("retry invoke http,times={}", times);
+                    }
+                })
+            .build();
+
+    private PrometheusSourceConfig sourceConfig;
+
+    private CloseableHttpClient httpClient;
+
+    private QueryPrometheusReq queryPrometheusReq;
+
+    private Long initTime;
+
+    private Long startTime;
+
+    private Integer interval;
+
+    private String url;
+
+    @Override
+    public Class<? extends Config> configClass() {
+        return PrometheusSourceConfig.class;
+    }
+
+    @Override
+    public void init(Config config) {
+        this.sourceConfig = (PrometheusSourceConfig) config;
+
+        doInit();
+    }
+
+    @Override
+    public void init(ConnectorContext connectorContext) {
+        SourceConnectorContext sourceConnectorContext = 
(SourceConnectorContext) connectorContext;
+        this.sourceConfig = (PrometheusSourceConfig) 
sourceConnectorContext.getSourceConfig();
+
+        doInit();
+    }
+
+    private void doInit() {
+        queryPrometheusReq = new QueryPrometheusReq();
+        
queryPrometheusReq.setQuery(sourceConfig.getConnectorConfig().getQuery());
+        
queryPrometheusReq.setStep(sourceConfig.getConnectorConfig().getStep());
+
+        interval = sourceConfig.getConnectorConfig().getInterval();
+        initTime = sourceConfig.getConnectorConfig().getInitTime();
+
+        url = MessageFormat.format("{0}/{1}", 
sourceConfig.getConnectorConfig().getAddress(), 
sourceConfig.getConnectorConfig().getApi());
+
+        // TODO: replace with feature #4481
+        httpClient = HttpClientBuilder.create().build();
+    }
+
+    @Override
+    public void start() {
+        log.info("prometheus source connector start.");
+        startTime = initTime != null ? initTime : System.currentTimeMillis() / 
1000;
+    }
+
+    @Override
+    public void commit(ConnectRecord record) {
+        startTime += interval;
+    }
+
+    @Override
+    public String name() {
+        return this.sourceConfig.getConnectorConfig().getConnectorName();
+    }
+
+    @Override
+    public void stop() {
+        log.info("prometheus source connector stop.");
+    }
+
+    @Override
+    public List<ConnectRecord> poll() {
+        try {
+            if (startTime > System.currentTimeMillis() / 1000 - interval) {
+                Thread.sleep(interval * 1000);
+            }
+
+            AtomicReference<CloseableHttpResponse> response = null;
+            retryer.call(() -> {
+                try {
+                    queryPrometheusReq.setStart(startTime);
+                    queryPrometheusReq.setEnd(startTime + interval);
+
+                    HttpPost httpPost = new HttpPost(url);
+                    httpPost.setEntity(new 
StringEntity(JSON.toJSONString(queryPrometheusReq), 
ContentType.APPLICATION_JSON));
+                    response.set(httpClient.execute(httpPost));
+                    return response.get().getStatusLine().getStatusCode() == 
HttpStatus.SC_OK;
+                } catch (Exception e) {
+                    log.error("invoke http failed", e);
+                    return false;
+                }
+            });
+
+            String result = EntityUtils.toString(response.get().getEntity(), 
StandardCharsets.UTF_8);
+            QueryPrometheusRsp responseData = JSONObject.parseObject(result, 
QueryPrometheusRsp.class);
+            List<ConnectRecord> connectRecords =
+                
responseData.getData().getResult().stream().map(this::assembleRecord).collect(Collectors.toList());
+
+            return connectRecords;
+        } catch (Exception e) {
+            log.error("failed to poll message from prometheus", e);
+            return null;
+        }
+    }
+
+    private ConnectRecord assembleRecord(String data) {
+        Long timestamp = System.currentTimeMillis();
+        RecordPartition recordPartition = new RecordPartition();
+        RecordOffset recordOffset = new RecordOffset();
+
+        return new ConnectRecord(recordPartition, recordOffset, timestamp, 
data);
+    }
+}
diff --git 
a/eventmesh-connectors/eventmesh-connector-prometheus/src/main/resources/server-config.yml
 
b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/resources/server-config.yml
new file mode 100644
index 000000000..0cd7b5b5a
--- /dev/null
+++ 
b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/resources/server-config.yml
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+
+sourceEnable: true
+sinkEnable: false
diff --git 
a/eventmesh-connectors/eventmesh-connector-prometheus/src/main/resources/source-config.yml
 
b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/resources/source-config.yml
new file mode 100644
index 000000000..5ad5e9bcc
--- /dev/null
+++ 
b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/resources/source-config.yml
@@ -0,0 +1,35 @@
+#
+# 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.
+#
+
+pubSubConfig:
+    meshAddress: 127.0.0.1:10000
+    subject: TopicTest
+    idc: FT
+    env: PRD
+    group: prometheusSource
+    appId: 5032
+    userName: prometheusSourceUser
+    passWord: prometheusPassWord
+connectorConfig:
+    connectorName: prometheusSource
+    connectorId: prometheusSourceId
+    address: https://127.0.0.1:9090
+    api: /api/v1/query_range
+    initTime: 1237507200
+    query: up
+    interval: 60
+    step: 1s
\ No newline at end of file
diff --git a/settings.gradle b/settings.gradle
index 42e7b6ec6..a1b63fd37 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -41,6 +41,7 @@ include 'eventmesh-connectors:eventmesh-connector-knative'
 include 'eventmesh-connectors:eventmesh-connector-jdbc'
 include 'eventmesh-connectors:eventmesh-connector-file'
 include 'eventmesh-connectors:eventmesh-connector-spring'
+include 'eventmesh-connectors:eventmesh-connector-prometheus'
 
 include 'eventmesh-storage-plugin:eventmesh-storage-api'
 include 'eventmesh-storage-plugin:eventmesh-storage-standalone'
diff --git a/tools/dependency-check/known-dependencies.txt 
b/tools/dependency-check/known-dependencies.txt
index 3a7af90a6..7dd456ae7 100644
--- a/tools/dependency-check/known-dependencies.txt
+++ b/tools/dependency-check/known-dependencies.txt
@@ -220,3 +220,4 @@ zookeeper-3.7.1.jar
 zookeeper-jute-3.7.1.jar
 zstd-jni-1.5.0-2.jar
 zstd-jni-1.5.2-2.jar
+guava-retrying-2.0.0.jar
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to