Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
Added connection success messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanratcliffe committed Jun 10, 2022
1 parent 70e9b8f commit 76a067e
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions dgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func (d DGraphConnectionOptions) Connect() (*dgo.Dgraph, error) {
"error": err.Error(),
}).Error("DGraph connection failed")
} else {
log.WithFields(log.Fields{
"server": server,
}).Info("DGraph connecton opened")

connections = append(connections, c)
}
}
Expand All @@ -76,14 +80,33 @@ func (d DGraphConnectionOptions) Connect() (*dgo.Dgraph, error) {
continue
}

apiClients := make([]api.DgraphClient, 0)
apiClients := make([]api.DgraphClient, len(connections))
serverFields := make(log.Fields)

for i, conn := range connections {
var versionString string

apiClients[i] = api.NewDgraphClient(conn)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

// Check the version and add to log fields
version, err := apiClients[i].CheckVersion(ctx, &api.Check{})

if err != nil || version == nil {
versionString = "unknown version"
} else {
versionString = version.Tag
}

for _, conn := range connections {
apiClients = append(apiClients, api.NewDgraphClient(conn))
serverFields[conn.Target()] = versionString
}

dGraphClient = dgo.NewDgraphClient(apiClients...)

log.WithFields(serverFields).Info("DGraph client created")

break
}

Expand Down

0 comments on commit 76a067e

Please sign in to comment.