-
Notifications
You must be signed in to change notification settings - Fork 662
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'WikiEducationFoundation:master' into improve-sentry-sdk
- Loading branch information
Showing
91 changed files
with
1,075 additions
and
114 deletions.
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -1,11 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
# Allows users to download the personal data bout them stored on the Dashboard | ||
require_dependency "#{Rails.root}/lib/personal_data/personal_data_csv_builder.rb" | ||
|
||
# Allows users to download the personal data about them stored on the Dashboard | ||
class PersonalDataController < ApplicationController | ||
before_action :require_signed_in | ||
respond_to :json | ||
respond_to :json, :csv | ||
|
||
def show | ||
@user = current_user | ||
end | ||
|
||
def personal_data_csv | ||
@user = current_user | ||
csv_data = PersonalData::PersonalDataCsvBuilder.new(@user).generate_csv | ||
|
||
send_data csv_data, | ||
type: 'text/csv', | ||
disposition: 'attachment', | ||
filename: "#{@user.username}_personal_data_#{Time.zone.today}.csv" | ||
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,10 @@ | ||
# frozen_string_literal: true | ||
|
||
class SystemStatusController < ApplicationController | ||
def index | ||
system_metrics = SystemMetrics.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
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
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,97 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'sidekiq/api' | ||
|
||
class SystemMetrics | ||
def initialize | ||
# 'very_long_update' queue is excluded as it is intentionally never processed | ||
@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: get_queue_status(queue.name, queue.latency), | ||
latency: convert_latency(queue.latency) | ||
} | ||
end | ||
|
||
LATENCY_THRESHOLDS = { | ||
'default' => 1, | ||
'short_update' => 2.hours, | ||
'medium_update' => 12.hours, | ||
'long_update' => 1.day, | ||
'daily_update' => 1.day, | ||
'constant_update' => 15.minutes | ||
}.freeze | ||
|
||
def get_queue_status(queue_name, latency) | ||
threshold = LATENCY_THRESHOLDS[queue_name] | ||
latency < threshold ? 'Normal' : 'Backlogged' | ||
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, sub_unit_name = case main_unit_name | ||
when 'day' | ||
[3600, 'hour'] | ||
when 'hour' | ||
[60, 'minute'] | ||
else | ||
[1, 'second'] | ||
end | ||
sub_unit_value = (remaining_seconds / sub_unit).to_i | ||
result += " #{sub_unit_value} #{sub_unit_name}#{'s' unless sub_unit_value == 1}" | ||
end | ||
result | ||
end | ||
end |
Oops, something went wrong.