Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debuggin integration test failures #6371

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions cmd/server/cadence/cadence.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/uber/cadence/common"
"github.com/uber/cadence/common/client"
"github.com/uber/cadence/common/config"
"github.com/uber/cadence/common/log/loggerimpl"
"github.com/uber/cadence/common/persistence/nosql/nosqlplugin/cassandra/gocql"
"github.com/uber/cadence/common/service"
"github.com/uber/cadence/tools/cassandra"
Expand All @@ -57,8 +58,15 @@ func startHandler(c *cli.Context) error {
if err != nil {
return fmt.Errorf("Config file corrupted: %w", err)
}

zapLogger, err := cfg.Log.NewZapLogger()
if err != nil {
log.Fatal("failed to create the zap logger, err: ", err.Error())
}
rootLogger := loggerimpl.NewLogger(zapLogger)

if cfg.Log.Level == "debug" {
log.Printf("config=%v", cfg.String())
zapLogger.Sugar().Debugf("config=%v", cfg.String())
}
if cfg.DynamicConfig.Client == "" {
cfg.DynamicConfigClient.Filepath = constructPathIfNeed(rootDir, cfg.DynamicConfigClient.Filepath)
Expand All @@ -83,13 +91,13 @@ func startHandler(c *cli.Context) error {
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, syscall.SIGTERM, syscall.SIGINT)
for _, svc := range services {
server := newServer(svc, &cfg)
server := newServer(svc, &cfg, rootLogger)
daemons = append(daemons, server)
server.Start()
}

<-sigc
log.Println("Received SIGTERM signal, initiating shutdown.")
rootLogger.Info("Received SIGTERM signal, initiating shutdown.")
for _, daemon := range daemons {
daemon.Stop()
}
Expand Down
26 changes: 12 additions & 14 deletions cmd/server/cadence/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
"github.com/uber/cadence/common/dynamicconfig/configstore"
"github.com/uber/cadence/common/elasticsearch"
"github.com/uber/cadence/common/isolationgroup/isolationgroupapi"
"github.com/uber/cadence/common/log/loggerimpl"
cadenceLog "github.com/uber/cadence/common/log"
"github.com/uber/cadence/common/log/tag"
"github.com/uber/cadence/common/membership"
"github.com/uber/cadence/common/messaging/kafka"
Expand All @@ -60,20 +60,22 @@ import (

type (
server struct {
name string
cfg *config.Config
doneC chan struct{}
daemon common.Daemon
name string
cfg *config.Config
doneC chan struct{}
daemon common.Daemon
rootLogger cadenceLog.Logger
}
)

// newServer returns a new instance of a daemon
// that represents a cadence service
func newServer(service string, cfg *config.Config) common.Daemon {
func newServer(service string, cfg *config.Config, rootLogger cadenceLog.Logger) common.Daemon {
return &server{
cfg: cfg,
name: service,
doneC: make(chan struct{}),
cfg: cfg,
name: service,
doneC: make(chan struct{}),
rootLogger: rootLogger,
}
}

Expand Down Expand Up @@ -111,11 +113,7 @@ func (s *server) startService() common.Daemon {
params := resource.Params{}
params.Name = service.FullName(s.name)

zapLogger, err := s.cfg.Log.NewZapLogger()
if err != nil {
log.Fatal("failed to create the zap logger, err: ", err.Error())
}
params.Logger = loggerimpl.NewLogger(zapLogger).WithTags(tag.Service(params.Name))
params.Logger = s.rootLogger.WithTags(tag.Service(params.Name))

params.PersistenceConfig = s.cfg.Persistence

Expand Down
6 changes: 5 additions & 1 deletion cmd/server/cadence/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ import (
"github.com/uber/cadence/common"
"github.com/uber/cadence/common/config"
"github.com/uber/cadence/common/dynamicconfig"
cadenceLog "github.com/uber/cadence/common/log"
"github.com/uber/cadence/common/log/loggerimpl"
"github.com/uber/cadence/common/log/testlogger"
"github.com/uber/cadence/common/persistence/nosql/nosqlplugin/cassandra/gocql"
"github.com/uber/cadence/common/resource"
"github.com/uber/cadence/common/service"
Expand All @@ -51,6 +53,7 @@ import (
type ServerSuite struct {
*require.Assertions
suite.Suite
logger cadenceLog.Logger
}

func TestServerSuite(t *testing.T) {
Expand All @@ -60,6 +63,7 @@ func TestServerSuite(t *testing.T) {

func (s *ServerSuite) SetupTest() {
s.Assertions = require.New(s.T())
s.logger = testlogger.New(s.T())
}

/*
Expand Down Expand Up @@ -107,7 +111,7 @@ func (s *ServerSuite) TestServerStartup() {
var daemons []common.Daemon
services := service.ShortNames(service.List)
for _, svc := range services {
server := newServer(svc, &cfg)
server := newServer(svc, &cfg, s.logger)
daemons = append(daemons, server)
server.Start()
}
Expand Down
8 changes: 4 additions & 4 deletions common/persistence/nosql/nosqlplugin/cassandra/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (db *cdb) SetupTestDatabase(schemaBaseDir string, replicas int) error {
// loadSchema from PersistenceTestCluster interface
func (db *cdb) loadSchema(fileNames []string, schemaBaseDir string) error {
workflowSchemaDir := schemaBaseDir + "/cadence"
err := loadCassandraSchema(workflowSchemaDir, fileNames, db.cfg.Hosts, db.cfg.Port, db.cfg.Keyspace, true, nil, db.cfg.ProtoVersion)
err := db.loadCassandraSchema(workflowSchemaDir, fileNames, db.cfg.Hosts, db.cfg.Port, db.cfg.Keyspace, true, nil, db.cfg.ProtoVersion)
if err != nil && !strings.Contains(err.Error(), "AlreadyExists") {
// TODO: should we remove the second condition?
return err
Expand All @@ -79,7 +79,7 @@ func (db *cdb) loadSchema(fileNames []string, schemaBaseDir string) error {
// loadVisibilitySchema from PersistenceTestCluster interface
func (db *cdb) loadVisibilitySchema(fileNames []string, schemaBaseDir string) error {
workflowSchemaDir := schemaBaseDir + "/visibility"
err := loadCassandraSchema(workflowSchemaDir, fileNames, db.cfg.Hosts, db.cfg.Port, db.cfg.Keyspace, false, nil, db.cfg.ProtoVersion)
err := db.loadCassandraSchema(workflowSchemaDir, fileNames, db.cfg.Hosts, db.cfg.Port, db.cfg.Keyspace, false, nil, db.cfg.ProtoVersion)
if err != nil && !strings.Contains(err.Error(), "AlreadyExists") {
// TODO: should we remove the second condition?
return err
Expand Down Expand Up @@ -129,7 +129,7 @@ func (db *cdb) dropCassandraKeyspace(s gocql.Session, keyspace string) (err erro
}

// loadCassandraSchema loads the schema from the given .cql files on this keyspace
func loadCassandraSchema(
func (db *cdb) loadCassandraSchema(
dir string,
fileNames []string,
hosts string,
Expand Down Expand Up @@ -177,7 +177,7 @@ func loadCassandraSchema(
},
}

err = cassandra.SetupSchema(config)
err = cassandra.SetupSchema(config, db.logger)
if err != nil {
err = fmt.Errorf("error loading schema:%v", err.Error())
}
Expand Down
6 changes: 3 additions & 3 deletions common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,9 @@
logger.Error("Error serializing history: %v\n", tag.Error(err))
}

fmt.Println("******************************************")
fmt.Println("History", tag.DetailInfo(string(data)))
fmt.Println("******************************************")
logger.Debug("******************************************")
logger.Debug("History", tag.DetailInfo(string(data)))
logger.Debug("******************************************")

Check warning on line 345 in common/util.go

View check run for this annotation

Codecov / codecov/patch

common/util.go#L343-L345

Added lines #L343 - L345 were not covered by tests
}

// IsValidContext checks that the thrift context is not expired on cancelled.
Expand Down
3 changes: 0 additions & 3 deletions host/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package host

import (
"math/rand"
"sync/atomic"
"time"

Expand Down Expand Up @@ -173,8 +172,6 @@ func (h *serviceImpl) Start() {

// The service is now started up
h.logger.Info("service started")
// seed the random generator once for this service
rand.Seed(time.Now().UTC().UnixNano())
}

// Stop closes the associated transport
Expand Down
5 changes: 3 additions & 2 deletions tools/cassandra/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/urfave/cli/v2"

"github.com/uber/cadence/common/log"
"github.com/uber/cadence/common/persistence/nosql/nosqlplugin/cassandra/gocql"
"github.com/uber/cadence/tools/common/schema"
)
Expand All @@ -36,15 +37,15 @@ func RunTool(args []string) error {
}

// SetupSchema setups the cassandra schema
func SetupSchema(config *SetupSchemaConfig) error {
func SetupSchema(config *SetupSchemaConfig, logger log.Logger) error {
if err := validateCQLClientConfig(&config.CQLClientConfig); err != nil {
return err
}
db, err := NewCQLClient(&config.CQLClientConfig, gocql.All)
if err != nil {
return err
}
return schema.SetupFromConfig(&config.SetupConfig, db)
return schema.SetupFromConfig(&config.SetupConfig, logger, db)
}

// root handler for all cli commands
Expand Down
41 changes: 24 additions & 17 deletions tools/common/schema/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"os"

"github.com/urfave/cli/v2"

"github.com/uber/cadence/common/log"
"github.com/uber/cadence/common/log/loggerimpl"
)

// VerifyCompatibleVersion ensures that the installed version is greater than or equal to the expected version.
Expand Down Expand Up @@ -52,66 +55,70 @@
}

// SetupFromConfig sets up schema tables based on the given config
func SetupFromConfig(config *SetupConfig, db SchemaClient) error {
func SetupFromConfig(config *SetupConfig, logger log.Logger, db SchemaClient) error {

Check warning on line 58 in tools/common/schema/handler.go

View check run for this annotation

Codecov / codecov/patch

tools/common/schema/handler.go#L58

Added line #L58 was not covered by tests
if err := validateSetupConfig(config); err != nil {
return err
}
return newSetupSchemaTask(db, config).Run()
return newSetupSchemaTask(db, logger, config).Run()

Check warning on line 62 in tools/common/schema/handler.go

View check run for this annotation

Codecov / codecov/patch

tools/common/schema/handler.go#L62

Added line #L62 was not covered by tests
}

// Setup sets up schema tables
func Setup(cli *cli.Context, db SchemaClient) error {
cfg, err := newSetupConfig(cli)
cfg, logger, err := newSetupConfig(cli)

Check warning on line 67 in tools/common/schema/handler.go

View check run for this annotation

Codecov / codecov/patch

tools/common/schema/handler.go#L67

Added line #L67 was not covered by tests
if err != nil {
return err
}
return newSetupSchemaTask(db, cfg).Run()
return SetupFromConfig(cfg, logger, db)

Check warning on line 71 in tools/common/schema/handler.go

View check run for this annotation

Codecov / codecov/patch

tools/common/schema/handler.go#L71

Added line #L71 was not covered by tests
}

// UpdateFromConfig updates the schema for the specified database based on the given config
func UpdateFromConfig(config *UpdateConfig, db SchemaClient) error {
func UpdateFromConfig(config *UpdateConfig, logger log.Logger, db SchemaClient) error {

Check warning on line 75 in tools/common/schema/handler.go

View check run for this annotation

Codecov / codecov/patch

tools/common/schema/handler.go#L75

Added line #L75 was not covered by tests
if err := validateUpdateConfig(config); err != nil {
return err
}
return NewUpdateSchemaTask(db, config).Run()
return NewUpdateSchemaTask(db, logger, config).Run()

Check warning on line 79 in tools/common/schema/handler.go

View check run for this annotation

Codecov / codecov/patch

tools/common/schema/handler.go#L79

Added line #L79 was not covered by tests
}

// Update updates the schema for the specified database
func Update(cli *cli.Context, db SchemaClient) error {
cfg, err := newUpdateConfig(cli)
cfg, logger, err := newUpdateConfig(cli)

Check warning on line 84 in tools/common/schema/handler.go

View check run for this annotation

Codecov / codecov/patch

tools/common/schema/handler.go#L84

Added line #L84 was not covered by tests
if err != nil {
return err
}
return NewUpdateSchemaTask(db, cfg).Run()
return UpdateFromConfig(cfg, logger, db)

Check warning on line 88 in tools/common/schema/handler.go

View check run for this annotation

Codecov / codecov/patch

tools/common/schema/handler.go#L88

Added line #L88 was not covered by tests
}

func newUpdateConfig(cli *cli.Context) (*UpdateConfig, error) {
func newUpdateConfig(cli *cli.Context) (*UpdateConfig, log.Logger, error) {

Check warning on line 91 in tools/common/schema/handler.go

View check run for this annotation

Codecov / codecov/patch

tools/common/schema/handler.go#L91

Added line #L91 was not covered by tests
config := new(UpdateConfig)
schemaDir := cli.String(CLIOptSchemaDir)
if len(schemaDir) == 0 {
return nil, NewConfigError("missing " + flag(CLIOptSchemaDir) + " argument ")
return nil, nil, NewConfigError("missing " + flag(CLIOptSchemaDir) + " argument ")

Check warning on line 95 in tools/common/schema/handler.go

View check run for this annotation

Codecov / codecov/patch

tools/common/schema/handler.go#L95

Added line #L95 was not covered by tests
}
config.SchemaFS = os.DirFS(schemaDir)
config.IsDryRun = cli.Bool(CLIOptDryrun)
config.TargetVersion = cli.String(CLIOptTargetVersion)

if err := validateUpdateConfig(config); err != nil {
return nil, err
logger, err := loggerimpl.NewDevelopment()
if err != nil {
return nil, nil, fmt.Errorf("build logger: %w", err)

Check warning on line 103 in tools/common/schema/handler.go

View check run for this annotation

Codecov / codecov/patch

tools/common/schema/handler.go#L101-L103

Added lines #L101 - L103 were not covered by tests
}
return config, nil

return config, logger, nil

Check warning on line 106 in tools/common/schema/handler.go

View check run for this annotation

Codecov / codecov/patch

tools/common/schema/handler.go#L106

Added line #L106 was not covered by tests
}

func newSetupConfig(cli *cli.Context) (*SetupConfig, error) {
func newSetupConfig(cli *cli.Context) (*SetupConfig, log.Logger, error) {

Check warning on line 109 in tools/common/schema/handler.go

View check run for this annotation

Codecov / codecov/patch

tools/common/schema/handler.go#L109

Added line #L109 was not covered by tests
config := new(SetupConfig)
config.SchemaFilePath = cli.String(CLIOptSchemaFile)
config.InitialVersion = cli.String(CLIOptVersion)
config.DisableVersioning = cli.Bool(CLIOptDisableVersioning)
config.Overwrite = cli.Bool(CLIOptOverwrite)

if err := validateSetupConfig(config); err != nil {
return nil, err
logger, err := loggerimpl.NewDevelopment()
if err != nil {
return nil, nil, fmt.Errorf("build logger: %w", err)

Check warning on line 118 in tools/common/schema/handler.go

View check run for this annotation

Codecov / codecov/patch

tools/common/schema/handler.go#L116-L118

Added lines #L116 - L118 were not covered by tests
}
return config, nil

return config, logger, nil

Check warning on line 121 in tools/common/schema/handler.go

View check run for this annotation

Codecov / codecov/patch

tools/common/schema/handler.go#L121

Added line #L121 was not covered by tests
}

func validateSetupConfig(config *SetupConfig) error {
Expand Down
Loading
Loading