Skip to content

Commit 28a87e1

Browse files
committed
Page and filter resource alerts on the server in alert tabs
1 parent 58b9be3 commit 28a87e1

3 files changed

Lines changed: 60 additions & 104 deletions

File tree

‎ui/src/components/view/ResourceAlertFiredTab.vue‎

Lines changed: 0 additions & 97 deletions
This file was deleted.

‎ui/src/components/view/ResourceAlertsTab.vue‎

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,21 @@
1717

1818
<template>
1919
<div>
20+
<a-select
21+
v-model:value="severity"
22+
style="width: 200px; margin-bottom: 12px"
23+
@change="onFilterChange">
24+
<a-select-option value="">{{ $t('label.severity') }}: {{ $t('label.all') }}</a-select-option>
25+
<a-select-option v-for="s in severities" :key="s" :value="s">{{ s }}</a-select-option>
26+
</a-select>
2027
<a-table
2128
size="small"
2229
:columns="columns"
2330
:dataSource="alerts"
2431
:rowKey="item => item.id"
2532
:loading="tabLoading"
26-
:pagination="{ pageSize: 20, showSizeChanger: true }">
33+
:pagination="pagination"
34+
@change="onTableChange">
2735
<template #bodyCell="{ column, text }">
2836
<template v-if="column.key === 'alerttimestamp'">
2937
{{ $toLocaleDate(text) }}
@@ -42,6 +50,7 @@
4250
<script>
4351
import { getAPI } from '@/api'
4452
53+
// Shows the alerts of one resource, or of one rule when no resourceType is given.
4554
export default {
4655
name: 'ResourceAlertsTab',
4756
props: {
@@ -51,19 +60,27 @@ export default {
5160
},
5261
resourceType: {
5362
type: String,
54-
required: true
63+
default: ''
5564
},
5665
loading: {
5766
type: Boolean,
5867
default: false
5968
}
6069
},
6170
data () {
71+
const firstColumn = this.resourceType
72+
? { title: this.$t('label.alertrulename'), dataIndex: 'alertrulename', key: 'alertrulename' }
73+
: { title: this.$t('label.resourcename'), dataIndex: 'resourcename', key: 'resourcename' }
6274
return {
6375
alerts: [],
6476
tabLoading: false,
77+
severity: '',
78+
severities: ['CRITICAL', 'HIGH', 'MEDIUM', 'LOW'],
79+
page: 1,
80+
pageSize: 20,
81+
total: 0,
6582
columns: [
66-
{ title: this.$t('label.alertrulename'), dataIndex: 'alertrulename', key: 'alertrulename' },
83+
firstColumn,
6784
{ title: this.$t('label.metrictype'), dataIndex: 'metrictype', key: 'metrictype' },
6885
{ title: this.$t('label.metricvalue'), dataIndex: 'metricvalue', key: 'metricvalue' },
6986
{ title: this.$t('label.severity'), dataIndex: 'severity', key: 'severity' },
@@ -72,26 +89,62 @@ export default {
7289
]
7390
}
7491
},
92+
computed: {
93+
pagination () {
94+
return {
95+
current: this.page,
96+
pageSize: this.pageSize,
97+
total: this.total,
98+
showSizeChanger: true,
99+
showTotal: total => `${this.$t('label.total')} ${total} ${this.$t('label.items')}`
100+
}
101+
}
102+
},
75103
created () {
76104
this.fetchData()
77105
},
78106
watch: {
79107
resource: {
80-
handler () {
108+
handler (newItem, oldItem) {
109+
if (newItem?.id !== oldItem?.id) {
110+
this.page = 1
111+
this.severity = ''
112+
}
81113
this.fetchData()
82114
}
83115
}
84116
},
85117
methods: {
86118
fetchData () {
87119
if (!this.resource || !this.resource.id) return
120+
const params = { listall: true, page: this.page, pagesize: this.pageSize }
121+
if (this.resourceType) {
122+
params.resourcetype = this.resourceType
123+
params.resourceid = this.resource.id
124+
} else {
125+
params.alertruleid = this.resource.id
126+
}
127+
if (this.severity) {
128+
params.severity = this.severity
129+
}
88130
this.tabLoading = true
89-
getAPI('listResourceAlerts', { resourcetype: this.resourceType, resourceid: this.resource.id, listall: true }).then(json => {
90-
this.alerts = json?.listresourcealertsresponse?.resourcealert || []
131+
getAPI('listResourceAlerts', params).then(json => {
132+
const response = json?.listresourcealertsresponse || {}
133+
this.alerts = response.resourcealert || []
134+
this.total = response.count || 0
91135
}).finally(() => {
92136
this.tabLoading = false
93137
})
94138
},
139+
onFilterChange () {
140+
this.page = 1
141+
this.fetchData()
142+
},
143+
onTableChange (pagination) {
144+
this.page = pagination.current
145+
this.pageSize = pagination.pageSize
146+
this.fetchData()
147+
},
95148
severityColor (severity) {
96149
const map = { CRITICAL: 'red', HIGH: 'orange', MEDIUM: 'gold', LOW: 'blue' }
97150
return map[severity] || 'default'

‎ui/src/config/section/infra/resourceAlertRules.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default {
3838
component: shallowRef(defineAsyncComponent(() => import('@/components/view/DetailsTab.vue')))
3939
}, {
4040
name: 'firedalerts',
41-
component: shallowRef(defineAsyncComponent(() => import('@/components/view/ResourceAlertFiredTab.vue'))),
41+
component: shallowRef(defineAsyncComponent(() => import('@/components/view/ResourceAlertsTab.vue'))),
4242
show: () => { return 'listResourceAlerts' in store.getters.apis }
4343
}],
4444
actions: [

0 commit comments

Comments
 (0)