From 3b1cce64b6e0af9194ad820dc6930c59fe943bc1 Mon Sep 17 00:00:00 2001 From: zyy17 Date: Tue, 24 Oct 2023 16:07:22 +0800 Subject: [PATCH] ci: add the simple framework of nightly functional tests --- .github/actions/deploy-greptimedb/action.yml | 31 ++++ .github/actions/sqlness-test/action.yml | 59 ++++++ .github/scripts/deploy-greptimedb.sh | 172 ++++++++++++++++++ .github/workflows/nightly-funtional-tests.yml | 26 +++ 4 files changed, 288 insertions(+) create mode 100644 .github/actions/deploy-greptimedb/action.yml create mode 100644 .github/actions/sqlness-test/action.yml create mode 100755 .github/scripts/deploy-greptimedb.sh create mode 100644 .github/workflows/nightly-funtional-tests.yml diff --git a/.github/actions/deploy-greptimedb/action.yml b/.github/actions/deploy-greptimedb/action.yml new file mode 100644 index 000000000000..b18830ef8d7f --- /dev/null +++ b/.github/actions/deploy-greptimedb/action.yml @@ -0,0 +1,31 @@ +name: Deploy GreptimeDB cluster +description: Deploy GreptimeDB cluster on Kubernetes +inputs: + aws-ci-test-bucket: + description: 'AWS S3 bucket name for testing' + required: true + aws-region: + description: 'AWS region for testing' + required: true + data-root: + description: 'Data root for testing' + required: true + aws-access-key-id: + description: 'AWS access key id for testing' + required: true + aws-secret-access-key: + description: 'AWS secret access key for testing' + required: true +runs: + using: composite + steps: + - name: Deploy GreptimeDB by Helm + shell: bash + env: + DATA_ROOT: ${{ inputs.data-root }} + AWS_CI_TEST_BUCKET: ${{ inputs.aws-ci-test-bucket }} + AWS_REGION: ${{ inputs.aws-region }} + AWS_ACCESS_KEY_ID: ${{ inputs.aws-access-key-id }} + AWS_SECRET_ACCESS_KEY: ${{ inputs.aws-secret-access-key }} + run: | + ./.github/scripts/deploy-greptimedb.sh diff --git a/.github/actions/sqlness-test/action.yml b/.github/actions/sqlness-test/action.yml new file mode 100644 index 000000000000..28d58902a6ba --- /dev/null +++ b/.github/actions/sqlness-test/action.yml @@ -0,0 +1,59 @@ +name: Run sqlness test +description: Run sqlness test on GreptimeDB + +inputs: + aws-ci-test-bucket: + description: 'AWS S3 bucket name for testing' + required: true + aws-region: + description: 'AWS region for testing' + required: true + data-root: + description: 'Data root for testing' + required: true + aws-access-key-id: + description: 'AWS access key id for testing' + required: true + aws-secret-access-key: + description: 'AWS secret access key for testing' + required: true + +runs: + using: composite + steps: + - name: Deploy GreptimeDB cluster by Helm + uses: ./.github/actions/deploy-greptimedb + with: + data-root: ${{ inputs.data-root }} + aws-ci-test-bucket: ${{ inputs.aws-ci-test-bucket }} + aws-region: ${{ inputs.aws-region }} + aws-access-key-id: ${{ inputs.aws-access-key-id }} + aws-secret-access-key: ${{ inputs.aws-secret-access-key }} + + # TODO(zyy17): The following tests will be replaced by the real sqlness test. + - name: Run tests on greptimedb cluster + shell: bash + run: | + mysql -h 127.0.0.1 -P 14002 -e "CREATE TABLE IF NOT EXISTS system_metrics (host VARCHAR(255), idc VARCHAR(255), cpu_util DOUBLE, memory_util DOUBLE, disk_util DOUBLE, ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(host, idc), TIME INDEX(ts));" && \ + mysql -h 127.0.0.1 -P 14002 -e "SHOW TABLES;" + + - name: Run tests on greptimedb cluster that uses S3 + shell: bash + run: | + mysql -h 127.0.0.1 -P 24002 -e "CREATE TABLE IF NOT EXISTS system_metrics (host VARCHAR(255), idc VARCHAR(255), cpu_util DOUBLE, memory_util DOUBLE, disk_util DOUBLE, ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(host, idc), TIME INDEX(ts));" && \ + mysql -h 127.0.0.1 -P 24002 -e "SHOW TABLES;" + + - name: Run tests on standalone greptimedb + shell: bash + run: | + mysql -h 127.0.0.1 -P 34002 -e "CREATE TABLE IF NOT EXISTS system_metrics (host VARCHAR(255), idc VARCHAR(255), cpu_util DOUBLE, memory_util DOUBLE, disk_util DOUBLE, ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(host, idc), TIME INDEX(ts));" && \ + mysql -h 127.0.0.1 -P 34002 -e "SHOW TABLES;" + + - name: Clean S3 data + shell: bash + env: + AWS_DEFAULT_REGION: ${{ inputs.aws-region }} + AWS_ACCESS_KEY_ID: ${{ inputs.aws-access-key-id }} + AWS_SECRET_ACCESS_KEY: ${{ inputs.aws-secret-access-key }} + run: | + aws s3 rm s3://${{ inputs.aws-ci-test-bucket }}/${{ inputs.data-root }} --recursive diff --git a/.github/scripts/deploy-greptimedb.sh b/.github/scripts/deploy-greptimedb.sh new file mode 100755 index 000000000000..2d063e9e9e78 --- /dev/null +++ b/.github/scripts/deploy-greptimedb.sh @@ -0,0 +1,172 @@ +#!/usr/bin/env bash + +set -e +set -o pipefail + +KUBERNETES_VERSION="${KUBERNETES_VERSION:-v1.24.0}" +ENABLE_STANDALONE_MODE="${ENABLE_STANDALONE_MODE:-true}" +DEFAULT_INSTALL_NAMESPACE=${DEFAULT_INSTALL_NAMESPACE:-default} +GREPTIMEDB_IMAGE_TAG=${GREPTIMEDB_IMAGE_TAG:-latest} +ETCD_CHART="oci://registry-1.docker.io/bitnamicharts/etcd" +GREPTIME_CHART="https://greptimeteam.github.io/helm-charts/" + +# Ceate a cluster with 1 control-plane node and 5 workers. +function create_kind_cluster() { + cat < /tmp/connections.out & +} + +# Deploy greptimedb cluster by using S3. +# It will expose cluster service ports as '24000', '24001', '24002', '24003' to local access. +function deploy_greptimedb_cluster_with_s3_storage() { + local cluster_name=$1 + local install_namespace=$2 + + kubectl create ns "$install_namespace" + + deploy_etcd_cluster "$install_namespace" + + helm install "$cluster_name" greptime/greptimedb-cluster -n "$install_namespace" \ + --set image.tag="$GREPTIMEDB_IMAGE_TAG" \ + --set meta.etcdEndpoints="etcd.$install_namespace:2379" \ + --set storage.s3.bucket="$AWS_CI_TEST_BUCKET" \ + --set storage.s3.region="$AWS_REGION" \ + --set storage.s3.root="$DATA_ROOT" \ + --set storage.s3.secretName=s3-credentials \ + --set storage.credentials.secretName=s3-credentials \ + --set storage.credentials.secretCreation.enabled=true \ + --set storage.credentials.secretCreation.enableEncryption=false \ + --set storage.credentials.secretCreation.data.access-key-id="$AWS_ACCESS_KEY_ID" \ + --set storage.credentials.secretCreation.data.secret-access-key="$AWS_SECRET_ACCESS_KEY" + + # Wait for greptimedb cluster to be ready. + while true; do + PHASE=$(kubectl -n "$install_namespace" get gtc "$cluster_name" -o jsonpath='{.status.clusterPhase}') + if [ "$PHASE" == "Running" ]; then + echo "Cluster is ready" + break + else + echo "Cluster is not ready yet: Current phase: $PHASE" + sleep 5 # wait for 5 seconds before check again. + fi + done + + # Expose greptimedb cluster to local access. + kubectl -n "$install_namespace" port-forward svc/"$cluster_name"-frontend \ + 24000:4000 \ + 24001:4001 \ + 24002:4002 \ + 24003:4003 > /tmp/connections.out & +} + +# Deploy standalone greptimedb. +# It will expose cluster service ports as '34000', '34001', '34002', '34003' to local access. +function deploy_standalone_greptimedb() { + helm install greptimedb-standalone greptime/greptimedb-standalone \ + --set image.tag="$GREPTIMEDB_IMAGE_TAG" \ + -n "$DEFAULT_INSTALL_NAMESPACE" + + # Wait for etcd cluster to be ready. + kubectl rollout status statefulset/greptimedb-standalone -n "$DEFAULT_INSTALL_NAMESPACE" + + # Expose greptimedb to local access. + kubectl -n "$DEFAULT_INSTALL_NAMESPACE" port-forward svc/greptimedb-standalone \ + 34000:4000 \ + 34001:4001 \ + 34002:4002 \ + 34003:4003 > /tmp/connections.out & +} + +# Entrypoint of the script. +function main() { + create_kind_cluster + add_greptime_chart + + # Deploy standalone greptimedb in the same K8s. + if [ "$ENABLE_STANDALONE_MODE" == "true" ]; then + deploy_standalone_greptimedb + fi + + deploy_greptimedb_operator + deploy_greptimedb_cluster testcluster testcluster + deploy_greptimedb_cluster_with_s3_storage testcluster-s3 testcluster-s3 +} + +# Usages: +# - Deploy greptimedb cluster: ./deploy-greptimedb.sh +main diff --git a/.github/workflows/nightly-funtional-tests.yml b/.github/workflows/nightly-funtional-tests.yml new file mode 100644 index 000000000000..5dbd04d30c28 --- /dev/null +++ b/.github/workflows/nightly-funtional-tests.yml @@ -0,0 +1,26 @@ +name: Nightly functional tests + +on: + schedule: + # At 00:00 on Tuesday. + - cron: '0 0 * * 2' + workflow_dispatch: + +jobs: + sqlness-test: + name: Run sqlness test + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Run sqlness test + uses: ./.github/actions/sqlness-test + with: + data-root: sqlness-test + aws-ci-test-bucket: ${{ vars.AWS_CI_TEST_BUCKET }} + aws-region: ${{ vars.AWS_CI_TEST_BUCKET_REGION }} + aws-access-key-id: ${{ secrets.AWS_CI_TEST_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_CI_TEST_SECRET_ACCESS_KEY }}