Skip to content

Commit

Permalink
Merge pull request banzaicloud#337 from mrsheepuk/fail-on-store-error
Browse files Browse the repository at this point in the history
Check product store is ready on startup
  • Loading branch information
sagikazarmark authored Jul 6, 2020
2 parents 2864956 + b342ef0 commit 7dcf274
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/cloudinfo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ func main() {
// use the configured store implementation
cloudInfoStore := cistore.NewCloudInfoStore(config.Store, cloudInfoLogger)
defer cloudInfoStore.Close()
if !cloudInfoStore.Ready() {
emperror.Panic(errors.New("configured product store not available"))
}

infoers, providers, err := loadInfoers(config, cloudInfoLogger)
emperror.Panic(err)
Expand Down
10 changes: 10 additions & 0 deletions internal/app/cloudinfo/cistore/cassandra.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ func NewCassandraProductStore(config cassandra.Config, logger cloudinfo.Logger)
}
}

func (cps *cassandraProductStore) Ready() bool {
err := cps.initSession()
if err != nil {
cps.log.Error("failure checking cassandra ready", map[string]interface{}{"error": err})
return false
}
cps.log.Debug("casandra product store ready")
return true
}

func (cps *cassandraProductStore) StoreRegions(provider, service string, val map[string]string) {
cps.set(cps.getKey(cloudinfo.RegionKeyTemplate, provider, service), val)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/app/cloudinfo/cistore/go-cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type cacheProductStore struct {
log cloudinfo.Logger
}

func (cis *cacheProductStore) Ready() bool {
return true
}

func (cis *cacheProductStore) DeleteRegions(provider, service string) {
cis.Delete(cis.getKey(cloudinfo.RegionKeyTemplate, provider, service))
}
Expand Down
17 changes: 17 additions & 0 deletions internal/app/cloudinfo/cistore/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ type redisProductStore struct {
log cloudinfo.Logger
}

func (rps *redisProductStore) Ready() bool {
conn := rps.pool.Get()
defer conn.Close()

reply, err := conn.Do("PING")
if err != nil {
rps.log.Error("failure checking redis ready", map[string]interface{}{"error": err})
return false
}
if reply != "PONG" {
rps.log.Error("redis PING returned unexpected value")
return false
}
rps.log.Debug("redis product store ready")
return true
}

func (rps *redisProductStore) DeleteRegions(provider, service string) {
rps.delete(rps.getKey(cloudinfo.RegionKeyTemplate, provider, service))
}
Expand Down
2 changes: 2 additions & 0 deletions internal/cloudinfo/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const (

// Storage operations for cloud information
type CloudInfoStore interface {
Ready() bool

StoreRegions(provider, service string, val map[string]string)
GetRegions(provider, service string) (map[string]string, bool)
DeleteRegions(provider, service string)
Expand Down

0 comments on commit 7dcf274

Please sign in to comment.