Skip to content

Commit

Permalink
Merge pull request #141 from earthgecko/py3
Browse files Browse the repository at this point in the history
Record anomaly_end_timestamp (webapp)
  • Loading branch information
earthgecko committed Nov 8, 2019
2 parents 539d96e + 1a6549f commit 7bd986b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion skyline/panorama/panorama.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@ def run(self):
if metric_var_files:
break

# @added 20191107 - Feature #3306: Record the end_timestamp of anomalies
# @added 20191107 - Feature #3306: Record anomaly_end_timestamp
# Branch #3262: py3
# Set the anomaly_end_timestamp for any metrics no longer anomalous
redis_set = 'current.anomalies'
Expand Down
22 changes: 18 additions & 4 deletions skyline/webapp/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ def get_ids_from_rows(thing, rows):

if latest_anomalies:
logger.info('Getting latest anomalies')
query = 'select id, metric_id, anomalous_datapoint, anomaly_timestamp, full_duration, created_timestamp from anomalies ORDER BY id DESC LIMIT 10'
# @modified 20191108 - Feature #3306: Record the anomaly_end_timestamp
# Branch #3262: py3
# query = 'select id, metric_id, anomalous_datapoint, anomaly_timestamp, full_duration, created_timestamp from anomalies ORDER BY id DESC LIMIT 10'
query = 'select id, metric_id, anomalous_datapoint, anomaly_timestamp, full_duration, created_timestamp, anomaly_end_timestamp from anomalies ORDER BY id DESC LIMIT 10'
try:
rows = mysql_select(skyline_app, query)
except:
Expand All @@ -136,7 +139,11 @@ def get_ids_from_rows(thing, rows):

if not latest_anomalies:
logger.info('Determining search parameters')
query_string = 'select id, metric_id, anomalous_datapoint, anomaly_timestamp, full_duration, created_timestamp from anomalies'
# @modified 20191108 - Feature #3306: Record the end_timestamp of anomalies
# Branch #3262: py3
# query_string = 'select id, metric_id, anomalous_datapoint, anomaly_timestamp, full_duration, created_timestamp from anomalies'
query_string = 'select id, metric_id, anomalous_datapoint, anomaly_timestamp, full_duration, created_timestamp, anomaly_end_timestamp from anomalies'

needs_and = False

# If we have to '' a string we cannot escape the query it seems...
Expand Down Expand Up @@ -391,11 +398,18 @@ def get_ids_from_rows(thing, rows):
if search_request:
anomalous_datapoint = str(row[2])
anomaly_timestamp = str(row[3])
anomaly_timestamp = str(row[3])
full_duration = str(row[4])
created_timestamp = str(row[5])
anomaly_data = (anomaly_id, metric, anomalous_datapoint, anomaly_timestamp, full_duration, created_timestamp)
anomalies.append([int(anomaly_id), str(metric), anomalous_datapoint, anomaly_timestamp, full_duration, created_timestamp])
# @modified 20191108 - Feature #3306: Record the anomaly_end_timestamp
# Branch #3262: py3
# anomaly_data = (anomaly_id, metric, anomalous_datapoint, anomaly_timestamp, full_duration, created_timestamp)
# anomalies.append([int(anomaly_id), str(metric), anomalous_datapoint, anomaly_timestamp, full_duration, created_timestamp])
anomaly_end_timestamp = str(row[6])
anomaly_data = (anomaly_id, metric, anomalous_datapoint, anomaly_timestamp, full_duration, created_timestamp, anomaly_end_timestamp)
anomalies.append([int(anomaly_id), str(metric), anomalous_datapoint, anomaly_timestamp, full_duration, created_timestamp, anomaly_end_timestamp])
anomalous_metrics.append(str(metric))

if count_request:
limit_argument = anomaly_count
if int(anomaly_count) > 100:
Expand Down
7 changes: 7 additions & 0 deletions skyline/webapp/static/js/panorama.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ var handle_data = function(panorama_data) {
full_duration = metric[4];
from_timestamp = (until_timestamp - full_duration);
created_date = metric[5];
// @added 20191108 - Feature #3306: Record the anomaly_end_timestamp
// Branch #3262: py3
anomaly_end_timestamp = metric[6];

time_shift = parseInt(full_duration) / 24;
five_percent_seconds = Math.round((parseInt(full_duration) / 100) * 5);
Expand Down Expand Up @@ -123,6 +126,10 @@ dygraph-1.1.1 */
full_duration = panorama_data[0][4];
created_date = panaroma_date[0][5];
from_timestamp = (until_timestamp - full_duration);
// @added 20191108 - Feature #3306: Record the anomaly_end_timestamp
// Branch #3262: py3
anomaly_end_timestamp = parseInt(anomaly_end_timestamp);

time_shift = parseInt(full_duration) / 24;

five_percent_seconds = Math.round((parseInt(full_duration) / 100) * 5);
Expand Down
9 changes: 9 additions & 0 deletions skyline/webapp/templates/panorama.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ <h6>{{ results }} :: {{ anomalies|length }} anomalies</h6>
<th>metric</th>
<th>datapoint</th>
<th>timestamp</th>
<th>end_timestamp</th>
<th>anomaly_duration</th>
<th>full_duration</th>
<th>created</th>
{% endif %}
Expand All @@ -130,6 +132,13 @@ <h6>{{ results }} :: {{ anomalies|length }} anomalies</h6>
<td> {{ item[1] }} </td>
<td> {{ item[2] }} </td>
<td> {{ item[3] }} </td>
{% if item[6] == 'None' %}
<td> {{ item[6] }} </td>
<td>Unknown</td>
{% else %}
<td> {{ item[6] }} </td>
<td> {{ ((item[6] | int) - (item[3] | int)) }} </td>
{% endif %}
<td> {{ item[4] }} </td>
<td> {{ item[5] }} </td>
{% endif %}
Expand Down

0 comments on commit 7bd986b

Please sign in to comment.