-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Timescale backend teething troubles (#237)
* cast postgres port to int * extend jsondict to support case-insensitive path lookups. * make translator lookup case insensitive both on keys and values. * add logging of selected backend * expose ssl config switch.
- Loading branch information
Showing
12 changed files
with
233 additions
and
142 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,50 @@ | ||
import yaml | ||
import logging | ||
import os | ||
import yaml | ||
|
||
from translators.crate import CrateTranslatorInstance | ||
from translators.timescale import postgres_translator_instance | ||
from utils.jsondict import maybe_value | ||
from utils.jsondict import maybe_string_match | ||
|
||
|
||
CRATE_BACKEND = 'Crate' | ||
TIMESCALE_BACKEND = 'Timescale' | ||
CRATE_BACKEND = 'crate' | ||
TIMESCALE_BACKEND = 'timescale' | ||
|
||
QL_CONFIG_ENV_VAR = 'QL_CONFIG' | ||
|
||
|
||
def log(): | ||
logging.basicConfig(level=logging.INFO) | ||
return logging.getLogger(__name__) | ||
|
||
|
||
def read_config() -> dict: | ||
path = os.environ.get(QL_CONFIG_ENV_VAR) | ||
if path: | ||
log().info(f"using config file: {path}") | ||
file = open(path) | ||
return yaml.safe_load(file) | ||
|
||
log().info(f"no config file specified, using defaults.") | ||
return {} | ||
|
||
|
||
def translator_for(fiware_service: str): | ||
config = read_config() | ||
backend = maybe_value(config, 'tenants', fiware_service, 'backend')\ | ||
or maybe_value(config, 'default-backend') | ||
backend = maybe_string_match(config, 'tenants', fiware_service, 'backend')\ | ||
or maybe_string_match(config, 'default-backend') | ||
backend = backend.strip().lower() if backend is not None else '' | ||
|
||
if backend == CRATE_BACKEND: | ||
return CrateTranslatorInstance() | ||
if backend == TIMESCALE_BACKEND: | ||
return postgres_translator_instance() | ||
return CrateTranslatorInstance() | ||
translator = CrateTranslatorInstance() | ||
selected = CRATE_BACKEND | ||
elif backend == TIMESCALE_BACKEND: | ||
translator = postgres_translator_instance() | ||
selected = TIMESCALE_BACKEND | ||
else: | ||
translator = CrateTranslatorInstance() | ||
selected = CRATE_BACKEND | ||
|
||
log().info( | ||
f"Backend selected for tenant '{fiware_service}' is: {selected}") | ||
return translator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,6 @@ tenants: | |
backend: Timescale | ||
t2: | ||
backend: Crate | ||
t3: | ||
T3: | ||
backend: Timescale | ||
default-backend: Crate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.