You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by GitBox <gi...@apache.org> on 2022/05/05 02:56:10 UTC

[GitHub] [incubator-shenyu] JooKS-me commented on a diff in pull request #3372: [type:Integration Test] Add metrics-plugin Integration Test

JooKS-me commented on code in PR #3372:
URL: https://github.com/apache/incubator-shenyu/pull/3372#discussion_r865520543


##########
shenyu-integrated-test/shenyu-integrated-test-http/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:     15s

Review Comment:
   ```suggestion
     scrape_interval: 15s
   ```



##########
shenyu-integrated-test/shenyu-integrated-test-common/src/main/java/org/apache/shenyu/integratedtest/common/helper/HttpHelper.java:
##########
@@ -48,6 +48,11 @@ public class HttpHelper {
      */
     public static final String GATEWAY_END_POINT = "http://localhost:9195";
 
+    /**
+     * The constant test metrics plugin.
+     */
+    public static final String METRICS_END_POINT = "http://localhost:8090";

Review Comment:
   Pls remove this.



##########
shenyu-integrated-test/shenyu-integrated-test-common/src/main/java/org/apache/shenyu/integratedtest/common/helper/HttpHelper.java:
##########
@@ -236,6 +241,26 @@ public <S> S getFromGateway(final String path, final Map<String, Object> headers
         }
     }
 
+    /**
+     * Send a get http request to shenyu gateway .
+     *
+     * @param <S>     response type
+     * @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 testMetricsPluginFromGateway(final String path, final Type type) throws IOException {

Review Comment:
   We can rename `testMetricsPluginFromGateway` to `getHttpService`, and a param `headers` can be added for more general use.



##########
shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/MetricsPluginTest.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.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.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+public final class MetricsPluginTest extends AbstractPluginDataInit {
+
+    private static final String TEST_CACHE_PATH = "/metrics";
+
+    @Test
+    public void testPass() throws ExecutionException, InterruptedException {
+        Future<String> resp = this.getService().submit(() -> HttpHelper.INSTANCE.testMetricsPluginFromGateway("http://shenyu-integrated-test-http:9090/api/v1/targets", String.class));

Review Comment:
   Maybe there should not be `shenyu-integrated-test-http` :)
   ```suggestion
           Future<String> resp = this.getService().submit(() -> HttpHelper.INSTANCE.testMetricsPluginFromGateway("http://localhost:9090/api/v1/targets", String.class));
   ```



##########
shenyu-integrated-test/shenyu-integrated-test-http/docker-compose.yml:
##########
@@ -87,13 +87,29 @@ services:
         condition: service_healthy
     ports:
       - "9195:9195"
+      - "8090:8090"
     networks:
       - shenyu
     healthcheck:
       test: [ "CMD", "wget", "http://shenyu-integrated-test-http:9195/actuator/health" ]
       timeout: 2s
       retries: 30
 
+  prometheus:
+    image: prom/prometheus:latest

Review Comment:
   We'd better use a fixed version to avoid problems that may occur in the future.



-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org