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

[IMPROVEMENT] Improve performance of rendering alerts and silences #372

Merged
merged 1 commit into from
Nov 16, 2021
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
29 changes: 12 additions & 17 deletions promgen/static/js/promgen.vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Vue.config.devtools = true

var dataStore = {
components: {},
selectedHosts: [],
newSilence: { 'labels': {} },
globalSilences: [],
Expand All @@ -18,7 +19,11 @@ var app = new Vue({
delimiters: ['[[', ']]'],
data: dataStore,
methods: {
toggleTarget: function (target) {
toggleComponent: function (component) {
let state = Boolean(this.components[component]);
this.$set(this.components, component, !state);
},
toggleCollapse: function (target) {
let tgt = document.getElementById(target);
tgt.classList.toggle('collapse');
},
Expand Down Expand Up @@ -52,7 +57,7 @@ var app = new Vue({
this.$delete(this.newSilence.labels, label)
},
showSilenceForm: function (event) {
document.getElementById('silence-form').classList.remove('collapse');
this.$set(this.components, 'silence-form', true);
scroll(0, 0);
},
silenceAppendLabel: function (event) {
Expand Down Expand Up @@ -123,43 +128,33 @@ var app = new Vue({
},
computed: {
alertLabelsService: function () {
return new Set(this.globalAlerts
.filter(x => x.status.state == 'active')
return new Set(this.filterActiveAlerts
.filter(x => x.labels.service)
.map(x => x.labels.service)
.sort()
);
},
alertLabelsProject: function () {
return new Set(this.globalAlerts
.filter(x => x.status.state == 'active')
return new Set(this.filterActiveAlerts
.filter(x => x.labels.project)
.map(x => x.labels.project)
.sort()
);
},
alertLabelsRule: function () {
return new Set(this.globalAlerts
.filter(x => x.status.state == 'active')
return new Set(this.filterActiveAlerts
.filter(x => x.labels.alertname)
.map(x => x.labels.alertname)
.sort()
);
},
silenceLabelsService: function () {
return new Set(this.globalSilences
.filter(x => x.status.state == 'active')
return new Set(this.filterActiveSilences
.filter(x => x.labels.service)
.map(x => x.labels.service)
.sort()
);
},
silenceLabelsProject: function () {
return new Set(this.globalSilences
.filter(x => x.status.state == 'active')
return new Set(this.filterActiveSilences
Comment on lines -158 to +155
Copy link
Contributor Author

@KarboniteKream KarboniteKream Nov 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior here has changed slightly. I noticed that filterActiveSilences was changed from state == 'active' to state != 'expired'. I think we want the same behavior here?

.filter(x => x.labels.project)
.map(x => x.labels.project)
.sort()
);
},
filterActiveAlerts: function () {
Expand Down
4 changes: 2 additions & 2 deletions promgen/templates/promgen/global_alerts.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="panel panel-danger collapse" id="globalAlerts">
<div v-cloak v-if="components['global-alerts']" class="panel panel-danger">
<div class="panel-heading">
Alerts
<a @click.prevent="toggleTarget('globalAlerts')" class="close" role="button">&times;</a>
<a @click="toggleComponent('global-alerts')" class="close" role="button">&times;</a>
</div>

<table class="table table-bordered table-condensed">
Expand Down
6 changes: 2 additions & 4 deletions promgen/templates/promgen/global_silences.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<div class="panel panel-warning collapse" id="globalSilences">
<div v-cloak v-if="components['global-silences']" class="panel panel-warning">
<div class="panel-heading">
Silences
<a @click.prevent="toggleTarget('globalSilences')" class="close" role="button" href="#">
&times;
</a>
<a @click="toggleComponent('global-silences')" class="close" role="button">&times;</a>
</div>
<table class="table table-bordered table-condensed table-responsive">
<tr>
Expand Down
7 changes: 4 additions & 3 deletions promgen/templates/promgen/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<li><a href="{% url 'audit-list' %}">Edit History</a></li>
<li><a href="{% url 'alert-list' %}">Alert History</a></li>
<li role="separator" class="divider"></li>

<li><a href="{% url 'site-detail' %}">Shared</a></li>
<li><a href="{% url 'farm-list' %}">Farms</a></li>
<li><a href="{% url 'host-list' %}">Hosts</a></li>
Expand Down Expand Up @@ -55,10 +55,11 @@
</div>
<button type="submit" class="btn btn-default">Search</button>
</form>
<a @click.prevent="toggleTarget('globalAlerts')" id="toggleAlerts" class="btn btn-danger navbar-btn" role="button">Alerts
<a @click="toggleComponent('global-alerts')" class="btn btn-danger navbar-btn" role="button">
Alerts
<span v-text="filterActiveAlerts.length" class="badge"></span>
</a>
<a @click.prevent="toggleTarget('globalSilences')" id="toggleSilences" class="btn btn-warning navbar-btn" role="button">
<a @click="toggleComponent('global-silences')" class="btn btn-warning navbar-btn" role="button">
Silences
<span v-text="filterActiveSilences.length" class="badge"></span>
</a>
Expand Down
8 changes: 4 additions & 4 deletions promgen/templates/promgen/project_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ <h1>

{% include "promgen/project_detail_configuration.html" %}

<div class="panel panel-danger" v-cloak v-show="alertLabelsProject.has('{{project.name}}')">
<div class="panel panel-danger" v-cloak v-if="alertLabelsProject.has('{{project.name}}')">
<div class="panel-heading">
<a @click.prevent="toggleTarget('alerts-project-{{project.name|slugify}}')" class="btn btn-danger btn-sm" role="button">Alerts</a>
<a @click="toggleCollapse('alerts-project-{{project.name|slugify}}')" class="btn btn-danger btn-sm" role="button">Alerts</a>
</div>
<table id="alerts-project-{{project.name|slugify}}" class="table table-bordered table-condensed">
<tr v-for="(alert, index) in globalAlerts" v-if="alert.labels.project == '{{project.name}}'">
Expand All @@ -40,9 +40,9 @@ <h1>
</table>
</div>

<div id="silence-project-{{ project.name|slugify }}" class="panel panel-warning" v-cloak v-show="silenceLabelsProject.has('{{project.name}}')">
<div id="silence-project-{{ project.name|slugify }}" class="panel panel-warning" v-cloak v-if="silenceLabelsProject.has('{{project.name}}')">
<div class="panel-heading">
<a @click.prevent="toggleTarget('silences-project-{{project.name|slugify}}')" class="btn btn-warning btn-sm" role="button">Silences</a>
<a @click="toggleCollapse('silences-project-{{project.name|slugify}}')" class="btn btn-warning btn-sm" role="button">Silences</a>
</div>
<table id="silences-project-{{project.name|slugify}}" class="table table-bordered table-condensed">
<tr v-for="(silence, index) in filterActiveSilences" v-if="silence.labels.project == '{{project.name}}'">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using v-for with v-if is not recommended. Additionally, this iterates over all active alerts/silences, which takes time, but currently doesn't look like a problem. I'll improve this in the next PR.

Expand Down
6 changes: 3 additions & 3 deletions promgen/templates/promgen/rule_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ <h1>Rule: {{ rule.name }}</h1>

{% breadcrumb rule %}

<div class="panel panel-danger" v-cloak v-show="alertLabelsRule.has('{{rule.name}}')" data-service="{{rule.name}}">
<div class="panel panel-danger" v-cloak v-if="alertLabelsRule.has('{{rule.name}}')" data-service="{{rule.name}}">
<div class="panel-heading">
<a @click.prevent="toggleTarget('alerts-service-{{rule.name|slugify}}')" class="btn btn-danger btn-sm" role="button">Alerts</a>
<a @click="toggleComponent('alerts-service-{{rule.name|slugify}}')" class="btn btn-danger btn-sm" role="button">Alerts</a>
</div>
<table id="alerts-service-{{rule.name|slugify}}" class="table table-bordered table-condensed collapse">
<table v-if="components['alerts-service-{{rule.name|slugify}}']" class="table table-bordered table-condensed">
<tr v-for="(alert, index) in globalAlerts" v-if="alert.labels.alertname == '{{rule.name}}'">
{% include 'promgen/alert_row.html' %}
</tr>
Expand Down
6 changes: 3 additions & 3 deletions promgen/templates/promgen/rule_update.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ <h1>Rule: {{ rule.name }}</h1>

{% breadcrumb rule 'Edit Rule' %}

<div data-service="{{rule.name}}" class="panel panel-danger" v-cloak v-show="alertLabelsRule.has('{{rule.name}}')">
<div data-service="{{rule.name}}" class="panel panel-danger" v-cloak v-if="alertLabelsRule.has('{{rule.name}}')">
<div class="panel-heading">
<a @click.prevent="toggleTarget('alerts-service-{{rule.name|slugify}}')" class="btn btn-danger btn-sm" role="button">Alerts</a>
<a @click="toggleComponent('alerts-service-{{rule.name|slugify}}')" class="btn btn-danger btn-sm" role="button">Alerts</a>
</div>
<table id="alerts-service-{{rule.name|slugify}}" class="table table-bordered table-condensed collapse">
<table v-if="components['alerts-service-{{rule.name|slugify}}']" class="table table-bordered table-condensed">
<tr v-for="(alert, index) in globalAlerts" v-if="alert.labels.alertname == '{{rule.name}}'">
{% include 'promgen/alert_row.html' %}
</tr>
Expand Down
12 changes: 6 additions & 6 deletions promgen/templates/promgen/service_block.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{% load i18n %}
{% load promgen %}
<div class="well">
<div data-service="{{service.name}}" class="panel panel-danger" v-cloak v-show="alertLabelsService.has('{{service.name}}')">
<div data-service="{{service.name}}" class="panel panel-danger" v-cloak v-if="alertLabelsService.has('{{service.name}}')">
<div class="panel-heading">
<a @click.prevent="toggleTarget('alerts-service-{{service.name|slugify}}')" class="btn btn-danger btn-sm" role="button">Alerts</a>
<a @click="toggleComponent('alerts-service-{{service.name|slugify}}')" class="btn btn-danger btn-sm" role="button">Alerts</a>
</div>
<table id="alerts-service-{{service.name|slugify}}" class="table table-bordered table-condensed collapse">
<table v-if="components['alerts-service-{{service.name|slugify}}']" class="table table-bordered table-condensed">
<tr v-for="(alert, index) in globalAlerts" v-if="alert.labels.service == '{{service.name}}'">
{% include 'promgen/alert_row.html' %}
</tr>
</table>
</div>

<div id="silence-service-{{ service.name|slugify }}" class="panel panel-warning" v-cloak v-show="silenceLabelsService.has('{{service.name}}')">
<div id="silence-service-{{ service.name|slugify }}" class="panel panel-warning" v-cloak v-if="silenceLabelsService.has('{{service.name}}')">
<div class="panel-heading">
<a @click.prevent="toggleTarget('silences-service-{{service.name|slugify}}')" class="btn btn-warning btn-sm" role="button">Silences</a>
<a @click="toggleComponent('silences-service-{{service.name|slugify}}')" class="btn btn-warning btn-sm" role="button">Silences</a>
</div>
<table id="silences-service-{{service.name|slugify}}" class="table table-bordered table-condensed collapse">
<table v-if="components['silences-service-{{service.name|slugify}}']" class="table table-bordered table-condensed">
<tr v-for="(silence, index) in filterActiveSilences" v-if="silence.labels.service == '{{service.name}}'">
{% include 'promgen/silence_row.html' %}
</tr>
Expand Down
6 changes: 3 additions & 3 deletions promgen/templates/promgen/silence_form.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{% load i18n %}
<form @submit.prevent="silenceSubmit" method="post" action="{% url 'proxy-silence' %}">
<form v-cloak v-if="components['silence-form']" @submit.prevent="silenceSubmit" method="post" action="{% url 'proxy-silence' %}">
<input name="next" type="hidden" value="{{ request.get_full_path }}" />
{% csrf_token %}

<div class="panel panel-warning collapse" id="silence-form">
<div class="panel panel-warning">
<div class="panel-heading">
Silence
<a @click.prevent="toggleTarget('silence-form')" type="button" class="close">&times;</a>
<a @click="toggleComponent('silence-form')" type="button" class="close">&times;</a>
</div>

<div class="labels panel-body">
Expand Down