Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated health endpoints for Timescale #377 #718

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ respectively for the query result as in e.g.
- Resolved TODO at src/reporter/tests/utils.py (#692)
- Added error handling in src/wq/ql/notify.py (#673)
- NGSI-LD tenant header (#664, #669)
- Updated health endpoint for Timescale (#377)

### Bug fixes

Expand Down
10 changes: 9 additions & 1 deletion src/reporter/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from geocoding.factory import get_geo_cache, is_geo_coding_available
from cache.factory import get_cache, is_cache_available
from translators.factory import CRATE_BACKEND, TIMESCALE_BACKEND, \
default_backend
default_backend, Timescale_backend


def check_db(db=CRATE_BACKEND):
Expand All @@ -20,6 +20,11 @@ def check_db(db=CRATE_BACKEND):
with postgres_translator_instance() as trans:
health = trans.get_health()
return health
if db2 == TIMESCALE_BACKEND:
from translators.timescale import postgres_translator_instance
with postgres_translator_instance() as trans:
health = trans.get_health()
return health


def check_cache():
Expand Down Expand Up @@ -82,11 +87,14 @@ def get_health(with_geocoder=False):

# Check defaultDB (critical)
db = default_backend().lower()
db2 = Timescale_backend().lower()
try:
res = _check_critical(check_db(db), res, db)
res = _check_critical(check_db(db2), res, db2)
except Exception:
res['status'] = 'fail'
res.setdefault('details', {})[db] = 'cannot reach ' + db
res.setdefault('details', {})[db2] = 'cannot reach ' + db2

# TODO add not critical check if a secondary db is configured

Expand Down
13 changes: 13 additions & 0 deletions src/translators/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ def default_backend() -> MaybeString:
return env_backend or config_backend or CRATE_BACKEND


def Timescale_backend() -> MaybeString:
cfg_reader = YamlReader(log=log().debug)
env_reader = EnvReader(log=log().debug)

config = cfg_reader.from_env_file(QL_CONFIG_ENV_VAR, defaults={})

config_backend = maybe_string_match(config, 'Timescale-backend')

env_backend = env_reader.read(StrVar(QL_DEFAULT_DB_ENV_VAR, None))

return env_backend or config_backend or TIMESCALE_BACKEND


def backend_id_for(fiware_service: str) -> str:
backend = lookup_backend(fiware_service)
backend = backend.strip().lower() if backend is not None else ''
Expand Down
Loading