Skip to content

Commit

Permalink
Merge pull request #1085 from flanksource/gorm-prom-in-routine
Browse files Browse the repository at this point in the history
chore: call gorm prometheus plugin in goroutine
  • Loading branch information
moshloop authored Jun 20, 2023
2 parents 8763b85 + 0f1c37a commit 8b3f32c
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions pkg/db/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,17 @@ func Init() error {
return err
}

if err := Gorm.Use(prometheus.New(prometheus.Config{
DBName: Pool.Config().ConnConfig.Database,
StartServer: false,
MetricsCollector: []prometheus.MetricsCollector{
&prometheus.Postgres{},
},
})); err != nil {
logger.Warnf("Failed to register prometheus metrics: %v", err)
}
go func() {
if err := Gorm.Use(prometheus.New(prometheus.Config{
DBName: Pool.Config().ConnConfig.Database,
StartServer: false,
MetricsCollector: []prometheus.MetricsCollector{
&prometheus.Postgres{},
},
})); err != nil {
logger.Warnf("Failed to register prometheus metrics: %v", err)
}
}()

if RunMigrations {
if err := duty.Migrate(ConnectionString, nil); err != nil {
Expand Down

0 comments on commit 8b3f32c

Please sign in to comment.