Commit dbacf097 authored by Mike Greiling's avatar Mike Greiling

Merge branch '5456-add-cluster-health-alert-frontend' into 'master'

Add frontend support for cluster health alerts

Closes #5456

See merge request gitlab-org/gitlab-ee!13443
parents 47f15257 f4f2d269
...@@ -4,6 +4,10 @@ class Projects::ClustersController < Clusters::ClustersController ...@@ -4,6 +4,10 @@ class Projects::ClustersController < Clusters::ClustersController
prepend_before_action :project prepend_before_action :project
before_action :repository before_action :repository
before_action do
push_frontend_feature_flag(:prometheus_computed_alerts)
end
layout 'project' layout 'project'
private private
......
...@@ -15,6 +15,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -15,6 +15,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
push_frontend_feature_flag(:environment_metrics_use_prometheus_endpoint) push_frontend_feature_flag(:environment_metrics_use_prometheus_endpoint)
push_frontend_feature_flag(:environment_metrics_show_multiple_dashboards) push_frontend_feature_flag(:environment_metrics_show_multiple_dashboards)
push_frontend_feature_flag(:grafana_dashboard_link) push_frontend_feature_flag(:grafana_dashboard_link)
push_frontend_feature_flag(:prometheus_computed_alerts)
end end
def index def index
......
...@@ -67,6 +67,9 @@ export default { ...@@ -67,6 +67,9 @@ export default {
formDisabled() { formDisabled() {
return Boolean(this.errorMessage || this.isLoading); return Boolean(this.errorMessage || this.isLoading);
}, },
supportsComputedAlerts() {
return gon.features && gon.features.prometheusComputedAlerts;
},
}, },
watch: { watch: {
isOpen(open) { isOpen(open) {
...@@ -200,7 +203,11 @@ export default { ...@@ -200,7 +203,11 @@ export default {
<icon :name="alertIcon" :size="16" aria-hidden="true" /> <icon :name="alertIcon" :size="16" aria-hidden="true" />
<icon :size="16" name="arrow-down" aria-hidden="true" class="chevron" /> <icon :size="16" name="arrow-down" aria-hidden="true" class="chevron" />
</button> </button>
<div ref="dropdownMenu" :class="{ show: isOpen }" class="dropdown-menu alert-dropdown-menu"> <div
ref="dropdownMenu"
:class="{ show: isOpen, 'h-auto': supportsComputedAlerts }"
class="dropdown-menu alert-dropdown-menu"
>
<div class="dropdown-title m0"> <div class="dropdown-title m0">
<span>{{ dropdownTitle }}</span> <span>{{ dropdownTitle }}</span>
<button <button
...@@ -212,7 +219,7 @@ export default { ...@@ -212,7 +219,7 @@ export default {
<icon :size="12" name="close" aria-hidden="true" /> <icon :size="12" name="close" aria-hidden="true" />
</button> </button>
</div> </div>
<div class="dropdown-content"> <div :class="{ 'mh-100': supportsComputedAlerts }" class="dropdown-content">
<alert-widget-form <alert-widget-form
ref="widgetForm" ref="widgetForm"
:disabled="formDisabled" :disabled="formDisabled"
......
...@@ -4,7 +4,14 @@ import _ from 'underscore'; ...@@ -4,7 +4,14 @@ import _ from 'underscore';
import Vue from 'vue'; import Vue from 'vue';
import Translate from '~/vue_shared/translate'; import Translate from '~/vue_shared/translate';
import { alertsValidator, queriesValidator } from '../validators'; import { alertsValidator, queriesValidator } from '../validators';
import { GlDropdown, GlDropdownItem } from '@gitlab/ui'; import {
GlFormGroup,
GlFormInput,
GlDropdown,
GlDropdownItem,
GlTooltipDirective,
} from '@gitlab/ui';
import Icon from '~/vue_shared/components/icon.vue';
Vue.use(Translate); Vue.use(Translate);
...@@ -28,8 +35,14 @@ const OPERATORS = { ...@@ -28,8 +35,14 @@ const OPERATORS = {
export default { export default {
components: { components: {
GlFormGroup,
GlFormInput,
GlDropdown, GlDropdown,
GlDropdownItem, GlDropdownItem,
Icon,
},
directives: {
GlTooltipDirective,
}, },
props: { props: {
disabled: { disabled: {
...@@ -55,16 +68,24 @@ export default { ...@@ -55,16 +68,24 @@ export default {
threshold: null, threshold: null,
prometheusMetricId: null, prometheusMetricId: null,
selectedAlert: {}, selectedAlert: {},
alertQuery: '',
}; };
}, },
computed: { computed: {
isValidQuery() {
// TODO: Add query validation check (most likely via http request)
return this.alertQuery.length ? true : null;
},
currentQuery() { currentQuery() {
return this.relevantQueries.find(query => query.metricId === this.prometheusMetricId) || {}; return this.relevantQueries.find(query => query.metricId === this.prometheusMetricId) || {};
}, },
formDisabled() { formDisabled() {
// We need a prometheusMetricId to determine whether we're // We need a prometheusMetricId to determine whether we're
// creating/updating/deleting // creating/updating/deleting
return this.disabled || !this.prometheusMetricId; return this.disabled || !(this.prometheusMetricId || this.isValidQuery);
},
supportsComputedAlerts() {
return gon.features && gon.features.prometheusComputedAlerts;
}, },
queryDropdownLabel() { queryDropdownLabel() {
return this.currentQuery.label || s__('PrometheusAlerts|Select query'); return this.currentQuery.label || s__('PrometheusAlerts|Select query');
...@@ -137,12 +158,44 @@ export default { ...@@ -137,12 +158,44 @@ export default {
this.selectedAlert = {}; this.selectedAlert = {};
}, },
}, },
alertQueryText: {
label: __('Query'),
validFeedback: __('Query is valid'),
invalidFeedback: __('Invalid query'),
descriptionTooltip: __(
'Example: Usage = single query. (Requested) / (Capacity) = multiple queries combined into a formula.',
),
},
}; };
</script> </script>
<template> <template>
<div class="alert-form"> <div class="alert-form">
<gl-dropdown :text="queryDropdownLabel" class="form-group" toggle-class="dropdown-menu-toggle"> <gl-form-group
v-if="supportsComputedAlerts"
:label="$options.alertQueryText.label"
:valid-feedback="$options.alertQueryText.validFeedback"
:invalid-feedback="$options.alertQueryText.invalidFeedback"
:state="isValidQuery"
>
<gl-form-input v-model.trim="alertQuery" :state="isValidQuery" />
<template #description>
<div class="d-flex align-items-center">
{{ __('Single or combined queries') }}
<icon
v-gl-tooltip-directive="$options.alertQueryText.descriptionTooltip"
name="question"
class="prepend-left-4"
/>
</div>
</template>
</gl-form-group>
<gl-dropdown
v-else
:text="queryDropdownLabel"
class="form-group"
toggle-class="dropdown-menu-toggle"
>
<gl-dropdown-item <gl-dropdown-item
v-for="query in relevantQueries" v-for="query in relevantQueries"
:key="query.metricId" :key="query.metricId"
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
%h4= s_('ClusterIntegration|Cluster health') %h4= s_('ClusterIntegration|Cluster health')
- if @cluster&.application_prometheus_available? - if @cluster&.application_prometheus_available?
#prometheus-graphs{ data: cluster_health_data(@cluster) } #prometheus-graphs{ data: cluster_health_data(@cluster).merge({ "alerts-endpoint" => ('/' if Feature.enabled?(:prometheus_computed_alerts)),
"prometheus-alerts-available" => ('true' if Feature.enabled?(:prometheus_computed_alerts)) }) }
- else - else
%p.settings-message.text-center= s_("ClusterIntegration|In order to view the health of your cluster, you must first install Prometheus below.") %p.settings-message.text-center= s_("ClusterIntegration|In order to view the health of your cluster, you must first install Prometheus below.")
...@@ -5167,6 +5167,9 @@ msgstr "" ...@@ -5167,6 +5167,9 @@ msgstr ""
msgid "Everything you need to create a GitLab Pages site using plain HTML." msgid "Everything you need to create a GitLab Pages site using plain HTML."
msgstr "" msgstr ""
msgid "Example: Usage = single query. (Requested) / (Capacity) = multiple queries combined into a formula."
msgstr ""
msgid "Except policy:" msgid "Except policy:"
msgstr "" msgstr ""
...@@ -7156,6 +7159,9 @@ msgstr "" ...@@ -7156,6 +7159,9 @@ msgstr ""
msgid "Invalid pin code" msgid "Invalid pin code"
msgstr "" msgstr ""
msgid "Invalid query"
msgstr ""
msgid "Invalid repository path" msgid "Invalid repository path"
msgstr "" msgstr ""
...@@ -10668,6 +10674,9 @@ msgstr "" ...@@ -10668,6 +10674,9 @@ msgstr ""
msgid "Query" msgid "Query"
msgstr "" msgstr ""
msgid "Query is valid"
msgstr ""
msgid "Quick actions can be used in the issues description and comment boxes." msgid "Quick actions can be used in the issues description and comment boxes."
msgstr "" msgstr ""
...@@ -11983,6 +11992,9 @@ msgstr "" ...@@ -11983,6 +11992,9 @@ msgstr ""
msgid "Similar issues" msgid "Similar issues"
msgstr "" msgstr ""
msgid "Single or combined queries"
msgstr ""
msgid "Size" msgid "Size"
msgstr "" msgstr ""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment