Skip to content

Commit

Permalink
fix: failed to start frontend in gtctl playground
Browse files Browse the repository at this point in the history
  • Loading branch information
daviderli614 committed Jan 15, 2024
1 parent 6f534d2 commit 85e5389
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/cluster/baremetal/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (c *Cluster) Create(ctx context.Context, options *opt.CreateOptions) error
if err := withSpinner("Etcd Cluster", c.createEtcdCluster); err != nil {
return err
}
if err := withSpinner("Greptime Cluster", c.createCluster); err != nil {
if err := withSpinner("GreptimeDB Cluster", c.createCluster); err != nil {
if err := c.Wait(ctx, true); err != nil {
return err
}
Expand All @@ -65,7 +65,7 @@ func (c *Cluster) Create(ctx context.Context, options *opt.CreateOptions) error

func (c *Cluster) createCluster(ctx context.Context, options *opt.CreateOptions) error {
if options.Cluster == nil {
return fmt.Errorf("missing create greptime cluster options")
return fmt.Errorf("missing create greptimedb cluster options")
}
clusterOpt := options.Cluster

Expand Down
8 changes: 4 additions & 4 deletions pkg/cluster/kubernetes/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ func (c *Cluster) Create(ctx context.Context, options *opt.CreateOptions) error
return nil
}

if err := withSpinner("Greptime Operator", c.createOperator); err != nil {
if err := withSpinner("GreptimeDB Operator", c.createOperator); err != nil {
return err
}
if err := withSpinner("Etcd cluster", c.createEtcdCluster); err != nil {
return err
}
if err := withSpinner("Greptime cluster", c.createCluster); err != nil {
if err := withSpinner("GreptimeDB cluster", c.createCluster); err != nil {
return err
}

Expand All @@ -68,7 +68,7 @@ func (c *Cluster) Create(ctx context.Context, options *opt.CreateOptions) error
// createOperator creates GreptimeDB Operator.
func (c *Cluster) createOperator(ctx context.Context, options *opt.CreateOptions) error {
if options.Operator == nil {
return fmt.Errorf("missing create greptime operator options")
return fmt.Errorf("missing create greptimedb operator options")
}
operatorOpt := options.Operator
resourceName, resourceNamespace := OperatorName(), options.Namespace
Expand Down Expand Up @@ -107,7 +107,7 @@ func (c *Cluster) createOperator(ctx context.Context, options *opt.CreateOptions
// createCluster creates GreptimeDB cluster.
func (c *Cluster) createCluster(ctx context.Context, options *opt.CreateOptions) error {
if options.Cluster == nil {
return fmt.Errorf("missing create greptime cluster options")
return fmt.Errorf("missing create greptimedb cluster options")
}
clusterOpt := options.Cluster
resourceName, resourceNamespace := options.Name, options.Namespace
Expand Down
1 change: 1 addition & 0 deletions pkg/components/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,6 @@ func generateAddrArg(addr string, nodeId int) string {
// The "addr" is validated when set.
host, port, _ := net.SplitHostPort(addr)
portInt, _ := strconv.Atoi(port)

return net.JoinHostPort(host, strconv.Itoa(portInt+nodeId))
}
7 changes: 6 additions & 1 deletion pkg/config/baremetal.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ func DefaultBareMetalConfig() *BareMetalClusterConfig {
Version: artifacts.LatestVersionTag,
},
Frontend: &Frontend{
Replicas: 1,
Replicas: 1,
HTTPAddr: "0.0.0.0:4000",
GRPCAddr: "0.0.0.0:4001",
MysqlAddr: "0.0.0.0:4002",
PostgresAddr: "0.0.0.0:4003",
OpentsdbAddr: "0.0.0.0:4242",
},
MetaSrv: &MetaSrv{
Replicas: 1,
Expand Down
106 changes: 106 additions & 0 deletions tests/e2e/greptimedbcluster_playground_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright 2023 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 e2e

import (
"context"
"database/sql"
"fmt"
"os"
"os/exec"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/go-sql-driver/mysql"
)

var _ = Describe("Basic test of greptimedb cluster playground", func() {
It("Bootstrap cluster", func() {
var err error
go func() {
err = playground()
Expect(err).NotTo(HaveOccurred(), "failed to create cluster playground")
}()

By("Connecting GreptimeDB")
var db *sql.DB
var conn *sql.Conn

Eventually(func() error {
cfg := mysql.Config{
Net: "tcp",
Addr: "127.0.0.1:4200",
User: "",
Passwd: "",
DBName: "",
AllowNativePasswords: true,
}

db, err = sql.Open("mysql", cfg.FormatDSN())
if err != nil {
return err
}

conn, err = db.Conn(context.TODO())
if err != nil {
return err
}

return nil
}, 30*time.Second, time.Second).ShouldNot(HaveOccurred())

By("Execute SQL queries after connecting")

ctx, cancel := context.WithTimeout(context.Background(), defaultQueryTimeout)
defer cancel()

_, err = conn.ExecContext(ctx, createTableSQL)
Expect(err).NotTo(HaveOccurred(), "failed to create SQL table")

ctx, cancel = context.WithTimeout(context.Background(), defaultQueryTimeout)
defer cancel()
for rowID := 1; rowID <= testRowIDNum; rowID++ {
insertDataSQL := fmt.Sprintf(insertDataSQLStr, rowID, rowID)
_, err = conn.ExecContext(ctx, insertDataSQL)
Expect(err).NotTo(HaveOccurred(), "failed to insert data")
}

ctx, cancel = context.WithTimeout(context.Background(), defaultQueryTimeout)
defer cancel()
results, err := conn.QueryContext(ctx, selectDataSQL)
Expect(err).NotTo(HaveOccurred(), "failed to get data")

var data []TestData
for results.Next() {
var d TestData
err = results.Scan(&d.timestamp, &d.n, &d.rowID)
Expect(err).NotTo(HaveOccurred(), "failed to scan data that query from db")
data = append(data, d)
}
Expect(len(data) == testRowIDNum).Should(BeTrue(), "get the wrong data from db")
})
})

func playground() error {
cmd := exec.Command("../../bin/gtctl", "playground", "--config", "testdata/cluster.yaml")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return err
}
return nil
}
2 changes: 1 addition & 1 deletion tests/e2e/greptimedbcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func forwardRequest() {
for {
cmd := exec.Command("kubectl", "port-forward", "svc/mydb-frontend", "4002:4002")
if err := cmd.Run(); err != nil {
klog.Errorf("Failed to port forward:%v", err)
klog.Errorf("Failed to port forward: %v", err)
return
}
}
Expand Down
21 changes: 21 additions & 0 deletions tests/e2e/testdata/cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cluster:
name: mycluster # name of the cluster
artifact:
version: latest
frontend:
replicas: 1
mysqlAddr: 0.0.0.0:4200
datanode:
replicas: 3
rpcAddr: 0.0.0.0:14100
mysqlAddr: 0.0.0.0:14200
httpAddr: 0.0.0.0:14300
meta:
replicas: 1
storeAddr: 127.0.0.1:2379
serverAddr: 0.0.0.0:3002
httpAddr: 0.0.0.0:14001

etcd:
artifact:
version: v3.5.7

0 comments on commit 85e5389

Please sign in to comment.