Skip to content

Commit

Permalink
Fix for "url" KeyError observed in public-dash redesign testing
Browse files Browse the repository at this point in the history
The bug was triggered by a .gitignore-d conf/ directory in public-dash which had a db.conf file.
This was being loaded when docker-compose.dev.yml was used to test the dev version of public-dash.

This was occurring since there was a nested dictionary in the db.conf.sample and db.conf files while I had initially only stored the nested keys (url, result_limit). Since it was still reading from the file, it stored the nested dictionary format with timeseries as the parent key followed by (url, result_limit) as children.

Hence, fixing it by adding the same nested dictionary structure in the emission/core/config.py and emission/core/get_database.py
  • Loading branch information
Mahadik, Mukul Chandrakant authored and Mahadik, Mukul Chandrakant committed Apr 30, 2024
1 parent 2e8a911 commit a0190d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions emission/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@

def get_config_data_from_env():
config_data_env = {
"url": os.getenv('DB_HOST', "localhost"),
"result_limit": os.getenv('DB_TS_RESULT_LIMIT', 250000)
"timeseries": {
"url": os.getenv('DB_HOST', "localhost"),
"result_limit": os.getenv('DB_TS_RESULT_LIMIT', 250000)
}
}
return config_data_env

def check_unset_env_vars():
config_data_env = {
"url": os.getenv('DB_HOST'),
"result_limit": os.getenv('DB_TS_RESULT_LIMIT')
"timeseries": {
"url": os.getenv('DB_HOST'),
"result_limit": os.getenv('DB_TS_RESULT_LIMIT')
}
}
return not any(config_data_env.values())

Expand All @@ -26,7 +30,7 @@ def get_config_data():
# if check_unset_env_vars():
# print("All DB environment variables are set to None")
ret_val = get_config_data_from_env()
if ret_val["url"] == "localhost":
if ret_val["timeseries"]["url"] == "localhost":
print("storage not configured, falling back to sample, default configuration")
return ret_val

Expand Down
4 changes: 2 additions & 2 deletions emission/core/get_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

import emission.core.config as ecc

url = ecc.get_config()["url"]
result_limit = ecc.get_config()["result_limit"]
url = ecc.get_config()["timeseries"]["url"]
result_limit = ecc.get_config()["timeseries"]["result_limit"]

try:
parsed=pymongo.uri_parser.parse_uri(url)
Expand Down

0 comments on commit a0190d4

Please sign in to comment.