Skip to content
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

Add links to alarms #1683

Merged
merged 5 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ var ALARM_WARNING_TEXT = `CPUUtilization > ${ALARM_WARNING_THRESHOLD}% is recomm
<div class="col-xs-10">
<input class="form-control" name="metricsUrl_{{ alarm.alarmId }}" required="true"
type="text" v-model="metrics"/>
<a href="{{ alarm.cwLink }}" target="_blank">CloudWatch alarm link (for reference only)</a>
<a href="{{ alarm.previewUrl }}" target="_blank" v-show="showPreviewUrl"> | Custom metric source link (for reference only)</a>
</div>
</div>

Expand Down Expand Up @@ -91,7 +93,7 @@ var ALARM_WARNING_TEXT = `CPUUtilization > ${ALARM_WARNING_THRESHOLD}% is recomm
{% endif %}
</div>
</div>

<form-warning v-show="showWarning" :alert-text="warning"></form-warning>
</fieldset>
{% csrf_token %}
Expand Down Expand Up @@ -128,6 +130,7 @@ let alarmVue = new Vue({
showWarning: false,
warning: ALARM_WARNING_TEXT,
threshold: {{ alarm.threshold }},
showPreviewUrl: "{{ alarm.previewUrl }}" != "" ? true : false,
},
methods: {
showWarningIfNeeded: function() {
Expand Down
10 changes: 10 additions & 0 deletions deploy-board/deploy_board/webapp/group_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
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,
hosts_helper, accounts_helper)
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__)

Expand Down Expand Up @@ -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
Expand All @@ -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?#alarmsV2:alarm/{alarm["groupName"]}-alarm-{alarm["alarmId"]}'

aws_metric_names = [
"CPUUtilization",
Expand Down
Loading