-
Notifications
You must be signed in to change notification settings - Fork 649
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
[WIP] System Status and Performance Info UI #6062
Open
empty-codes
wants to merge
5
commits into
WikiEducationFoundation:master
Choose a base branch
from
empty-codes:system-status-ui
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+329
−0
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d19a4a0
Creates SystemStatusController and SystemMetricsService for status in…
empty-codes 2978545
Creates first version of UI consisting of queue details and sidekiq s…
empty-codes 133a099
Updates all text to use i18n
empty-codes 520be65
Adds test spec files for system status controller and service class +…
empty-codes 2d5df2c
Updates queue status to display 'Normal' or 'Backlogged' based on lat…
empty-codes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
class SystemStatusController < ApplicationController | ||
def index | ||
system_metrics = GetSystemMetrics.new | ||
|
||
@sidekiq_stats = system_metrics.fetch_sidekiq_stats | ||
@queue_metrics = system_metrics.fetch_queue_management_metrics | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'sidekiq/api' | ||
|
||
class GetSystemMetrics | ||
def initialize | ||
@queues = YAML.load_file('config/sidekiq.yml')[:queues] | ||
.reject { |queue_name| queue_name == 'very_long_update' } | ||
fetch_sidekiq_stats | ||
end | ||
|
||
def fetch_sidekiq_stats | ||
stats = Sidekiq::Stats.new | ||
{ | ||
enqueued_jobs: stats.enqueued, | ||
active_jobs: stats.processes_size | ||
} | ||
end | ||
|
||
def fetch_queue_management_metrics | ||
queues = [] | ||
paused_queues = [] | ||
all_operational = true | ||
|
||
@queues.each do |queue_name| | ||
queue = Sidekiq::Queue.new(queue_name) | ||
queues << get_queue_data(queue) | ||
|
||
if queue.paused? | ||
all_operational = false | ||
paused_queues << queue_name | ||
end | ||
end | ||
|
||
{ | ||
queues:, | ||
paused_queues:, | ||
all_operational: | ||
} | ||
end | ||
|
||
def get_queue_data(queue) | ||
{ | ||
name: queue.name, | ||
size: queue.size, | ||
status: queue.size.zero? ? 'No pending jobs' : 'Pending jobs', | ||
latency: convert_latency(queue.latency) | ||
} | ||
end | ||
|
||
def convert_latency(seconds) | ||
case seconds | ||
when 0...60 | ||
"#{seconds.to_i} second#{'s' unless seconds == 1}" | ||
when 60...3600 | ||
format_time(seconds, 60, 'minute', 'second') | ||
when 3600...86400 | ||
format_time(seconds, 3600, 'hour', 'minute') | ||
else | ||
format_time(seconds, 86400, 'day', 'hour') | ||
end | ||
end | ||
|
||
def format_time(seconds, unit, main_unit_name, sub_unit_name) | ||
main_unit = (seconds / unit).to_i | ||
remaining_seconds = (seconds % unit).to_i | ||
result = "#{main_unit} #{main_unit_name}#{'s' unless main_unit == 1}" | ||
if remaining_seconds.positive? | ||
sub_unit_value = (remaining_seconds / (unit / 60)).to_i | ||
result += " #{sub_unit_value} #{sub_unit_name}#{'s' unless sub_unit_value == 1}" | ||
end | ||
result | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
.container.queues | ||
.module | ||
.section-header | ||
%h3 Queues Overview | ||
.notification | ||
.container | ||
- if @queue_metrics[:all_operational] | ||
%p All Queues Operational | ||
- else | ||
%p All Queues Operational except: | ||
.notifications | ||
.notice | ||
.container | ||
- @queue_metrics[:paused_queues].each do |queue_name| | ||
%p= queue_name.humanize | ||
%br/ | ||
|
||
%table.table.table--hoverable | ||
%thead | ||
%tr | ||
%th Queue | ||
%th Purpose | ||
%th Status | ||
%th | ||
.tooltip-trigger | ||
= t("status.size") | ||
%span.tooltip-indicator | ||
.tooltip.dark | ||
%p= t("status.size_doc") | ||
%th | ||
.tooltip-trigger | ||
= t("status.latency") | ||
%span.tooltip-indicator | ||
.tooltip.dark | ||
%p= t("status.latency_doc") | ||
%tbody | ||
- @queue_metrics[:queues].each do |queue| | ||
%tr{ class: queue[:size].zero? ? "table-row--success" : "table-row--warning" } | ||
%td | ||
.tooltip-trigger | ||
= t("status.#{queue[:name]}") | ||
%span.tooltip-indicator | ||
.tooltip.dark | ||
%p= t("status.#{queue[:name]}_description") | ||
%td= t("status.#{queue[:name]}_doc") | ||
%td= queue[:status] | ||
%td= queue[:size] | ||
%td= queue[:latency] | ||
|
||
.container.sidekiq_stats | ||
%br/ | ||
%h3 Sidekiq Stats | ||
.stat-display | ||
- @sidekiq_stats.each do |key, value| | ||
.stat-display__stat.tooltip-trigger | ||
.stat-display__value= value | ||
%small= key.to_s.humanize | ||
|
||
.tooltip.dark | ||
- case key | ||
- when :enqueued_jobs | ||
%p= t("status.enqueued_jobs_doc") | ||
- when :active_jobs | ||
%p= t("status.active_jobs_doc") | ||
- else | ||
%p No additional info available |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use i18n for all the text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, Any other changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not at the moment! Is this a complete MVP? If so, mark it ready for review and I can probably review it tomorrow. Also @Formasitchijoh please do a code review if you have a chance.