Skip to content

Commit

Permalink
test: add TestClusterEnableMonitoring e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
zyy17 committed Sep 30, 2024
1 parent e7b909e commit 55a1cdf
Show file tree
Hide file tree
Showing 18 changed files with 168 additions and 91 deletions.
8 changes: 8 additions & 0 deletions config/crd/resources/greptime.io_greptimedbclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16914,6 +16914,8 @@ spec:
type: object
httpPort:
format: int32
maximum: 65535
minimum: 0
type: integer
initializer:
properties:
Expand Down Expand Up @@ -16943,6 +16945,8 @@ spec:
type: object
mysqlPort:
format: int32
maximum: 65535
minimum: 0
type: integer
objectStorage:
properties:
Expand Down Expand Up @@ -17021,6 +17025,8 @@ spec:
type: object
postgreSQLPort:
format: int32
maximum: 65535
minimum: 0
type: integer
prometheusMonitor:
properties:
Expand All @@ -17037,6 +17043,8 @@ spec:
type: object
rpcPort:
format: int32
maximum: 65535
minimum: 0
type: integer
service:
properties:
Expand Down
8 changes: 8 additions & 0 deletions manifests/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16920,6 +16920,8 @@ spec:
type: object
httpPort:
format: int32
maximum: 65535
minimum: 0
type: integer
initializer:
properties:
Expand Down Expand Up @@ -16949,6 +16951,8 @@ spec:
type: object
mysqlPort:
format: int32
maximum: 65535
minimum: 0
type: integer
objectStorage:
properties:
Expand Down Expand Up @@ -17027,6 +17031,8 @@ spec:
type: object
postgreSQLPort:
format: int32
maximum: 65535
minimum: 0
type: integer
prometheusMonitor:
properties:
Expand All @@ -17043,6 +17049,8 @@ spec:
type: object
rpcPort:
format: int32
maximum: 65535
minimum: 0
type: integer
service:
properties:
Expand Down
8 changes: 8 additions & 0 deletions manifests/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16913,6 +16913,8 @@ spec:
type: object
httpPort:
format: int32
maximum: 65535
minimum: 0
type: integer
initializer:
properties:
Expand Down Expand Up @@ -16942,6 +16944,8 @@ spec:
type: object
mysqlPort:
format: int32
maximum: 65535
minimum: 0
type: integer
objectStorage:
properties:
Expand Down Expand Up @@ -17020,6 +17024,8 @@ spec:
type: object
postgreSQLPort:
format: int32
maximum: 65535
minimum: 0
type: integer
prometheusMonitor:
properties:
Expand All @@ -17036,6 +17042,8 @@ spec:
type: object
rpcPort:
format: int32
maximum: 65535
minimum: 0
type: integer
service:
properties:
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/greptimedbcluster/test_basic_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/greptimedbcluster/test_cluster_enable_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
101 changes: 101 additions & 0 deletions tests/e2e/greptimedbcluster/test_cluster_enable_monitoring.go
Original file line number Diff line number Diff line change
@@ -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")
}
}
3 changes: 3 additions & 0 deletions tests/e2e/greptimedbcluster/test_cluster_enable_remote_wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/greptimedbcluster/test_cluster_standalone_wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/greptimedbcluster/test_scale_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/greptimedbcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
3 changes: 3 additions & 0 deletions tests/e2e/greptimedbstandalone/test_basic_standalone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
18 changes: 0 additions & 18 deletions tests/e2e/testdata/resources/cluster/basic/cluster.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -31,7 +17,3 @@ spec:
- etcd.etcd-cluster:2379
datanode:
replicas: 3
httpPort: 4000
rpcPort: 4001
mysqlPort: 4002
postgreSQLPort: 4003
18 changes: 0 additions & 18 deletions tests/e2e/testdata/resources/cluster/enable-flow/cluster.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -33,7 +19,3 @@ spec:
replicas: 3
flownode:
replicas: 2
httpPort: 4000
rpcPort: 4001
mysqlPort: 4002
postgreSQLPort: 4003
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
18 changes: 0 additions & 18 deletions tests/e2e/testdata/resources/cluster/scale/cluster.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -34,7 +20,3 @@ spec:
storage:
fs:
storageRetainPolicy: Delete
httpPort: 4000
rpcPort: 4001
mysqlPort: 4002
postgreSQLPort: 4003
Loading

0 comments on commit 55a1cdf

Please sign in to comment.