You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by jo...@apache.org on 2022/06/25 17:59:16 UTC
[incubator-shenyu] branch master updated: [type:Integration Test] Add metrics-plugin Integration Test (#3549)
This is an automated email from the ASF dual-hosted git repository.
jooks pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new d5f93dbc5 [type:Integration Test] Add metrics-plugin Integration Test (#3549)
d5f93dbc5 is described below
commit d5f93dbc515b0e632e46b97c23c491e7f40ac410
Author: 尔等同学 <37...@users.noreply.github.com>
AuthorDate: Sun Jun 26 01:59:08 2022 +0800
[type:Integration Test] Add metrics-plugin Integration Test (#3549)
* test metrics
* fix checkstyle
* fix ci
* test metrics
* test metrics
* fix checkstyle
* test metrics
* fix 'unexpected end of stream on Connection'
* fix Conflicts
* fix CI
* fix CI
* fix CI
* Update MetricsPluginTest.java
fix CI
* fix connect failed
* fix connect failed
* fix connect failed
* fix CI
Co-Authored-By: Kunshuai Zhu <jo...@gmail.com>
* update prometheus-java-client.version
* reactor code
* reactor code
* fix ci
Co-authored-by: Kunshuai Zhu <jo...@gmail.com>
---
.../integratedtest/common/helper/HttpHelper.java | 21 ++++++++++++
.../config/prometheus.yml | 26 ++++++++++++++
.../shenyu-integrated-test-http/docker-compose.yml | 16 +++++++++
.../shenyu-integrated-test-http/pom.xml | 8 +++++
.../src/main/resources/application.yml | 8 +++++
.../test/http/combination/MetricsPluginTest.java | 40 ++++++++++++++++++++++
6 files changed, 119 insertions(+)
diff --git a/shenyu-integrated-test/shenyu-integrated-test-common/src/main/java/org/apache/shenyu/integratedtest/common/helper/HttpHelper.java b/shenyu-integrated-test/shenyu-integrated-test-common/src/main/java/org/apache/shenyu/integratedtest/common/helper/HttpHelper.java
index 48b4eac25..a82543eb5 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-common/src/main/java/org/apache/shenyu/integratedtest/common/helper/HttpHelper.java
+++ b/shenyu-integrated-test/shenyu-integrated-test-common/src/main/java/org/apache/shenyu/integratedtest/common/helper/HttpHelper.java
@@ -264,4 +264,25 @@ public class HttpHelper {
Request request = requestBuilder.build();
return client.newCall(request).execute();
}
+
+ /**
+ * Send a get http request to shenyu gateway .
+ *
+ * @param <S> response type
+ * @param headers headers
+ * @param path path
+ * @param type type of response passed to {@link Gson#fromJson(String, Type)}
+ * @return response from gateway
+ * @throws IOException IO exception
+ */
+ public <S> S getHttpService(final String path, final Map<String, Object> headers, final Type type) throws IOException {
+ Response response = getHttpService(path, headers);
+ String respBody = Objects.requireNonNull(response.body()).string();
+ LOG.info("getHttpService({}) resp({})", path, respBody);
+ try {
+ return GSON.fromJson(respBody, type);
+ } catch (Exception e) {
+ return (S) respBody;
+ }
+ }
}
diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/config/prometheus.yml b/shenyu-integrated-test/shenyu-integrated-test-http/config/prometheus.yml
new file mode 100644
index 000000000..7584d8087
--- /dev/null
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/config/prometheus.yml
@@ -0,0 +1,26 @@
+# 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.
+
+global:
+ scrape_interval: 5s
+
+scrape_configs:
+ - job_name: 'Apache ShenYu'
+ static_configs:
+ - targets: ['shenyu-integrated-test-http:8090']
+ - job_name: "prometheus"
+ static_configs:
+ - targets: ["localhost:9090"]
diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/docker-compose.yml b/shenyu-integrated-test/shenyu-integrated-test-http/docker-compose.yml
index 5fb73e99c..22fdfb1d3 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-http/docker-compose.yml
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/docker-compose.yml
@@ -87,6 +87,7 @@ services:
condition: service_healthy
ports:
- "9195:9195"
+ - "8090:8090"
networks:
- shenyu
healthcheck:
@@ -94,6 +95,21 @@ services:
timeout: 2s
retries: 30
+ shenyu-prometheus:
+ image: prom/prometheus:v2.35.0
+ container_name: shenyu-prometheus
+ ports:
+ - "9090:9090"
+ depends_on:
+ shenyu-integrated-test-http:
+ condition: service_healthy
+ networks:
+ - shenyu
+ volumes:
+ - type: bind
+ source: ./config/prometheus.yml
+ target: /etc/prometheus/prometheus.yml
+
networks:
shenyu:
name: shenyu
diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/pom.xml b/shenyu-integrated-test/shenyu-integrated-test-http/pom.xml
index 6c4ccbe49..bf6b19cab 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-http/pom.xml
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/pom.xml
@@ -162,6 +162,14 @@
</dependency>
<!-- apache shenyu mqtt plugin end-->
+ <!--shenyu metrics plugin start-->
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-spring-boot-starter-plugin-metrics</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <!--shenyu metrics plugin end-->
+
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-integrated-test-common</artifactId>
diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/src/main/resources/application.yml b/shenyu-integrated-test/shenyu-integrated-test-http/src/main/resources/application.yml
index 7f6fae9af..b7d813ba9 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-http/src/main/resources/application.yml
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/src/main/resources/application.yml
@@ -33,6 +33,14 @@ management:
enabled: false
shenyu:
+ metrics:
+ enabled: true
+ name: prometheus
+ host: 0.0.0.0
+ port: 8090
+ jmxConfig:
+ props:
+ jvm_enabled: true
switchConfig:
local: true
cross:
diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/MetricsPluginTest.java b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/MetricsPluginTest.java
new file mode 100644
index 000000000..bac45bbd8
--- /dev/null
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/MetricsPluginTest.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.shenyu.integrated.test.http.combination;
+
+import org.apache.shenyu.integratedtest.common.AbstractPluginDataInit;
+import org.apache.shenyu.integratedtest.common.helper.HttpHelper;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+public final class MetricsPluginTest extends AbstractPluginDataInit {
+
+ @Test
+ public void testPass() throws ExecutionException, InterruptedException {
+ Map<String, Object> headers = new HashMap<>();
+ Future<String> resp = this.getService().submit(() -> HttpHelper.INSTANCE.getHttpService("http://localhost:9090/api/v1/targets", headers, String.class));
+ assertFalse(resp.get().contains("down"));
+ }
+
+}