-
Notifications
You must be signed in to change notification settings - Fork 17
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
Load dashboards for kibana on startup US314 #116
Load dashboards for kibana on startup US314 #116
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few minor comments, but nothing serious. Did not test.
scripts/loadAssets.py
Outdated
search_type = "search" | ||
session = requests.Session() | ||
# Retry on Internal Server Error (500) and Service Unavailable (503) | ||
retries = Retry(total=5, backoff_factor=0.3, status_forcelist=[ 500, 503]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want to retry on other errors here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added 408, 502, and 504.
scripts/exportAssets.py
Outdated
|
||
session = requests.Session() | ||
# Retry on Internal Server Error (500) and Service Unavailable (503) | ||
retries = Retry(total=5, backoff_factor=0.3, status_forcelist=[ 500, 503]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want to retry on other errors here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added:
- Request Timeout (408)
- Bad Gateway (502)
- Gateway timeout (504)
es_id, | ||
content) | ||
try: | ||
url = 'http://localhost:9200/.kibana/_doc/' + es_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we might want to grab the id from the imported file? If ever the es_id
and the id
from the dashboard differ, I'm not sure which id elastic search would take
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The id is not saved in the json, so not available there. I think we are depending on the name of the file to have the correct id.
scripts/loadAssets.py
Outdated
es_ok = check_elasticsearch_health() | ||
if es_ok: | ||
# Create arrays of the filenames in the resources directory | ||
objects = [filename for filename in listdir(resources) if isfile(join(resources, filename))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this iteration could get moved into the load_assets
function, with the only parameter to load_assets
being the path_to_files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Changed as suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments but just about python style, nothing that NEEDS to change 👍 - Reviewed but not tested.
scripts/exportAssets.py
Outdated
|
||
session = requests.Session() | ||
# Retry on Internal Server Error (500) and Service Unavailable (503) | ||
retries = Retry(total=5, backoff_factor=0.3, status_forcelist=[ 500, 503]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to retry for 502 (bad gateway) and 504 (gateway timeout) also potentially? https://httpstatuses.com/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
scripts/exportAssets.py
Outdated
return False | ||
|
||
def get_search_title_json(es_type, es_title): | ||
esField = es_type + '.title' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guido Van Rossum frowns upon your camel case, python PEP8 prefers snake case for functions and variables http://www.python.org/dev/peps/pep-0008/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guido is right. Changed to snake case.
session.mount('https://', HTTPAdapter(max_retries=retries)) | ||
session.mount('http://', HTTPAdapter(max_retries=retries)) | ||
esQuery = json.dumps(es_query) | ||
headers = { 'Content-type': 'application/json' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a lot of variability in this file between single and double quotes, might be good to pick one or the other and stick with them throughout for consistency. I tend to default to single quotes in python.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single quotes it is. Fixed.
scripts/exportAssets.py
Outdated
@@ -118,33 +162,40 @@ def main(argv): | |||
global OUTPUT_DIR | |||
global FILE_PATHS_AND_CONTENTS | |||
global TYPE | |||
global ID | |||
global TITLE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these globals are not "pythonic". Prefer passing as params and returning modified variables rather than modifying globals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
scripts/loadAssets.py
Outdated
es_ok = check_elasticsearch_health() | ||
if es_ok: | ||
# Create arrays of the filenames in the resources directory | ||
objects = [filename for filename in listdir(resources) if isfile(join(resources, filename))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh fancy list comprehension! ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kudos to @craig-cogdill
scripts/exportAssets.py
Outdated
else: | ||
print "ERROR: Did not find any " + TYPE + " named " + ID + " in Elasticsearch." | ||
sys.exit(2) | ||
print "elasticsearch is not ready\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be logger.error()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Again this lets the user know their request didn't work.
scripts/exportAssets.py
Outdated
get_all_dashboard_content_from_ES(dashboard_raw=UTIL.safe_list_read(list_ob=FILE_PATHS_AND_CONTENTS, key=get_full_path(asset_id=asset_id))) | ||
export_all_files() | ||
else: | ||
print "ERROR: Did not find any " + TYPE + " named " + TITLE + " in Elasticsearch." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be logger.error()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. In this case, the error has already been logged to file in the call to get_asset
. This output to the terminal lets the user know it failed. Added additional print statement to point the user to the log file for more info.
scripts/exportAssets.py
Outdated
|
||
session = requests.Session() | ||
# Retry on Internal Server Error (500) and Service Unavailable (503) | ||
retries = Retry(total=5, backoff_factor=0.3, status_forcelist=[ 500, 503]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space between [ 500,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Also added 408, 502, and 504.
scripts/exportAssets.py
Outdated
return True | ||
|
||
except Exception as err: | ||
logger.warning("[loadAssets.py] Caught HTTP exception: {0}".format(err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[loadAssets.py]
--> [exportAssets.py]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
scripts/exportAssets.py
Outdated
return True, response.text | ||
|
||
except Exception as err: | ||
logger.info("[getEs.py] Caught HTTP exception: {0}".format(err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[getEs.py]
--> [exportAssets.py]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
scripts/exportAssets.py
Outdated
if not response.ok: | ||
response.raise_for_status() | ||
|
||
logger.info("GET RETURNS: " + "\n" + UTIL.pretty_format(response.json())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could probably go before if not response.ok
so that we see an error response as well? Or we could remove it entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved before if not response.ok
scripts/exportAssets.py
Outdated
success, ret = get_asset(INDEX, panel_type, panel_id) | ||
es_query = get_search_id_json(panel_type, panel_id) | ||
success, asset_raw = get_asset(es_query) | ||
asset_id = panel_type + ":" + panel_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go in the if
block below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Fixed.
scripts/loadAssets.py
Outdated
load_assets(resources, objects) | ||
set_default_index_pattern() | ||
else: | ||
print "elasticsearch is not ready\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.error()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. In this case it makes sense because the script is run out of a systemd unit file.
Load dashboards for kibana on startup US314
See user story: https://rally1.rallydev.com/#/detail/userstory/334308455668