From 55a1cdf0cf6bda99fd8e357c5e8b71bd1c870ed3 Mon Sep 17 00:00:00 2001 From: zyy17 Date: Mon, 30 Sep 2024 12:08:59 +0800 Subject: [PATCH] test: add TestClusterEnableMonitoring e2e --- .../greptime.io_greptimedbclusters.yaml | 8 ++ manifests/bundle.yaml | 8 ++ manifests/crds.yaml | 8 ++ .../greptimedbcluster/test_basic_cluster.go | 2 + .../test_cluster_enable_flow.go | 3 + .../test_cluster_enable_monitoring.go | 101 ++++++++++++++++++ .../test_cluster_enable_remote_wal.go | 3 + .../test_cluster_standalone_wal.go | 3 + .../greptimedbcluster/test_scale_cluster.go | 3 + tests/e2e/greptimedbcluster_test.go | 4 + .../test_basic_standalone.go | 3 + .../resources/cluster/basic/cluster.yaml | 18 ---- .../cluster/enable-flow/cluster.yaml | 18 ---- .../cluster/enable-monitoring/cluster.yaml | 21 ++++ .../cluster/enable-remote-wal/cluster.yaml | 14 --- .../resources/cluster/scale/cluster.yaml | 18 ---- .../cluster/standalone-wal/cluster.yaml | 6 +- .../standalone/basic/standalone.yaml | 18 ---- 18 files changed, 168 insertions(+), 91 deletions(-) create mode 100644 tests/e2e/greptimedbcluster/test_cluster_enable_monitoring.go create mode 100644 tests/e2e/testdata/resources/cluster/enable-monitoring/cluster.yaml diff --git a/config/crd/resources/greptime.io_greptimedbclusters.yaml b/config/crd/resources/greptime.io_greptimedbclusters.yaml index 8d6aae0f..bf6a528c 100644 --- a/config/crd/resources/greptime.io_greptimedbclusters.yaml +++ b/config/crd/resources/greptime.io_greptimedbclusters.yaml @@ -16914,6 +16914,8 @@ spec: type: object httpPort: format: int32 + maximum: 65535 + minimum: 0 type: integer initializer: properties: @@ -16943,6 +16945,8 @@ spec: type: object mysqlPort: format: int32 + maximum: 65535 + minimum: 0 type: integer objectStorage: properties: @@ -17021,6 +17025,8 @@ spec: type: object postgreSQLPort: format: int32 + maximum: 65535 + minimum: 0 type: integer prometheusMonitor: properties: @@ -17037,6 +17043,8 @@ spec: type: object rpcPort: format: int32 + maximum: 65535 + minimum: 0 type: integer service: properties: diff --git a/manifests/bundle.yaml b/manifests/bundle.yaml index 3ba7f3d1..149c7240 100644 --- a/manifests/bundle.yaml +++ b/manifests/bundle.yaml @@ -16920,6 +16920,8 @@ spec: type: object httpPort: format: int32 + maximum: 65535 + minimum: 0 type: integer initializer: properties: @@ -16949,6 +16951,8 @@ spec: type: object mysqlPort: format: int32 + maximum: 65535 + minimum: 0 type: integer objectStorage: properties: @@ -17027,6 +17031,8 @@ spec: type: object postgreSQLPort: format: int32 + maximum: 65535 + minimum: 0 type: integer prometheusMonitor: properties: @@ -17043,6 +17049,8 @@ spec: type: object rpcPort: format: int32 + maximum: 65535 + minimum: 0 type: integer service: properties: diff --git a/manifests/crds.yaml b/manifests/crds.yaml index 8d51f9ce..ca36d526 100644 --- a/manifests/crds.yaml +++ b/manifests/crds.yaml @@ -16913,6 +16913,8 @@ spec: type: object httpPort: format: int32 + maximum: 65535 + minimum: 0 type: integer initializer: properties: @@ -16942,6 +16944,8 @@ spec: type: object mysqlPort: format: int32 + maximum: 65535 + minimum: 0 type: integer objectStorage: properties: @@ -17020,6 +17024,8 @@ spec: type: object postgreSQLPort: format: int32 + maximum: 65535 + minimum: 0 type: integer prometheusMonitor: properties: @@ -17036,6 +17042,8 @@ spec: type: object rpcPort: format: int32 + maximum: 65535 + minimum: 0 type: integer service: properties: diff --git a/tests/e2e/greptimedbcluster/test_basic_cluster.go b/tests/e2e/greptimedbcluster/test_basic_cluster.go index 6d9a08e8..cd3953d0 100644 --- a/tests/e2e/greptimedbcluster/test_basic_cluster.go +++ b/tests/e2e/greptimedbcluster/test_basic_cluster.go @@ -60,6 +60,8 @@ func TestBasicCluster(ctx context.Context, h *helper.Helper) { return nil }, helper.DefaultTimeout, time.Second).ShouldNot(HaveOccurred()) + err = h.Get(ctx, client.ObjectKey{Name: testCluster.Name, Namespace: testCluster.Namespace}, testCluster) + Expect(err).NotTo(HaveOccurred(), "failed to get cluster") By("Execute distributed SQL test") frontendAddr, err := h.PortForward(ctx, testCluster.Namespace, common.ResourceName(testCluster.Name, greptimev1alpha1.FrontendComponentKind), int(testCluster.Spec.PostgreSQLPort)) Expect(err).NotTo(HaveOccurred(), "failed to port forward frontend service") diff --git a/tests/e2e/greptimedbcluster/test_cluster_enable_flow.go b/tests/e2e/greptimedbcluster/test_cluster_enable_flow.go index c3718562..aa52c78b 100644 --- a/tests/e2e/greptimedbcluster/test_cluster_enable_flow.go +++ b/tests/e2e/greptimedbcluster/test_cluster_enable_flow.go @@ -60,6 +60,9 @@ func TestClusterEnableFlow(ctx context.Context, h *helper.Helper) { return nil }, helper.DefaultTimeout, time.Second).ShouldNot(HaveOccurred()) + err = h.Get(ctx, client.ObjectKey{Name: testCluster.Name, Namespace: testCluster.Namespace}, testCluster) + Expect(err).NotTo(HaveOccurred(), "failed to get cluster") + By("Execute distributed SQL test") frontendAddr, err := h.PortForward(ctx, testCluster.Namespace, common.ResourceName(testCluster.Name, greptimev1alpha1.FrontendComponentKind), int(testCluster.Spec.PostgreSQLPort)) Expect(err).NotTo(HaveOccurred(), "failed to port forward frontend service") diff --git a/tests/e2e/greptimedbcluster/test_cluster_enable_monitoring.go b/tests/e2e/greptimedbcluster/test_cluster_enable_monitoring.go new file mode 100644 index 00000000..c3f5739e --- /dev/null +++ b/tests/e2e/greptimedbcluster/test_cluster_enable_monitoring.go @@ -0,0 +1,101 @@ +// Copyright 2024 Greptime Team +// +// Licensed 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 greptimedbcluster + +import ( + "context" + "fmt" + "net" + "time" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "sigs.k8s.io/controller-runtime/pkg/client" + + greptimev1alpha1 "github.com/GreptimeTeam/greptimedb-operator/apis/v1alpha1" + "github.com/GreptimeTeam/greptimedb-operator/controllers/common" + "github.com/GreptimeTeam/greptimedb-operator/tests/e2e/helper" +) + +// TestClusterEnableMonitoring tests a cluster that enables monitoring. +func TestClusterEnableMonitoring(ctx context.Context, h *helper.Helper) { + const ( + testCRFile = "./testdata/resources/cluster/enabled-monitoring/cluster.yaml" + testSQLFile = "./testdata/sql/cluster/partition.sql" + ) + + By(fmt.Sprintf("greptimecluster test with CR file %s and SQL file %s", testCRFile, testSQLFile)) + + testCluster := new(greptimev1alpha1.GreptimeDBCluster) + err := h.LoadCR(testCRFile, testCluster) + Expect(err).NotTo(HaveOccurred(), "failed to load greptimedbcluster yaml file") + + err = h.Create(ctx, testCluster) + Expect(err).NotTo(HaveOccurred(), "failed to create greptimedbcluster") + + By("Check the status of testCluster") + Eventually(func() error { + clusterPhase, err := h.GetPhase(ctx, testCluster.Namespace, testCluster.Name, new(greptimev1alpha1.GreptimeDBCluster)) + if err != nil { + return err + } + + if clusterPhase != greptimev1alpha1.PhaseRunning { + return fmt.Errorf("cluster is not running") + } + + return nil + }, helper.DefaultTimeout, time.Second).ShouldNot(HaveOccurred()) + + err = h.Get(ctx, client.ObjectKey{Name: testCluster.Name, Namespace: testCluster.Namespace}, testCluster) + Expect(err).NotTo(HaveOccurred(), "failed to get cluster") + By("Execute distributed SQL test") + frontendAddr, err := h.PortForward(ctx, testCluster.Namespace, common.ResourceName(testCluster.Name, greptimev1alpha1.FrontendComponentKind), int(testCluster.Spec.PostgreSQLPort)) + Expect(err).NotTo(HaveOccurred(), "failed to port forward frontend service") + Eventually(func() error { + conn, err := net.Dial("tcp", frontendAddr) + if err != nil { + return err + } + conn.Close() + return nil + }, helper.DefaultTimeout, time.Second).ShouldNot(HaveOccurred()) + + err = h.RunSQLTest(ctx, frontendAddr, testSQLFile) + Expect(err).NotTo(HaveOccurred(), "failed to run sql test") + + By("Kill the port forwarding process") + h.KillPortForwardProcess() + + By("Delete cluster") + err = h.Delete(ctx, testCluster) + Expect(err).NotTo(HaveOccurred(), "failed to delete cluster") + Eventually(func() error { + // The cluster will be deleted eventually. + return h.Get(ctx, client.ObjectKey{Name: testCluster.Name, Namespace: testCluster.Namespace}, testCluster) + }, helper.DefaultTimeout, time.Second).Should(HaveOccurred()) + + By("The PVC of the datanode should be retained") + datanodePVCs, err := h.GetPVCs(ctx, testCluster.Namespace, testCluster.Name, greptimev1alpha1.DatanodeComponentKind, common.FileStorageTypeDatanode) + Expect(err).NotTo(HaveOccurred(), "failed to get datanode PVCs") + Expect(int32(len(datanodePVCs))).To(Equal(*testCluster.Spec.Datanode.Replicas), "the number of datanode PVCs should be equal to the number of datanode replicas") + + By("Remove the PVC of the datanode") + for _, pvc := range datanodePVCs { + err = h.Delete(ctx, &pvc) + Expect(err).NotTo(HaveOccurred(), "failed to delete datanode PVC") + } +} diff --git a/tests/e2e/greptimedbcluster/test_cluster_enable_remote_wal.go b/tests/e2e/greptimedbcluster/test_cluster_enable_remote_wal.go index a58d0793..1d2cac2d 100644 --- a/tests/e2e/greptimedbcluster/test_cluster_enable_remote_wal.go +++ b/tests/e2e/greptimedbcluster/test_cluster_enable_remote_wal.go @@ -60,6 +60,9 @@ func TestClusterEnableRemoteWal(ctx context.Context, h *helper.Helper) { return nil }, helper.DefaultTimeout, time.Second).ShouldNot(HaveOccurred()) + err = h.Get(ctx, client.ObjectKey{Name: testCluster.Name, Namespace: testCluster.Namespace}, testCluster) + Expect(err).NotTo(HaveOccurred(), "failed to get cluster") + By("Execute distributed SQL test") frontendAddr, err := h.PortForward(ctx, testCluster.Namespace, common.ResourceName(testCluster.Name, greptimev1alpha1.FrontendComponentKind), int(testCluster.Spec.PostgreSQLPort)) Expect(err).NotTo(HaveOccurred(), "failed to port forward frontend service") diff --git a/tests/e2e/greptimedbcluster/test_cluster_standalone_wal.go b/tests/e2e/greptimedbcluster/test_cluster_standalone_wal.go index e49c3e6a..1dcb38b0 100644 --- a/tests/e2e/greptimedbcluster/test_cluster_standalone_wal.go +++ b/tests/e2e/greptimedbcluster/test_cluster_standalone_wal.go @@ -60,6 +60,9 @@ func TestClusterStandaloneWAL(ctx context.Context, h *helper.Helper) { return nil }, helper.DefaultTimeout, time.Second).ShouldNot(HaveOccurred()) + err = h.Get(ctx, client.ObjectKey{Name: testCluster.Name, Namespace: testCluster.Namespace}, testCluster) + Expect(err).NotTo(HaveOccurred(), "failed to get cluster") + By("Execute distributed SQL test") frontendAddr, err := h.PortForward(ctx, testCluster.Namespace, common.ResourceName(testCluster.Name, greptimev1alpha1.FrontendComponentKind), int(testCluster.Spec.PostgreSQLPort)) Expect(err).NotTo(HaveOccurred(), "failed to port forward frontend service") diff --git a/tests/e2e/greptimedbcluster/test_scale_cluster.go b/tests/e2e/greptimedbcluster/test_scale_cluster.go index 93a8490b..d7911cc3 100644 --- a/tests/e2e/greptimedbcluster/test_scale_cluster.go +++ b/tests/e2e/greptimedbcluster/test_scale_cluster.go @@ -61,6 +61,9 @@ func TestScaleCluster(ctx context.Context, h *helper.Helper) { return nil }, helper.DefaultTimeout, time.Second).ShouldNot(HaveOccurred()) + err = h.Get(ctx, client.ObjectKey{Name: testCluster.Name, Namespace: testCluster.Namespace}, testCluster) + Expect(err).NotTo(HaveOccurred(), "failed to get cluster") + By("Execute distributed SQL test") frontendAddr, err := h.PortForward(ctx, testCluster.Namespace, common.ResourceName(testCluster.Name, greptimev1alpha1.FrontendComponentKind), int(testCluster.Spec.PostgreSQLPort)) Expect(err).NotTo(HaveOccurred(), "failed to port forward frontend service") diff --git a/tests/e2e/greptimedbcluster_test.go b/tests/e2e/greptimedbcluster_test.go index 22e186ac..2fe69449 100644 --- a/tests/e2e/greptimedbcluster_test.go +++ b/tests/e2e/greptimedbcluster_test.go @@ -52,4 +52,8 @@ var _ = Describe("Test GreptimeDBCluster", func() { It("Test a cluster with standalone WAL", func() { greptimedbcluster.TestClusterStandaloneWAL(ctx, h) }) + + It("Test a cluster that enables monitoring", func() { + greptimedbcluster.TestClusterEnableMonitoring(ctx, h) + }) }) diff --git a/tests/e2e/greptimedbstandalone/test_basic_standalone.go b/tests/e2e/greptimedbstandalone/test_basic_standalone.go index 9dc92cb3..5e50042a 100644 --- a/tests/e2e/greptimedbstandalone/test_basic_standalone.go +++ b/tests/e2e/greptimedbstandalone/test_basic_standalone.go @@ -46,6 +46,9 @@ func TestBasicStandalone(ctx context.Context, h *helper.Helper) { err = h.Create(ctx, testStandalone) Expect(err).NotTo(HaveOccurred(), "failed to create greptimedbstandalone") + err = h.Get(ctx, client.ObjectKey{Name: testStandalone.Name, Namespace: testStandalone.Namespace}, testStandalone) + Expect(err).NotTo(HaveOccurred(), "failed to get standalone") + By("Check the status of testStandalone") Eventually(func() error { phase, err := h.GetPhase(ctx, testStandalone.Namespace, testStandalone.Name, new(greptimev1alpha1.GreptimeDBStandalone)) diff --git a/tests/e2e/testdata/resources/cluster/basic/cluster.yaml b/tests/e2e/testdata/resources/cluster/basic/cluster.yaml index a2d34028..6e4cd67e 100644 --- a/tests/e2e/testdata/resources/cluster/basic/cluster.yaml +++ b/tests/e2e/testdata/resources/cluster/basic/cluster.yaml @@ -1,17 +1,3 @@ -# Copyright 2022 Greptime Team -# -# Licensed 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. - apiVersion: greptime.io/v1alpha1 kind: GreptimeDBCluster metadata: @@ -31,7 +17,3 @@ spec: - etcd.etcd-cluster:2379 datanode: replicas: 3 - httpPort: 4000 - rpcPort: 4001 - mysqlPort: 4002 - postgreSQLPort: 4003 diff --git a/tests/e2e/testdata/resources/cluster/enable-flow/cluster.yaml b/tests/e2e/testdata/resources/cluster/enable-flow/cluster.yaml index 5206a505..7ef68935 100644 --- a/tests/e2e/testdata/resources/cluster/enable-flow/cluster.yaml +++ b/tests/e2e/testdata/resources/cluster/enable-flow/cluster.yaml @@ -1,17 +1,3 @@ -# Copyright 2022 Greptime Team -# -# Licensed 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. - apiVersion: greptime.io/v1alpha1 kind: GreptimeDBCluster metadata: @@ -33,7 +19,3 @@ spec: replicas: 3 flownode: replicas: 2 - httpPort: 4000 - rpcPort: 4001 - mysqlPort: 4002 - postgreSQLPort: 4003 diff --git a/tests/e2e/testdata/resources/cluster/enable-monitoring/cluster.yaml b/tests/e2e/testdata/resources/cluster/enable-monitoring/cluster.yaml new file mode 100644 index 00000000..c3561f99 --- /dev/null +++ b/tests/e2e/testdata/resources/cluster/enable-monitoring/cluster.yaml @@ -0,0 +1,21 @@ +apiVersion: greptime.io/v1alpha1 +kind: GreptimeDBCluster +metadata: + name: e2e-cluster-enable-monitoring + namespace: default +spec: + initializer: + image: localhost:5001/greptime/greptimedb-initializer:latest + base: + main: + image: localhost:5001/greptime/greptimedb:latest + frontend: + replicas: 1 + meta: + replicas: 1 + etcdEndpoints: + - "etcd.etcd-cluster.svc.cluster.local:2379" + datanode: + replicas: 1 + monitoring: + enabled: true diff --git a/tests/e2e/testdata/resources/cluster/enable-remote-wal/cluster.yaml b/tests/e2e/testdata/resources/cluster/enable-remote-wal/cluster.yaml index 04d579e8..60087ed4 100644 --- a/tests/e2e/testdata/resources/cluster/enable-remote-wal/cluster.yaml +++ b/tests/e2e/testdata/resources/cluster/enable-remote-wal/cluster.yaml @@ -1,17 +1,3 @@ -# Copyright 2024 Greptime Team -# -# Licensed 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. - apiVersion: greptime.io/v1alpha1 kind: GreptimeDBCluster metadata: diff --git a/tests/e2e/testdata/resources/cluster/scale/cluster.yaml b/tests/e2e/testdata/resources/cluster/scale/cluster.yaml index a2d535ea..eab65cac 100644 --- a/tests/e2e/testdata/resources/cluster/scale/cluster.yaml +++ b/tests/e2e/testdata/resources/cluster/scale/cluster.yaml @@ -1,17 +1,3 @@ -# Copyright 2024 Greptime Team -# -# Licensed 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. - apiVersion: greptime.io/v1alpha1 kind: GreptimeDBCluster metadata: @@ -34,7 +20,3 @@ spec: storage: fs: storageRetainPolicy: Delete - httpPort: 4000 - rpcPort: 4001 - mysqlPort: 4002 - postgreSQLPort: 4003 diff --git a/tests/e2e/testdata/resources/cluster/standalone-wal/cluster.yaml b/tests/e2e/testdata/resources/cluster/standalone-wal/cluster.yaml index 4b67ce7a..3e2fc079 100644 --- a/tests/e2e/testdata/resources/cluster/standalone-wal/cluster.yaml +++ b/tests/e2e/testdata/resources/cluster/standalone-wal/cluster.yaml @@ -1,7 +1,7 @@ apiVersion: greptime.io/v1alpha1 kind: GreptimeDBCluster metadata: - name: cluster-with-standalone-wal + name: e2e-cluster-with-standalone-wal namespace: default spec: base: @@ -15,10 +15,6 @@ spec: - "etcd.etcd-cluster:2379" datanode: replicas: 1 - httpPort: 4000 - rpcPort: 4001 - mysqlPort: 4002 - postgreSQLPort: 4003 wal: raftEngine: fs: diff --git a/tests/e2e/testdata/resources/standalone/basic/standalone.yaml b/tests/e2e/testdata/resources/standalone/basic/standalone.yaml index 6ce933fd..4b3ae88a 100644 --- a/tests/e2e/testdata/resources/standalone/basic/standalone.yaml +++ b/tests/e2e/testdata/resources/standalone/basic/standalone.yaml @@ -1,17 +1,3 @@ -# Copyright 2024 Greptime Team -# -# Licensed 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. - apiVersion: greptime.io/v1alpha1 kind: GreptimeDBStandalone metadata: @@ -21,7 +7,3 @@ spec: base: main: image: localhost:5001/greptime/greptimedb:latest - httpPort: 4000 - rpcPort: 4001 - mysqlPort: 4002 - postgreSQLPort: 4003