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

Fix : Incorrect MongoDB Connection Logs #1355

Merged
merged 20 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions pkg/gofr/datasource/mongo/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (c *Client) UseTracer(tracer any) {

// Connect establishes a connection to MongoDB and registers metrics using the provided configuration when the client was Created.
func (c *Client) Connect() {
c.logger.Debugf("connecting to MongoDB at %v to database %v", c.config.URI, c.config.Database)
c.logger.Debugf("connecting to MongoDB at %v to database %v", c.config.Host, c.config.Database)
coolwednesday marked this conversation as resolved.
Show resolved Hide resolved

uri := c.config.URI

Expand All @@ -108,18 +108,18 @@ func (c *Client) Connect() {
}

if err = m.Ping(ctx, nil); err != nil {
c.logger.Errorf("could not connect to mongoDB at %v due to err: %v", c.config.URI, err)
c.logger.Errorf("could not connect to mongoDB at %v due to err: %v", c.config.Host, err)
return
}

c.logger.Logf("connected to mongoDB successfully at %v to database %v", c.config.URI, c.config.Database)
c.logger.Logf("connected to mongoDB successfully at %v to database %v", c.config.Host, c.config.Database)

mongoBuckets := []float64{.05, .075, .1, .125, .15, .2, .3, .5, .75, 1, 2, 3, 4, 5, 7.5, 10}
c.metrics.NewHistogram("app_mongo_stats", "Response time of MONGO queries in milliseconds.", mongoBuckets...)
coolwednesday marked this conversation as resolved.
Show resolved Hide resolved

c.Database = m.Database(c.config.Database)

c.logger.Logf("connected to MongoDB at %v to database %v", uri, c.Database)
c.logger.Logf("connected to MongoDB at %v to database %v", c.config.Host, c.Database)
}

// InsertOne inserts a single document into the specified collection.
Expand Down
2 changes: 1 addition & 1 deletion pkg/gofr/datasource/mongo/mongo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func Test_NewMongoClientError(t *testing.T) {
logger.EXPECT().Debugf("connecting to MongoDB at %v to database %v", "mongo", "test")
logger.EXPECT().Errorf("error while connecting to MongoDB, err:%v", gomock.Any())

client := New(Config{URI: "mongo", Database: "test"})
client := New(Config{Host: "mongo", Database: "test"})
client.UseLogger(logger)
client.UseMetrics(metrics)
client.Connect()
Expand Down
Loading