Skip to content

Commit

Permalink
Add better logging for fdb client calls (FoundationDB#1317)
Browse files Browse the repository at this point in the history
  • Loading branch information
johscheuer authored and JoshuaMcManus committed Aug 26, 2022
1 parent 15c07f7 commit 9da98e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
5 changes: 2 additions & 3 deletions fdbclient/admin_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func NewCliAdminClient(cluster *fdbv1beta2.FoundationDBCluster, _ client.Client,
if err != nil {
return nil, err
}
clusterFilePath := clusterFile.Name()

defer clusterFile.Close()
_, err = clusterFile.WriteString(cluster.Status.ConnectionString)
Expand All @@ -101,7 +100,7 @@ func NewCliAdminClient(cluster *fdbv1beta2.FoundationDBCluster, _ client.Client,
return nil, err
}

return &cliAdminClient{Cluster: cluster, clusterFilePath: clusterFilePath, useClientLibrary: true, log: log}, nil
return &cliAdminClient{Cluster: cluster, clusterFilePath: clusterFile.Name(), useClientLibrary: true, log: log}, nil
}

// cliCommand describes a command that we are running against FDB.
Expand Down Expand Up @@ -614,7 +613,7 @@ func (client *cliAdminClient) GetConnectionString() (string, error) {
if client.Cluster.UseManagementAPI() {
// This will call directly the database and fetch the connection string
// from the system key space.
connectionStringBytes, err = getConnectionStringFromDB(client.Cluster)
connectionStringBytes, err = getConnectionStringFromDB(client.Cluster, client.log)
} else {
var output string
output, err = client.runCommandWithBackoff("status minimal")
Expand Down
13 changes: 8 additions & 5 deletions fdbclient/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ func getFDBDatabase(cluster *fdbv1beta2.FoundationDBCluster) (fdb.Database, erro
return database, nil
}

func getValueFromDBUsingKey(cluster *fdbv1beta2.FoundationDBCluster, fdbKey string, extraTimeout int64) ([]byte, error) {
func getValueFromDBUsingKey(cluster *fdbv1beta2.FoundationDBCluster, log logr.Logger, fdbKey string, extraTimeout int64) ([]byte, error) {
log.Info("Fetch values from FDB", "namespace", cluster.Namespace, "cluster", cluster.Name, "key", fdbKey)
defer func() {
log.Info("Done fetching values from FDB", "namespace", cluster.Namespace, "cluster", cluster.Name, "key", fdbKey)
}()
database, err := getFDBDatabase(cluster)
if err != nil {
return nil, err
Expand Down Expand Up @@ -116,14 +120,13 @@ func getValueFromDBUsingKey(cluster *fdbv1beta2.FoundationDBCluster, fdbKey stri
}

// getConnectionStringFromDB gets the database's connection string directly from the system key
func getConnectionStringFromDB(cluster *fdbv1beta2.FoundationDBCluster) ([]byte, error) {
return getValueFromDBUsingKey(cluster, "\xff\xff/connection_string", 1)
func getConnectionStringFromDB(cluster *fdbv1beta2.FoundationDBCluster, log logr.Logger) ([]byte, error) {
return getValueFromDBUsingKey(cluster, log, "\xff\xff/connection_string", 1)
}

// getStatusFromDB gets the database's status directly from the system key
func getStatusFromDB(cluster *fdbv1beta2.FoundationDBCluster, log logr.Logger) ([]byte, error) {
log.Info("Fetch status from FDB", "namespace", cluster.Namespace, "cluster", cluster.Name)
return getValueFromDBUsingKey(cluster, "\xff\xff/status/json", 1000)
return getValueFromDBUsingKey(cluster, log, "\xff\xff/status/json", 1000)
}

type realDatabaseClientProvider struct {
Expand Down

0 comments on commit 9da98e1

Please sign in to comment.