Skip to content

Commit

Permalink
chore: disable db-metrics by default
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Oct 17, 2023
1 parent 6bc390d commit 0173bdb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func init() {

Root.PersistentFlags().StringVar(&db.ConnectionString, "db", "DB_URL", "Connection string for the postgres database")
Root.PersistentFlags().BoolVar(&db.RunMigrations, "db-migrations", false, "Run database migrations")
Root.PersistentFlags().BoolVar(&db.DbMetrics, "db-metrics", false, "Expose db metrics")
Root.PersistentFlags().BoolVar(&logFail, "log-fail", true, "Log every failing check")
Root.PersistentFlags().BoolVar(&logPass, "log-pass", false, "Log every passing check")
Root.PersistentFlags().StringArrayVar(&sharedLibrary, "shared-library", []string{}, "Add javascript files to be shared by all javascript templates")
Expand Down
25 changes: 14 additions & 11 deletions pkg/db/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var Gorm *gorm.DB
var ConnectionString string
var DefaultExpiryDays int
var RunMigrations bool
var DbMetrics bool

Check failure on line 25 in pkg/db/init.go

View workflow job for this annotation

GitHub Actions / lint

ST1003: var DbMetrics should be DBMetrics (stylecheck)
var PostgresServer *embeddedpostgres.EmbeddedPostgres
var HTTPEndpoint = "http://localhost:8080/db"

Expand Down Expand Up @@ -101,17 +102,19 @@ func Init() error {
return 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 DbMetrics {
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 {
opts := &migrate.MigrateOptions{IgnoreFiles: []string{"007_events.sql", "012_changelog.sql"}}
Expand Down

0 comments on commit 0173bdb

Please sign in to comment.