You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by me...@apache.org on 2020/11/30 09:17:24 UTC

[apisix-dashboard] branch master updated: test: add e2e test cases for route with trace plugin (#903)

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

membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 09dee7f  test: add e2e test cases for route with trace plugin (#903)
09dee7f is described below

commit 09dee7f38f29579bc20a90f6e3dae4d2eefbeb0b
Author: nic-chen <33...@users.noreply.github.com>
AuthorDate: Mon Nov 30 17:17:14 2020 +0800

    test: add e2e test cases for route with trace plugin (#903)
    
    related issue: #636
---
 api/test/docker/apisix_config.yaml           |  47 ++++++++
 api/test/docker/docker-compose.yaml          |  11 ++
 api/test/e2e/route_with_trace_plugin_test.go | 159 +++++++++++++++++++++++++++
 3 files changed, 217 insertions(+)

diff --git a/api/test/docker/apisix_config.yaml b/api/test/docker/apisix_config.yaml
index c8e60e0..540cacd 100644
--- a/api/test/docker/apisix_config.yaml
+++ b/api/test/docker/apisix_config.yaml
@@ -41,3 +41,50 @@ apisix:
 
 nginx_config:
   error_log_level: "debug"
+
+plugins:                          # plugin list (sorted in alphabetical order)
+  - api-breaker
+  - authz-keycloak
+  - basic-auth
+  - batch-requests
+  - consumer-restriction
+  - cors
+  - echo
+  - fault-injection
+  - grpc-transcode
+  - hmac-auth
+  - http-logger
+  - ip-restriction
+  - jwt-auth
+  - kafka-logger
+  - key-auth
+  - limit-conn
+  - limit-count
+  - limit-req
+  - node-status
+  - openid-connect
+  - prometheus
+  - proxy-cache
+  - proxy-mirror
+  - proxy-rewrite
+  - redirect
+  - referer-restriction
+  - request-id
+  - request-validation
+  - response-rewrite
+  - serverless-post-function
+  - serverless-pre-function
+  - skywalking
+  - sls-logger
+  - syslog
+  - tcp-logger
+  - udp-logger
+  - uri-blocker
+  - wolf-rbac
+  - zipkin
+
+plugin_attr:
+  skywalking:
+    service_name: APISIX
+    service_instance_name: "APISIX Instance Name"
+    endpoint_addr: http://172.16.238.50:12800
diff --git a/api/test/docker/docker-compose.yaml b/api/test/docker/docker-compose.yaml
index 91aec31..d72dc3c 100644
--- a/api/test/docker/docker-compose.yaml
+++ b/api/test/docker/docker-compose.yaml
@@ -186,6 +186,17 @@ services:
       apisix_dashboard_e2e:
         ipv4_address: 172.16.238.40
 
+  skywalking:
+    image: apache/skywalking-oap-server
+    restart: always
+    ports:
+      - '1234:1234/tcp'
+      - '11800:11800/tcp'
+      - '12800:12800/tcp'
+    networks:
+      apisix_dashboard_e2e:
+        ipv4_address: 172.16.238.50
+
 networks:
   apisix_dashboard_e2e:
     driver: bridge
diff --git a/api/test/e2e/route_with_trace_plugin_test.go b/api/test/e2e/route_with_trace_plugin_test.go
new file mode 100644
index 0000000..d21ebef
--- /dev/null
+++ b/api/test/e2e/route_with_trace_plugin_test.go
@@ -0,0 +1,159 @@
+/*
+ * 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 e2e
+
+import (
+	"net/http"
+	"testing"
+	"time"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestRoute_With_Plugin_Skywalking(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc:     "make sure the route is not created ",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			ExpectStatus: http.StatusNotFound,
+			ExpectBody:   `{"error_msg":"404 Route Not Found"}`,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"skywalking": {
+						"sample_ratio": 1 
+					}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": [{
+						"host": "172.16.238.20",
+						"port": 1981,
+						"weight": 1
+					}]
+				}
+			}`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "tiger skywalking",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "hello world",
+			Sleep:        sleepTime,
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+
+	// sleep for process log
+	time.Sleep(4 * time.Second)
+
+	// verify by checking log
+	logContent := readAPISIXErrorLog(t)
+	assert.Contains(t, logContent, "segments reported")
+
+	// clean log
+	cleanAPISIXErrorLog(t)
+
+	tests = []HttpTestCase{
+		{
+			caseDesc: "update route to change sample ratio",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"skywalking": {
+						"sample_ratio": 0.00001
+					}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": [{
+						"host": "172.16.238.20",
+						"port": 1981,
+						"weight": 1
+					}]
+				}
+			}`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "access the route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "hello world",
+			Sleep:        sleepTime,
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+
+	// sleep for process log
+	time.Sleep(4 * time.Second)
+
+	// verify by checking log
+	logContent = readAPISIXErrorLog(t)
+	assert.Contains(t, logContent, "miss sampling, ignore")
+
+	// clean log
+	cleanAPISIXErrorLog(t)
+
+	tests = []HttpTestCase{
+		{
+			caseDesc:     "delete route",
+			Object:       MangerApiExpect(t),
+			Method:       http.MethodDelete,
+			Path:         "/apisix/admin/routes/r1",
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "make sure the route has been deleted",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello_",
+			ExpectStatus: http.StatusNotFound,
+			ExpectBody:   `{"error_msg":"404 Route Not Found"}`,
+			Sleep:        sleepTime,
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}