Skip to content

Commit

Permalink
Log around config.FromConnStr to diagnose slow DNS SRV resolution (#6255
Browse files Browse the repository at this point in the history
)
  • Loading branch information
bbrks authored May 19, 2023
1 parent c3146d8 commit cb6aef7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions base/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ const (

// ServerlessChannelLimit is hard limit on channels allowed per user when running in serverless mode
ServerlessChannelLimit = 500

// FromConnStrWarningThreshold determines the amount of time it should take before we warn about parsing a connstr (mostly for DNS resolution)
FromConnStrWarningThreshold = 10 * time.Second
)

const (
Expand Down
7 changes: 7 additions & 0 deletions base/dcp_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,17 @@ func (dc *DCPClient) initAgent(spec BucketSpec) error {
}

agentConfig := gocbcore.DCPAgentConfig{}
DebugfCtx(context.TODO(), KeyAll, "Parsing cluster connection string %q", UD(connStr))
beforeFromConnStr := time.Now()
connStrError := agentConfig.FromConnStr(connStr)
if connStrError != nil {
return fmt.Errorf("Unable to start DCP Client - error building conn str: %v", connStrError)
}
if d := time.Since(beforeFromConnStr); d > FromConnStrWarningThreshold {
WarnfCtx(context.TODO(), "Parsed cluster connection string %q in: %v", UD(connStr), d)
} else {
DebugfCtx(context.TODO(), KeyAll, "Parsed cluster connection string %q in: %v", UD(connStr), d)
}

auth, authErr := spec.GocbcoreAuthProvider()
if authErr != nil {
Expand Down
11 changes: 9 additions & 2 deletions rest/server_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -1523,10 +1523,17 @@ func initClusterAgent(ctx context.Context, clusterAddress, clusterUser, clusterP
},
}

base.DebugfCtx(ctx, base.KeyAll, "Parsing cluster connection string %q", base.UD(clusterAddress))
beforeFromConnStr := time.Now()
err = config.FromConnStr(clusterAddress)
if err != nil {
return nil, err
}
if d := time.Since(beforeFromConnStr); d > base.FromConnStrWarningThreshold {
base.WarnfCtx(ctx, "Parsed cluster connection string %q in: %v", base.UD(clusterAddress), d)
} else {
base.DebugfCtx(ctx, base.KeyAll, "Parsed cluster connection string %q in: %v", base.UD(clusterAddress), d)
}

agent, err := gocbcore.CreateAgent(&config)
if err != nil {
Expand Down Expand Up @@ -1838,9 +1845,9 @@ func (sc *ServerContext) Database(ctx context.Context, name string) *db.Database
}

func (sc *ServerContext) initializeCouchbaseServerConnections(ctx context.Context) error {
base.InfofCtx(ctx, base.KeyAll, "initializing server connections")
base.InfofCtx(ctx, base.KeyAll, "Initializing server connections")
defer func() {
base.InfofCtx(ctx, base.KeyAll, "finished initializing server connections")
base.InfofCtx(ctx, base.KeyAll, "Finished initializing server connections")
}()
goCBAgent, err := sc.initializeGoCBAgent(ctx)
if err != nil {
Expand Down

0 comments on commit cb6aef7

Please sign in to comment.