Skip to content

Commit

Permalink
Merge pull request #557 from earthgecko/SNAB
Browse files Browse the repository at this point in the history
Correct misspelt function file
  • Loading branch information
earthgecko authored May 3, 2022
2 parents 8da1298 + 3be095d commit a56c1a8
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 38 deletions.
2 changes: 1 addition & 1 deletion skyline/analyzer/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ def run_selected_algorithm(
# @added 20201127 - Feature #3566: custom_algorithms
# Handle if the result is None
if result is None:
logger.warn('warning :: algorithms :: %s failed to run on %s' % (
logger.warning('warning :: algorithms :: %s failed to run on %s' % (
str(custom_algorithm), str(base_name)))
else:
if custom_consensus == 1:
Expand Down
14 changes: 14 additions & 0 deletions skyline/webapp/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,13 @@ def get_cluster_data(api_endpoint, data_required, only_host='all', endpoint_para
logger.error('error :: get_cluster_data :: failed to get %s from %s' % (
api_endpoint, str(item)))
if r:
# @added 20220503 - Feature #4530: namespace.analysed_events
# Added 404 to handle resource not on cluster node
if r.status_code == 404:
logger.warning('get_cluster_data :: %s from %s responded with status code %s and reason %s' % (
api_endpoint, str(item), str(r.status_code), str(r.reason)))
return data

if r.status_code != 200:
logger.error('error :: get_cluster_data :: %s from %s responded with status code %s and reason %s' % (
api_endpoint, str(item), str(r.status_code), str(r.reason)))
Expand Down Expand Up @@ -1040,6 +1047,13 @@ def get_cluster_data(api_endpoint, data_required, only_host='all', endpoint_para
str(remote_data), str(data_required), str(item[0])))
data.append(remote_data)
else:
# @added 20220503 - Feature #4530: namespace.analysed_events
# Added 404 to handle resource not on cluster node
if r.status_code == 404:
logger.warning('get_cluster_data :: %s from %s responded with status code %s and reason %s' % (
api_endpoint, str(item), str(r.status_code), str(r.reason)))
return data

logger.error('error :: get_cluster_data :: failed to get response from %s on %s' % (
api_endpoint, str(item)))

Expand Down
6 changes: 4 additions & 2 deletions skyline/webapp/ionosphere_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -7109,7 +7109,6 @@ def expected_features_profiles_dirs():
# logger.error('error :: could not determine fp_dir for fp_id %s' % str(fp_id))
# features_profiles_dirs_error_logged = True
fp_dir = None
pass
if not fp_dir:
try:
metric_id = fps[fp_id]['metric_id']
Expand All @@ -7119,7 +7118,10 @@ def expected_features_profiles_dirs():
fp_dir = '%s/%s/%s' % (
settings.IONOSPHERE_PROFILES_FOLDER, metric_timeseries_dir,
str(timestamp))
features_profile_dirs_dict[fp_id] = fp_dir
# @modified 20220503 - Feature #3890: metrics_manager - sync_cluster_files
# Use a str for jsonify
# features_profile_dirs_dict[fp_id] = fp_dir
features_profile_dirs_dict[str(fp_id)] = fp_dir
added_fps += 1
except:
logger.error(traceback.format_exc())
Expand Down
102 changes: 67 additions & 35 deletions skyline/webapp/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3343,6 +3343,13 @@ def api():

if 'metric' in request.args:
metric = request.args.get(str('metric'), None)

# @added 20220503 - Feature #4530: namespace.analysed_events
# Handle cluster_data
logger.info('/api?metric=%s' % str(metric))
timeseries = []
raw_series = None

try:
# @modified 20200225 - Bug #3266: py3 Redis binary objects not strings
# Branch #3262: py3
Expand All @@ -3354,13 +3361,13 @@ def api():
# @modified 20220115 - Bug #4374: webapp - handle url encoded chars
# Roll back change - breaking existing metrics with colons
# metric_name = url_encode_metric_name(metric_name)

raw_series = REDIS_CONN_UNDECODE.get(metric_name)
if not raw_series:
resp = json.dumps(
{'results': 'Error: No metric by that name - try /api?metric=' + settings.FULL_NAMESPACE + 'metric_namespace'})
return resp, 404
else:
except Exception as err:
logger.error(traceback.format_exc())
logger.error('error :: could not get raw data from Redis for %s' % metric)

if raw_series:
try:
unpacker = Unpacker(use_list=False)
unpacker.feed(raw_series)
# @modified 20201117 - Feature #3824: get_cluster_data
Expand All @@ -3370,36 +3377,61 @@ def api():
# Replace redefinition of item from line 1338
# timeseries = [item[:2] for item in unpacker]
timeseries = [ts_item[:2] for ts_item in unpacker]
# @added 20210416
remove_full_namespace_prefix = False
if 'remove_full_namespace_prefix' in request.args:
remove_full_namespace_prefix_str = request.args.get('remove_full_namespace_prefix', 'false')
if remove_full_namespace_prefix_str == 'true':
remove_full_namespace_prefix = True
if metric.startswith(settings.FULL_NAMESPACE):
metric = metric.replace(settings.FULL_NAMESPACE, '', 1)
if 'format' in request.args:
format = request.args.get(str('format'), 'pjson')
if format == 'json':
duration = (time.time() - start)
data_dict = {
"status": {
"cluster_data": cluster_data,
"format": format,
"response": 200,
"request_time": duration,
"remove_full_namespace_prefix": remove_full_namespace_prefix
},
"data": {
"metric": metric,
"timeseries": timeseries
}
except Exception as err:
logger.error(traceback.format_exc())
logger.error('error :: failed to unpack raw data from Redis for %s' % metric)

if not timeseries:
if settings.REMOTE_SKYLINE_INSTANCES and cluster_data:
redis_metric_data_uri = 'metric=%s&format=json' % str(metric)
try:
timeseries = get_cluster_data(redis_metric_data_uri, 'timeseries')
except:
logger.error(traceback.format_exc())
logger.error('error :: Webapp could not get timeseries from the remote Skyline instances')
if timeseries:
logger.info('got timeseries of length %s from the remote Skyline instances' % str(len(timeseries)))
else:
logger.warning('warning :: failed to get timeseries from the remote Skyline instances')

if not timeseries:
data_dict = {"status": {"cluster_data": cluster_data, "response": 404}}
return jsonify(data_dict), 404

resp = json.dumps(
{'results': 'Error: No metric by that name - try /api?metric=' + settings.FULL_NAMESPACE + 'metric_namespace'})
return resp, 404

try:
remove_full_namespace_prefix = False
if 'remove_full_namespace_prefix' in request.args:
remove_full_namespace_prefix_str = request.args.get('remove_full_namespace_prefix', 'false')
if remove_full_namespace_prefix_str == 'true':
remove_full_namespace_prefix = True
if metric.startswith(settings.FULL_NAMESPACE):
metric = metric.replace(settings.FULL_NAMESPACE, '', 1)
if 'format' in request.args:
use_format = request.args.get(str('format'), 'pjson')
if use_format == 'json':
duration = (time.time() - start)
data_dict = {
"status": {
"cluster_data": cluster_data,
"format": use_format,
"response": 200,
"request_time": duration,
"remove_full_namespace_prefix": remove_full_namespace_prefix
},
"data": {
"metric": metric,
"timeseries": timeseries
}
return jsonify(data_dict), 200
resp = json.dumps({'results': timeseries})
return resp, 200
except Exception as e:
error = "Error: " + str(e)
}
return jsonify(data_dict), 200
resp = json.dumps({'results': timeseries})
return resp, 200
except Exception as err:
error = "Error: " + str(err)
resp = json.dumps({'results': error})
return resp, 500

Expand Down

0 comments on commit a56c1a8

Please sign in to comment.