From 87f0047a32cb6159cbfbb2b7e5baf7feeb368d52 Mon Sep 17 00:00:00 2001 From: Tyler Ouyang Date: Thu, 1 Aug 2024 14:17:59 -0700 Subject: [PATCH 1/5] Add links to alarms --- .../deploy_board/templates/groups/asg_metrics.tmpl | 6 +++++- deploy-board/deploy_board/webapp/group_view.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/deploy-board/deploy_board/templates/groups/asg_metrics.tmpl b/deploy-board/deploy_board/templates/groups/asg_metrics.tmpl index 21038752ab..493b2359d1 100644 --- a/deploy-board/deploy_board/templates/groups/asg_metrics.tmpl +++ b/deploy-board/deploy_board/templates/groups/asg_metrics.tmpl @@ -36,6 +36,9 @@ var ALARM_WARNING_TEXT = `CPUUtilization > ${ALARM_WARNING_THRESHOLD}% is recomm
+ CloudWatch alarm link + | + Alarm source link
@@ -91,7 +94,7 @@ var ALARM_WARNING_TEXT = `CPUUtilization > ${ALARM_WARNING_THRESHOLD}% is recomm {% endif %} - + {% csrf_token %} @@ -128,6 +131,7 @@ let alarmVue = new Vue({ showWarning: false, warning: ALARM_WARNING_TEXT, threshold: {{ alarm.threshold }}, + showPreviewUrl: "{{ alarm.previewUrl }}" != "None" ? true : false, }, methods: { showWarningIfNeeded: function() { diff --git a/deploy-board/deploy_board/webapp/group_view.py b/deploy-board/deploy_board/webapp/group_view.py index 86e8074076..8dacc4b074 100644 --- a/deploy-board/deploy_board/webapp/group_view.py +++ b/deploy-board/deploy_board/webapp/group_view.py @@ -25,6 +25,7 @@ import json import logging import traceback +import urllib.parse from .helpers import (environs_helper, clusters_helper, hosttypes_helper, groups_helper, baseimages_helper, specs_helper, autoscaling_groups_helper, autoscaling_metrics_helper, placements_helper, @@ -32,6 +33,7 @@ from diff_match_patch import diff_match_patch from deploy_board import settings from .helpers.exceptions import NotFoundException, TeletraanException +from .templatetags.utils import itemToComparator log = logging.getLogger(__name__) @@ -682,6 +684,11 @@ def _parse_metrics_configs(request, group_name): return configs +def _construct_alarm_preview_url(metric, comparator, threshold, evaluation_time): + encoded_url = urllib.parse.quote( + f'{{"forms":[{{"metric":"{ metric }"}}],"crit":"(d{itemToComparator(comparator)}{threshold}).for({evaluation_time}m)"}}' + ) + return 'https://statsboard.pinadmin.com/build3?settings=' + encoded_url def get_alarms(request, group_name): comparators = autoscaling_groups_helper.Comparator @@ -694,6 +701,9 @@ def get_alarms(request, group_name): # we restrict alarm has only one scaling policy policy = alarm["scalingPolicies"][0] alarm["scalingType"] = policy["policyType"] + if not alarm["fromAwsMetric"]: + alarm["previewUrl"] = _construct_alarm_preview_url(alarm["metricSource"], alarm["comparator"], alarm["threshold"], alarm["evaluationTime"]) + alarm['cwLink'] = f'https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#alarmsV2:alarm/{alarm["groupName"]}-alarm-{alarm["alarmId"]}' aws_metric_names = [ "CPUUtilization", From a6854b1bafe254e6d8e3117a896fd4e76d77ed57 Mon Sep 17 00:00:00 2001 From: Tyler Ouyang Date: Thu, 1 Aug 2024 14:27:46 -0700 Subject: [PATCH 2/5] Fix issue --- deploy-board/deploy_board/templates/groups/asg_metrics.tmpl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/deploy-board/deploy_board/templates/groups/asg_metrics.tmpl b/deploy-board/deploy_board/templates/groups/asg_metrics.tmpl index 493b2359d1..371737e39f 100644 --- a/deploy-board/deploy_board/templates/groups/asg_metrics.tmpl +++ b/deploy-board/deploy_board/templates/groups/asg_metrics.tmpl @@ -37,8 +37,7 @@ var ALARM_WARNING_TEXT = `CPUUtilization > ${ALARM_WARNING_THRESHOLD}% is recomm CloudWatch alarm link - | - Alarm source link + | Custom metric source link @@ -131,7 +130,7 @@ let alarmVue = new Vue({ showWarning: false, warning: ALARM_WARNING_TEXT, threshold: {{ alarm.threshold }}, - showPreviewUrl: "{{ alarm.previewUrl }}" != "None" ? true : false, + showPreviewUrl: "{{ alarm.previewUrl }}" != "" ? true : false, }, methods: { showWarningIfNeeded: function() { From eb30b4eb09391bc4209980471be539ea02c8c544 Mon Sep 17 00:00:00 2001 From: Tyler Ouyang Date: Thu, 1 Aug 2024 14:33:03 -0700 Subject: [PATCH 3/5] Update urls --- deploy-board/deploy_board/templates/groups/asg_metrics.tmpl | 4 ++-- deploy-board/deploy_board/webapp/group_view.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/deploy-board/deploy_board/templates/groups/asg_metrics.tmpl b/deploy-board/deploy_board/templates/groups/asg_metrics.tmpl index 371737e39f..41fb41edd6 100644 --- a/deploy-board/deploy_board/templates/groups/asg_metrics.tmpl +++ b/deploy-board/deploy_board/templates/groups/asg_metrics.tmpl @@ -36,8 +36,8 @@ var ALARM_WARNING_TEXT = `CPUUtilization > ${ALARM_WARNING_THRESHOLD}% is recomm diff --git a/deploy-board/deploy_board/webapp/group_view.py b/deploy-board/deploy_board/webapp/group_view.py index 8dacc4b074..9ef2bbcb60 100644 --- a/deploy-board/deploy_board/webapp/group_view.py +++ b/deploy-board/deploy_board/webapp/group_view.py @@ -703,7 +703,7 @@ def get_alarms(request, group_name): alarm["scalingType"] = policy["policyType"] if not alarm["fromAwsMetric"]: alarm["previewUrl"] = _construct_alarm_preview_url(alarm["metricSource"], alarm["comparator"], alarm["threshold"], alarm["evaluationTime"]) - alarm['cwLink'] = f'https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#alarmsV2:alarm/{alarm["groupName"]}-alarm-{alarm["alarmId"]}' + alarm['cwLink'] = f'https://console.aws.amazon.com/cloudwatch/home?alarmsV2:alarm/{alarm["groupName"]}-alarm-{alarm["alarmId"]}' aws_metric_names = [ "CPUUtilization", From 49389a36d1de3508372e8bb4ed9001dcff466e31 Mon Sep 17 00:00:00 2001 From: Tyler Ouyang Date: Thu, 1 Aug 2024 15:37:50 -0700 Subject: [PATCH 4/5] typo --- deploy-board/deploy_board/templates/groups/asg_metrics.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy-board/deploy_board/templates/groups/asg_metrics.tmpl b/deploy-board/deploy_board/templates/groups/asg_metrics.tmpl index 41fb41edd6..861914d3c3 100644 --- a/deploy-board/deploy_board/templates/groups/asg_metrics.tmpl +++ b/deploy-board/deploy_board/templates/groups/asg_metrics.tmpl @@ -36,8 +36,8 @@ var ALARM_WARNING_TEXT = `CPUUtilization > ${ALARM_WARNING_THRESHOLD}% is recomm From a156612d6a7a9719aeb9f8737af7e89379c221d8 Mon Sep 17 00:00:00 2001 From: Tyler Ouyang Date: Thu, 1 Aug 2024 19:04:36 -0700 Subject: [PATCH 5/5] add # --- deploy-board/deploy_board/webapp/group_view.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy-board/deploy_board/webapp/group_view.py b/deploy-board/deploy_board/webapp/group_view.py index 9ef2bbcb60..d8fedbf8c3 100644 --- a/deploy-board/deploy_board/webapp/group_view.py +++ b/deploy-board/deploy_board/webapp/group_view.py @@ -703,7 +703,7 @@ def get_alarms(request, group_name): alarm["scalingType"] = policy["policyType"] if not alarm["fromAwsMetric"]: alarm["previewUrl"] = _construct_alarm_preview_url(alarm["metricSource"], alarm["comparator"], alarm["threshold"], alarm["evaluationTime"]) - alarm['cwLink'] = f'https://console.aws.amazon.com/cloudwatch/home?alarmsV2:alarm/{alarm["groupName"]}-alarm-{alarm["alarmId"]}' + alarm['cwLink'] = f'https://console.aws.amazon.com/cloudwatch/home?#alarmsV2:alarm/{alarm["groupName"]}-alarm-{alarm["alarmId"]}' aws_metric_names = [ "CPUUtilization",