From 94b672c094846421843552fa07403ca3afff5da7 Mon Sep 17 00:00:00 2001 From: "Ben Sheldon [he/him]" Date: Fri, 5 Jul 2024 18:22:28 -0700 Subject: [PATCH] Add initial Performance panel to dashboard (#1388) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --------- Co-authored-by: Arnaud Levy Co-authored-by: Arnaud Levy Co-authored-by: Sébastien Gaya --- .../good_job/performances_controller.rb | 23 +++++++++ app/helpers/good_job/application_helper.rb | 1 + .../good_job/performances/index.html.erb | 50 +++++++++++++++++++ app/views/good_job/shared/_navbar.erb | 5 ++ config/locales/de.yml | 11 ++++ config/locales/en.yml | 11 ++++ config/locales/es.yml | 11 ++++ config/locales/fr.yml | 11 ++++ config/locales/it.yml | 11 ++++ config/locales/ja.yml | 11 ++++ config/locales/ko.yml | 11 ++++ config/locales/nl.yml | 11 ++++ config/locales/pt-BR.yml | 11 ++++ config/locales/ru.yml | 11 ++++ config/locales/tr.yml | 11 ++++ config/locales/uk.yml | 11 ++++ config/routes.rb | 2 + demo/db/seeds.rb | 5 +- .../good_job/performances_controller_spec.rb | 22 ++++++++ spec/system/performance_spec.rb | 19 +++++++ 20 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 app/controllers/good_job/performances_controller.rb create mode 100644 app/views/good_job/performances/index.html.erb create mode 100644 spec/app/controllers/good_job/performances_controller_spec.rb create mode 100644 spec/system/performance_spec.rb diff --git a/app/controllers/good_job/performances_controller.rb b/app/controllers/good_job/performances_controller.rb new file mode 100644 index 000000000..afbcd3f5e --- /dev/null +++ b/app/controllers/good_job/performances_controller.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module GoodJob + class PerformancesController < ApplicationController + def index + if GoodJob::DiscreteExecution.monotonic_duration_migrated? + @performances = GoodJob::DiscreteExecution + .where.not(job_class: nil) + .group(:job_class) + .select(" + job_class, + COUNT(*) AS executions_count, + AVG(duration) AS avg_duration, + MIN(duration) AS min_duration, + MAX(duration) AS max_duration + ") + .order("job_class") + else + @needs_upgrade = true + end + end + end +end diff --git a/app/helpers/good_job/application_helper.rb b/app/helpers/good_job/application_helper.rb index 39558e6b7..4fa12f4b0 100644 --- a/app/helpers/good_job/application_helper.rb +++ b/app/helpers/good_job/application_helper.rb @@ -9,6 +9,7 @@ module ApplicationHelper def format_duration(sec) return unless sec + return "" if sec.is_a?(String) # pg interval support added in Rails 6.1 if sec < 1 t 'good_job.duration.milliseconds', ms: (sec * 1000).floor diff --git a/app/views/good_job/performances/index.html.erb b/app/views/good_job/performances/index.html.erb new file mode 100644 index 000000000..be0de2475 --- /dev/null +++ b/app/views/good_job/performances/index.html.erb @@ -0,0 +1,50 @@ +
+

<%= t ".title" %>

+
+ +<% if @needs_upgrade %> +
+ <%= t "shared.needs_migration" %> +
+<% else %> + +
+
+
+
+
<%= t ".job_class" %>
+
<%= t ".executions" %>
+ +
<%= t ".average_duration" %>
+
<%= t ".minimum_duration" %>
+
<%= t ".maximum_duration" %>
+
+
+ + <% @performances.each do |performance| %> +
+
+
<%= performance.job_class %>
+
+
<%= t ".executions" %>
+ <%= performance.executions_count %> +
+ +
+
<%= t ".average_duration" %>
+ <%= format_duration performance.avg_duration %> +
+
+
<%= t ".minimum_duration" %>
+ <%= format_duration performance.min_duration %> +
+
+
<%= t ".maximum_duration" %>
+ <%= format_duration performance.max_duration %> +
+
+
+ <% end %> +
+
+<% end %> diff --git a/app/views/good_job/shared/_navbar.erb b/app/views/good_job/shared/_navbar.erb index c4466af03..5229978ca 100644 --- a/app/views/good_job/shared/_navbar.erb +++ b/app/views/good_job/shared/_navbar.erb @@ -39,6 +39,11 @@ <% end %> +