mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-16 02:27:40 +02:00
health-check: add storage health check (#5074)
This commit is contained in:
parent
2da4801d3a
commit
08eb255bbf
3 changed files with 26 additions and 0 deletions
|
@ -17,6 +17,7 @@ import (
|
|||
"github.com/pomerium/pomerium/internal/signal"
|
||||
"github.com/pomerium/pomerium/pkg/contextutil"
|
||||
"github.com/pomerium/pomerium/pkg/grpc/databroker"
|
||||
"github.com/pomerium/pomerium/pkg/health"
|
||||
"github.com/pomerium/pomerium/pkg/storage"
|
||||
)
|
||||
|
||||
|
@ -78,6 +79,16 @@ func New(dsn string, options ...Option) *Backend {
|
|||
return backend.listenForNotifications(ctx)
|
||||
}, time.Millisecond*100)
|
||||
|
||||
go backend.doPeriodically(func(ctx context.Context) error {
|
||||
err := backend.ping(ctx)
|
||||
if err != nil {
|
||||
health.ReportError(health.StorageBackend, err, health.StrAttr("backend", "postgres"))
|
||||
} else {
|
||||
health.ReportOK(health.StorageBackend, health.StrAttr("backend", "postgres"))
|
||||
}
|
||||
return nil
|
||||
}, time.Minute)
|
||||
|
||||
return backend
|
||||
}
|
||||
|
||||
|
@ -440,6 +451,15 @@ func (backend *Backend) listenForNotifications(ctx context.Context) error {
|
|||
}
|
||||
}
|
||||
|
||||
func (backend *Backend) ping(ctx context.Context) error {
|
||||
_, pool, err := backend.init(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return pool.Ping(ctx)
|
||||
}
|
||||
|
||||
// ParseConfig parses a DSN into a pgxpool.Config.
|
||||
func ParseConfig(dsn string) (*pgxpool.Config, error) {
|
||||
config, err := pgxpool.ParseConfig(dsn)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue