You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by mo...@apache.org on 2023/05/23 06:33:12 UTC

[apisix] branch master updated: chore(ci): use real clickhouse server in ci (#9437)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 6786d08b2 chore(ci): use real clickhouse server in ci (#9437)
6786d08b2 is described below

commit 6786d08b20c3b73dcb31b91e963b164ebbff5d85
Author: Abhishek Choudhary <sh...@gmail.com>
AuthorDate: Tue May 23 12:03:06 2023 +0530

    chore(ci): use real clickhouse server in ci (#9437)
---
 ci/init-plugin-test-service.sh   |  3 ++
 ci/pod/docker-compose.plugin.yml | 17 ++++++++++
 t/plugin/clickhouse-logger.t     | 67 ++++++++++++++++++++--------------------
 3 files changed, 53 insertions(+), 34 deletions(-)

diff --git a/ci/init-plugin-test-service.sh b/ci/init-plugin-test-service.sh
index fbabe1ca1..39feb410c 100755
--- a/ci/init-plugin-test-service.sh
+++ b/ci/init-plugin-test-service.sh
@@ -51,6 +51,9 @@ after() {
     # configure keycloak
     docker exec apisix_keycloak bash /tmp/kcadm_configure_cas.sh
     docker exec apisix_keycloak bash /tmp/kcadm_configure_university.sh
+
+    echo 'CREATE TABLE default.test (`host` String, `client_ip` String, `route_id` String, `service_id` String, `@timestamp` String, PRIMARY KEY(`@timestamp`)) ENGINE = MergeTree()' | curl 'http://localhost:8123/' --data-binary @-
+    echo 'CREATE TABLE default.test (`host` String, `client_ip` String, `route_id` String, `service_id` String, `@timestamp` String, PRIMARY KEY(`@timestamp`)) ENGINE = MergeTree()' | curl 'http://localhost:8124/' --data-binary @-
 }
 
 before() {
diff --git a/ci/pod/docker-compose.plugin.yml b/ci/pod/docker-compose.plugin.yml
index 0979e1e61..5f7fa7f1d 100644
--- a/ci/pod/docker-compose.plugin.yml
+++ b/ci/pod/docker-compose.plugin.yml
@@ -326,6 +326,22 @@ services:
     networks:
       vector_net:
 
+  clickhouse:
+    image: clickhouse/clickhouse-server:23.4.2-alpine
+    container_name: clickhouse
+    ports:
+      - '8123:8123'
+    networks:
+      clickhouse_net:
+
+  clickhouse2:
+    image: clickhouse/clickhouse-server:23.4.2-alpine
+    container_name: clickhouse2
+    ports:
+      - '8124:8123'
+    networks:
+      clickhouse_net:
+
 networks:
   apisix_net:
   kafka_net:
@@ -333,3 +349,4 @@ networks:
   rocketmq_net:
   opa_net:
   vector_net:
+  clickhouse_net:
diff --git a/t/plugin/clickhouse-logger.t b/t/plugin/clickhouse-logger.t
index 3aa28190a..43ce54cd8 100644
--- a/t/plugin/clickhouse-logger.t
+++ b/t/plugin/clickhouse-logger.t
@@ -183,13 +183,11 @@ passed
                         "plugins": {
                             "clickhouse-logger": {
                                 "user": "default",
-                                "password": "a",
+                                "password": "",
                                 "database": "default",
-                                "logtable": "t",
-                                "endpoint_addrs": ["http://127.0.0.1:1980/clickhouse_logger_server",
-                                                  "http://127.0.0.1:10420/clickhouse-logger/test1"],
-                                "batch_max_size":1,
-                                "inactive_timeout":1
+                                "logtable": "test",
+                                "endpoint_addrs": ["http://127.0.0.1:8123",
+                                                  "http://127.0.0.1:8124"]
                             }
                         },
                         "upstream": {
@@ -214,21 +212,24 @@ passed
 
 
 
-=== TEST 6: access local server
+=== TEST 6: hit route
 --- request
 GET /opentracing
---- response_body
-opentracing
---- error_log
-clickhouse body: INSERT INTO t FORMAT JSONEachRow
-clickhouse headers: x-clickhouse-key:a
-clickhouse headers: x-clickhouse-user:default
-clickhouse headers: x-clickhouse-database:default
+--- error_code: 200
 --- wait: 5
 
 
 
-=== TEST 7: log format in plugin
+=== TEST 7: get log
+--- exec
+echo "select * from default.test" | curl 'http://localhost:8123/' --data-binary @-
+echo "select * from default.test" | curl 'http://localhost:8124/' --data-binary @-
+--- response_body_like
+.*127.0.0.1.*1.*
+
+
+
+=== TEST 8: use single clickhouse server
 --- config
     location /t {
         content_by_lua_block {
@@ -239,24 +240,19 @@ clickhouse headers: x-clickhouse-database:default
                         "plugins": {
                             "clickhouse-logger": {
                                 "user": "default",
-                                "password": "a",
+                                "password": "",
                                 "database": "default",
-                                "logtable": "t",
-                                "endpoint_addrs": ["http://127.0.0.1:10420/clickhouse-logger/test1"],
-                                "log_format": {
-                                    "vip": "$remote_addr"
-                                },
-                                "batch_max_size":1,
-                                "inactive_timeout":1
+                                "logtable": "test",
+                                "endpoint_addr": "http://127.0.0.1:8123"
                             }
                         },
                         "upstream": {
                             "nodes": {
-                                "127.0.0.1:1980": 1
+                                "127.0.0.1:1982": 1
                             },
                             "type": "roundrobin"
                         },
-                        "uri": "/hello"
+                        "uri": "/opentracing"
                 }]]
                 )
 
@@ -266,18 +262,21 @@ clickhouse headers: x-clickhouse-database:default
             ngx.say(body)
         }
     }
---- request
-GET /t
 --- response_body
 passed
 
 
 
-=== TEST 8: hit route and report logger
+=== TEST 9: hit route
 --- request
-GET /hello
---- response_body
-hello world
---- wait: 1.5
---- error_log eval
-qr/clickhouse body: INSERT INTO t FORMAT JSONEachRow \{.*"vip":"127.0.0.1".*\}/
+GET /opentracing
+--- error_code: 200
+--- wait: 5
+
+
+
+=== TEST 10: get log
+--- exec
+echo "select * from default.test" | curl 'http://localhost:8123/' --data-binary @-
+--- response_body_like
+.*127.0.0.1.*1.*