Commit 152468d4 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Added the custom application metric lists and form adjustments

parent ab3978af
...@@ -12,6 +12,12 @@ ...@@ -12,6 +12,12 @@
margin: 0; margin: 0;
} }
.flash-warning {
@extend .alert;
@extend .alert-warning;
margin: 0;
}
.flash-alert { .flash-alert {
@extend .alert; @extend .alert;
@extend .alert-danger; @extend .alert-danger;
......
...@@ -242,8 +242,6 @@ ...@@ -242,8 +242,6 @@
} }
.custom-monitored-metrics { .custom-monitored-metrics {
margin-bottom: 0;
.panel-title { .panel-title {
display: flex; display: flex;
align-items: center; align-items: center;
......
.row.prepend-top-default.append-bottom-default .row.prepend-top-default.append-bottom-default
= form_for [@project.namespace.becomes(Namespace), @project, @metric], html: { class: 'col-lg-9' } do |f| = form_for [@project.namespace.becomes(Namespace), @project, @metric], html: { class: 'col-lg-8 col-lg-offset-2' } do |f|
= form_errors(@metric) = form_errors(@metric)
.form-group .form-group
= f.label :title, 'Title', class: 'label-light' = f.label :title, 'Title', class: 'label-light'
= f.text_field :title, required: true, class: 'form-control' = f.text_field :title, required: true, class: 'form-control', placeholder: 'e.g. Throughput'
%span.help-block
Used as a title for the chart
.form-group .form-group
= f.label :query, 'Query', class: 'label-light' = f.label :query, 'Query', class: 'label-light'
= f.text_field :query, required: true, class: 'form-control' = f.text_field :query, required: true, class: 'form-control', placeholder: 'e.g. sum(metric...'
%span.help-block
Must be a valid PromQL query.
= link_to "https://prometheus.io/docs/prometheus/latest/querying/basics/" do
= sprite_icon("external-link", size: 12)
Prometheus Query Documentation
.form-group .form-group
= f.label :y_label, 'Y-axis label', class: 'label-light' = f.label :y_label, 'Y-axis label', class: 'label-light'
= f.text_field :y_label, class: 'form-control' = f.text_field :y_label, class: 'form-control', placeholder: 'e.g. Requests/second'
%span.help-block
Label of the chart's vertical axis. Usually the type of the unit being charted. The horizontal axis (X-axis) always represents time
.form-group .form-group
= f.label :unit, 'Unit label', class: 'label-light' = f.label :unit, 'Unit label', class: 'label-light'
= f.text_field :unit, class: 'form-control' = f.text_field :unit, class: 'form-control', placeholder: 'e.g. req/sec'
.form-group .form-group
= f.label :legend, 'Legend label', class: 'label-light' = f.label :legend, 'Legend label', class: 'label-light'
= f.text_field :legend, class: 'form-control' = f.text_field :legend, class: 'form-control', placeholder: 'e.g. HTTP requests'
%span.help-block
Used if the query returns a single series. If it returns multiple series, their legends labels will be picked up from the response
.form-actions .form-actions
= f.submit 'Save', class: 'btn btn-save' = f.submit 'Save', class: 'btn btn-save'
......
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
%span.badge.js-custom-monitored-count 0 %span.badge.js-custom-monitored-count 0
= link_to s_('PrometheusService|New metric'), new_project_prometheus_metric_path(@project), class: 'btn btn-success js-new-metric-button hidden' = link_to s_('PrometheusService|New metric'), new_project_prometheus_metric_path(@project), class: 'btn btn-success js-new-metric-button hidden'
.panel-body .panel-body
.flash-container.hidden
.flash-warning
.flash-text
.loading-metrics.js-loading-custom-metrics .loading-metrics.js-loading-custom-metrics
%p %p
= icon('spinner spin', class: 'metrics-load-spinner') = icon('spinner spin', class: 'metrics-load-spinner')
......
...@@ -26,7 +26,6 @@ function backOffRequest(makeRequestCallback) { ...@@ -26,7 +26,6 @@ function backOffRequest(makeRequestCallback) {
export default class PrometheusMetrics { export default class PrometheusMetrics {
constructor(wrapperSelector) { constructor(wrapperSelector) {
// Call the common metrics (CE stuff basically)
const cePrometheusMetrics = new CEPrometheusMetrics(wrapperSelector); const cePrometheusMetrics = new CEPrometheusMetrics(wrapperSelector);
cePrometheusMetrics.loadActiveMetrics(); cePrometheusMetrics.loadActiveMetrics();
...@@ -36,6 +35,8 @@ export default class PrometheusMetrics { ...@@ -36,6 +35,8 @@ export default class PrometheusMetrics {
this.$monitoredCustomMetricsLoading = this.$monitoredCustomMetricsPanel.find('.js-loading-custom-metrics'); this.$monitoredCustomMetricsLoading = this.$monitoredCustomMetricsPanel.find('.js-loading-custom-metrics');
this.$monitoredCustomMetricsEmpty = this.$monitoredCustomMetricsPanel.find('.js-empty-custom-metrics'); this.$monitoredCustomMetricsEmpty = this.$monitoredCustomMetricsPanel.find('.js-empty-custom-metrics');
this.$monitoredCustomMetricsList = this.$monitoredCustomMetricsPanel.find('.js-custom-metrics-list'); this.$monitoredCustomMetricsList = this.$monitoredCustomMetricsPanel.find('.js-custom-metrics-list');
this.$newCustomMetricButton = this.$monitoredCustomMetricsPanel.find('.js-new-metric-button');
this.$flashCustomMetricsContainer = this.$wrapperCustomMetrics.find('.flash-container');
this.activeCustomMetricsEndpoint = this.$monitoredCustomMetricsPanel.data('active-custom-metrics'); this.activeCustomMetricsEndpoint = this.$monitoredCustomMetricsPanel.data('active-custom-metrics');
} }
...@@ -46,43 +47,48 @@ export default class PrometheusMetrics { ...@@ -46,43 +47,48 @@ export default class PrometheusMetrics {
this.$monitoredCustomMetricsLoading.removeClass('hidden'); this.$monitoredCustomMetricsLoading.removeClass('hidden');
this.$monitoredCustomMetricsEmpty.addClass('hidden'); this.$monitoredCustomMetricsEmpty.addClass('hidden');
this.$monitoredCustomMetricsList.addClass('hidden'); this.$monitoredCustomMetricsList.addClass('hidden');
this.$newCustomMetricButton.addClass('hidden');
break; break;
case PANEL_STATE.LIST: case PANEL_STATE.LIST:
this.$monitoredCustomMetricsLoading.addClass('hidden'); this.$monitoredCustomMetricsLoading.addClass('hidden');
this.$monitoredCustomMetricsEmpty.addClass('hidden'); this.$monitoredCustomMetricsEmpty.addClass('hidden');
this.$newCustomMetricButton.removeClass('hidden');
this.$monitoredCustomMetricsList.removeClass('hidden'); this.$monitoredCustomMetricsList.removeClass('hidden');
break; break;
default: default:
this.$monitoredCustomMetricsLoading.addClass('hidden'); this.$monitoredCustomMetricsLoading.addClass('hidden');
this.$monitoredCustomMetricsEmpty.removeClass('hidden'); this.$monitoredCustomMetricsEmpty.removeClass('hidden');
this.$monitoredCustomMetricsList.addClass('hidden'); this.$monitoredCustomMetricsList.addClass('hidden');
this.$newCustomMetricButton.addClass('hidden');
break; break;
} }
} }
populateActiveMetrics(metrics) { populateCustomMetrics(metrics) {
let totalMonitoredMetrics = 0;
metrics.forEach((metric) => { metrics.forEach((metric) => {
this.$monitoredMetricsList.append(`<li>${metric.group}</li>`); this.$monitoredCustomMetricsList.append(`<li><a href="${metric.edit_path}">${metric.title}</a></li>`);
totalMonitoredMetrics += metric.active_metrics;
}); });
this.$monitoredMetricsCount.text(totalMonitoredMetrics); this.$monitoredCustomMetricsCount.text(metrics.length);
this.showMonitoringCustomMetricsPanelState(PANEL_STATE.LIST); this.showMonitoringCustomMetricsPanelState(PANEL_STATE.LIST);
} }
showFlashMessage(message) {
this.$flashCustomMetricsContainer.removeClass('hidden');
this.$flashCustomMetricsContainer.find('.flash-text').text(message);
}
loadActiveCustomMetrics() { loadActiveCustomMetrics() {
backOffRequest(() => axios.get(this.activeCustomMetricsEndpoint)) backOffRequest(() => axios.get(this.activeCustomMetricsEndpoint))
.then(resp => resp.data) .then(resp => resp.data)
.then((response) => { .then((response) => {
if (!response || !response.data) { if (!response || !response.metrics) {
// add a flash
this.showMonitoringCustomMetricsPanelState(PANEL_STATE.EMPTY); this.showMonitoringCustomMetricsPanelState(PANEL_STATE.EMPTY);
} else { } else {
this.populateActiveMetrics(response.data); this.populateCustomMetrics(response.metrics);
} }
}).catch((err) => { }).catch((err) => {
this.showFlashMessage(err);
this.showMonitoringCustomMetricsPanelState(PANEL_STATE.EMPTY); this.showMonitoringCustomMetricsPanelState(PANEL_STATE.EMPTY);
}); });
} }
......
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