This is an automated email from the ASF dual-hosted git repository.
liutianyou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
The following commit(s) were added to refs/heads/master by this push:
new 2288d8e900 [e2e] add e2e test for k8s monitor (#3280)
2288d8e900 is described below
commit 2288d8e90091d0464952fa593ed82146ca69abfd
Author: liutianyou <[email protected]>
AuthorDate: Tue Apr 22 23:57:01 2025 +0800
[e2e] add e2e test for k8s monitor (#3280)
Co-authored-by: aias00 <[email protected]>
Co-authored-by: tomsun28 <[email protected]>
Co-authored-by: Jast <[email protected]>
---
.github/workflows/monitor-e2e-test.yml | 53 +++++++++++++
.gitignore | 2 +
e2e/k8s/data/config/k3s.yaml | 39 ++++++++++
e2e/k8s/data/config/node-token.txt | 1 +
e2e/k8s/data/create_k8s_monitor_data.json | 37 +++++++++
e2e/k8s/data/testsuite.yaml | 69 +++++++++++++++++
e2e/k8s/docker-compose.yml | 123 ++++++++++++++++++++++++++++++
7 files changed, 324 insertions(+)
diff --git a/.github/workflows/monitor-e2e-test.yml
b/.github/workflows/monitor-e2e-test.yml
new file mode 100644
index 0000000000..a07b7100d1
--- /dev/null
+++ b/.github/workflows/monitor-e2e-test.yml
@@ -0,0 +1,53 @@
+# 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.
+
+# This workflow will build a Java project with Maven
+# For more information see:
https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
+
+name: Monitor E2E Test
+
+
+on:
+ schedule:
+ # trigger at 01:00 everyday
+ - cron: '0 1 * * *'
+ push:
+ branches: [ action* ]
+jobs:
+ check-license-header:
+ name: Monitor E2E Test
+ runs-on: ubuntu-latest
+ timeout-minutes: 10
+ steps:
+ - uses: actions/checkout@v4
+ - uses: ./script/ci/github-actions/setup-deps
+ - name: Build with Maven
+ run: mvn clean -B package -Prelease -Dmaven.test.skip=true --file
pom.xml
+ - name: Build Image
+ uses: docker/build-push-action@v3
+ with:
+ context: ./dist
+ file: ./script/docker/server/Dockerfile
+ push: false
+ tags: apache/hertzbeat:test
+ - name: Run K8s Monitor E2E Test
+ run: |
+ sudo curl -L
https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-linux-x86_64
-o /usr/local/bin/docker-compose
+ sudo chmod u+x /usr/local/bin/docker-compose
+ cd e2e/k8s
+ sudo docker-compose version
+ sudo docker-compose up --exit-code-from testing --remove-orphans
diff --git a/.gitignore b/.gitignore
index 664bd30e14..d5f9897078 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,6 +13,8 @@ package-lock.json
jdk/
data/
+!/e2e/**/data/
+
### STS ###
.apt_generated
.classpath
diff --git a/e2e/k8s/data/config/k3s.yaml b/e2e/k8s/data/config/k3s.yaml
new file mode 100644
index 0000000000..1268c07d58
--- /dev/null
+++ b/e2e/k8s/data/config/k3s.yaml
@@ -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.
+
+# This workflow will build a Java project with Maven
+# For more information see:
https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
+
+apiVersion: v1
+clusters:
+- cluster:
+ certificate-authority-data:
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJkakNDQVIyZ0F3SUJBZ0lCQURBS0JnZ3Foa2pPUFFRREFqQWpNU0V3SHdZRFZRUUREQmhyTTNNdGMyVnkKZG1WeUxXTmhRREUzTkRVeU5ESTROamd3SGhjTk1qVXdOREl4TVRNME1UQTRXaGNOTXpVd05ERTVNVE0wTVRBNApXakFqTVNFd0h3WURWUVFEREJock0zTXRjMlZ5ZG1WeUxXTmhRREUzTkRVeU5ESTROamd3V1RBVEJnY3Foa2pPClBRSUJCZ2dxaGtqT1BRTUJCd05DQUFUR2U2SW5hQko4RGRiQVdmZTRNM09yS3ZTR1IvWkROS0JJV2lMejZXckcKYmh4Mm5ncHJFQjhRYThEWDZocGRCVkI1RmN3L1hwTXZjRnNCeFh3MThPNkdvMEl3UURBT0JnTlZI
[...]
+ server: https://172.29.0.11:6443
+ name: default
+contexts:
+- context:
+ cluster: default
+ user: default
+ name: default
+current-context: default
+kind: Config
+preferences: {}
+users:
+- name: default
+ user:
+ client-certificate-data:
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJrVENDQVRlZ0F3SUJBZ0lJZm5OdzUyby9ybDB3Q2dZSUtvWkl6ajBFQXdJd0l6RWhNQjhHQTFVRUF3d1kKYXpOekxXTnNhV1Z1ZEMxallVQXhOelExTWpReU9EWTRNQjRYRFRJMU1EUXlNVEV6TkRFd09Gb1hEVEkyTURReQpNVEV6TkRFd09Gb3dNREVYTUJVR0ExVUVDaE1PYzNsemRHVnRPbTFoYzNSbGNuTXhGVEFUQmdOVkJBTVRESE41CmMzUmxiVHBoWkcxcGJqQlpNQk1HQnlxR1NNNDlBZ0VHQ0NxR1NNNDlBd0VIQTBJQUJHa3UxWDQvRGNMU1h4cXcKSzczdGhMUFd5Y3JCendrL3ZMbzkzMTZ0dXNXRWE4WnNMdytnYk5wWEVOSFNxQk8zdGcrYUFSdGhWakF
[...]
+ client-key-data:
LS0tLS1CRUdJTiBFQyBQUklWQVRFIEtFWS0tLS0tCk1IY0NBUUVFSUpMOGJrS1FMbEdZWUE0Ny9Lek9CRm5iZnI0NGQ5VndUWXlPT0dJdnNLOXNvQW9HQ0NxR1NNNDkKQXdFSG9VUURRZ0FFYVM3VmZqOE53dEpmR3JBcnZlMkVzOWJKeXNIUENUKzh1ajNmWHEyNnhZUnJ4bXd2RDZCcwoybGNRMGRLb0U3ZTJENW9CRzJGV01ERDAwV0ZoaXlhTGpRPT0KLS0tLS1FTkQgRUMgUFJJVkFURSBLRVktLS0tLQo=
diff --git a/e2e/k8s/data/config/node-token.txt
b/e2e/k8s/data/config/node-token.txt
new file mode 100644
index 0000000000..190bd768b4
--- /dev/null
+++ b/e2e/k8s/data/config/node-token.txt
@@ -0,0 +1 @@
+K10800b7e6b1f6390067e433bd30dff5f925893b60074f8c36f7725bfdce6a45917::server:ca7449eb0dddd8a4bb6e5ca86e2d0cdd
diff --git a/e2e/k8s/data/create_k8s_monitor_data.json
b/e2e/k8s/data/create_k8s_monitor_data.json
new file mode 100644
index 0000000000..43eaa8fc0f
--- /dev/null
+++ b/e2e/k8s/data/create_k8s_monitor_data.json
@@ -0,0 +1,37 @@
+{
+ "detected": true,
+ "monitor": {
+ "intervals": 10,
+ "tags": [],
+ "app": "kubernetes",
+ "host": "172.29.0.11",
+ "name": "Brave_Stingray_55yR"
+ },
+ "collector": "",
+ "params": [
+ {
+ "display": true,
+ "field": "host",
+ "type": 1,
+ "paramValue": "172.29.0.11"
+ },
+ {
+ "display": true,
+ "field": "port",
+ "type": 0,
+ "paramValue": 6443
+ },
+ {
+ "display": true,
+ "field": "authType",
+ "type": 1,
+ "paramValue": "Bearer Token"
+ },
+ {
+ "display": true,
+ "field": "token",
+ "type": 1,
+ "paramValue": "#TOKEN#"
+ }
+ ]
+}
diff --git a/e2e/k8s/data/testsuite.yaml b/e2e/k8s/data/testsuite.yaml
new file mode 100644
index 0000000000..346f4e5d52
--- /dev/null
+++ b/e2e/k8s/data/testsuite.yaml
@@ -0,0 +1,69 @@
+#!api-testing
+# 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.
+
+# yaml-language-server:
$schema=https://linuxsuren.github.io/api-testing/api-testing-schema.json
+name: hertzbeat
+api: |
+ {{default "http://localhost:1157" (env "SERVER")}}
+param:
+ monitorHTTP: "{{randAlpha 6}}"
+ monitorSiteMap: "{{randAlpha 6}}"
+ monitorPort: "{{randAlpha 6}}"
+ monitorSSL: "{{randAlpha 6}}"
+ monitorPing: "{{randAlpha 6}}"
+ monitorUDP: "{{randAlpha 6}}"
+ monitorWebsite: "{{randAlpha 6}}"
+ monitorFTP: "{{randAlpha 6}}"
+ tagName: "{{randAlpha 3}}"
+items:
+- name: login
+ request:
+ api: /api/account/auth/form
+ method: POST
+ header:
+ Content-type: application/json
+ body: |
+ {
+ "type": 0,
+ "identifier": "admin",
+ "credential": "hertzbeat"
+ }
+ expect:
+ bodyFieldsExpect:
+ code: "0"
+- name: detectMonitor
+ request:
+ api: /api/monitor/detect
+ method: POST
+ header:
+ Authorization: Bearer {{.login.data.token}}
+ Content-type: application/json
+ bodyFromFile: data/tmp.json
+ expect:
+ statusCode: 200
+- name: createMonitor
+ request:
+ api: /api/monitor
+ method: POST
+ header:
+ Authorization: Bearer {{.login.data.token}}
+ Content-type: application/json
+ bodyFromFile: data/tmp.json
+ expect:
+ statusCode: 200
+
diff --git a/e2e/k8s/docker-compose.yml b/e2e/k8s/docker-compose.yml
new file mode 100644
index 0000000000..9304f7e8e8
--- /dev/null
+++ b/e2e/k8s/docker-compose.yml
@@ -0,0 +1,123 @@
+# 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.
+
+version: '3.8'
+services:
+ init:
+ image: bitnami/kubectl:latest
+ privileged: true
+ depends_on:
+ k3s:
+ condition: service_healthy
+ entrypoint: /bin/bash
+ networks:
+ k3s_network:
+ ipv4_address: 172.29.0.10
+ volumes:
+ - ./data/config/k3s.yaml:/.kube/config
+ - ./data:/testcase
+ command:
+ - -c
+ - |
+ # Wait for k3s to start
+ until kubectl cluster-info; do sleep 1; done
+ sleep 5
+ # Create serviceaccount and clusterrolebinding
+ kubectl create serviceaccount -n kube-system cluster-admin-sa
+ kubectl create clusterrolebinding -n kube-system cluster-admin-binding
--clusterrole=cluster-admin --serviceaccount=kube-system:cluster-admin-sa
+ cd /testcase
+ kubectl create token cluster-admin-sa -n kube-system --duration=24h
+ echo $(sed "s/#TOKEN#/$(echo $(kubectl create token cluster-admin-sa
-n kube-system --duration=24h))/g" create_k8s_monitor_data.json)>tmp.json
+ # install metrics server
+ kubectl apply -f
https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
+ sleep 30
+ tail -f /dev/null
+ k3s:
+ image: rancher/k3s:v1.31.0-k3s1
+ container_name: k3s
+ privileged: true
+ ports:
+ - "6443:6443"
+ - "80:80"
+ command: server --bind-address 172.29.0.11
+ networks:
+ k3s_network:
+ ipv4_address: 172.29.0.11
+ healthcheck:
+ test: [ "CMD-SHELL",
+ "kubectl cluster-info && echo $(cat
/var/lib/rancher/k3s/server/node-token)>node-token.txt" ]
+ interval: 3s
+ retries: 30
+ start_period: 10s
+ timeout: 10s
+ volumes:
+ - ./data/config/k3s.yaml:/etc/rancher/k3s/k3s.yaml
+ - ./data/config/node-token.txt:/node-token.txt
+ testing:
+ image: ghcr.io/linuxsuren/api-testing:v0.0.17
+ environment:
+ SERVER: http://hertzbeat:1157
+ container_name: e2e-testing
+ volumes:
+ - ./data/:/work/data/
+ - ./data/testsuite.yaml:/work/testsuite.yaml
+ command: atest run -p /work/testsuite.yaml --level debug --thread 3
+ networks:
+ k3s_network:
+ ipv4_address: 172.29.0.12
+ depends_on:
+ checker:
+ condition: service_healthy
+ k3s:
+ condition: service_healthy
+ links:
+ - hertzbeat
+ - checker
+ - k3s
+ checker:
+ image: alpine:latest
+ container_name: e2e-checker
+ command: sh -c "apk add --update curl && tail -f /dev/null"
+ healthcheck:
+ test: [ "CMD-SHELL",
+ "curl -s -X POST -H \"Content-Type: application/json\" -d
'{\"type\": 0,\"identifier\": \"admin\",\"credential\": \"hertzbeat\"}'
http://hertzbeat:1157/api/account/auth/form | grep -q token"
+ ]
+ interval: 3s
+ timeout: 60s
+ retries: 10
+ start_period: 10s
+ networks:
+ k3s_network:
+ ipv4_address: 172.29.0.13
+ depends_on:
+ - init
+ hertzbeat:
+ image: apache/hertzbeat:test
+ container_name: e2e-hertzbeat
+ volumes:
+ - ./logs/:/opt/hertzbeat/logs/
+ ports:
+ - "1157:1157"
+ networks:
+ k3s_network:
+ ipv4_address: 172.29.0.14
+networks:
+ k3s_network:
+ driver: bridge
+ ipam:
+ config:
+ - subnet: 172.29.0.0/16
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]