diff --git a/cmd/cloudinfo/main.go b/cmd/cloudinfo/main.go index 641832c15..bbb80cffa 100644 --- a/cmd/cloudinfo/main.go +++ b/cmd/cloudinfo/main.go @@ -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) diff --git a/internal/app/cloudinfo/cistore/cassandra.go b/internal/app/cloudinfo/cistore/cassandra.go index 95b558ee2..ab926a392 100644 --- a/internal/app/cloudinfo/cistore/cassandra.go +++ b/internal/app/cloudinfo/cistore/cassandra.go @@ -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) } diff --git a/internal/app/cloudinfo/cistore/go-cache.go b/internal/app/cloudinfo/cistore/go-cache.go index 10589084e..6b57cd22f 100644 --- a/internal/app/cloudinfo/cistore/go-cache.go +++ b/internal/app/cloudinfo/cistore/go-cache.go @@ -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)) } diff --git a/internal/app/cloudinfo/cistore/redis.go b/internal/app/cloudinfo/cistore/redis.go index 262548678..8afb08363 100644 --- a/internal/app/cloudinfo/cistore/redis.go +++ b/internal/app/cloudinfo/cistore/redis.go @@ -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)) } diff --git a/internal/cloudinfo/store.go b/internal/cloudinfo/store.go index 3077011a3..03b0280c4 100644 --- a/internal/cloudinfo/store.go +++ b/internal/cloudinfo/store.go @@ -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)