Skip to content

Commit

Permalink
Remove NOW() from Dashboard SQL; fix chart x-axis order left-to-rig…
Browse files Browse the repository at this point in the history
…ht, old-to-new (#355)

- Replaces `NOW()` with times coming from Ruby in query
- Fixes chart x-axis to be left-to-right, old-to-new timestamps
- Replaces x-axis labels with simply times with timestamps rather than full datetimes
- Slightly improves label visual overflow
- Increases quantity of seed data generated for fuller chart
  • Loading branch information
bensheldon authored Aug 31, 2021
1 parent 4b3e13e commit 936ef93
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
4 changes: 4 additions & 0 deletions engine/app/assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@
.tooltip.tooltip-hidden {
opacity: 0;
}

.ct-label.ct-horizontal {
white-space: nowrap;
}
1 change: 0 additions & 1 deletion engine/app/assets/vendor/bootstrap/bootstrap.bundle.min.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion engine/app/assets/vendor/bootstrap/bootstrap.min.css

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions engine/app/controllers/good_job/dashboards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ def to_params(override)
def index
@filter = JobFilter.new(params)

job_data = GoodJob::Job.connection.exec_query Arel.sql(<<~SQL.squish)
count_query = Arel.sql(GoodJob::Job.pg_or_jdbc_query(<<~SQL.squish))
SELECT *
FROM generate_series(
date_trunc('hour', NOW() - '1 day'::interval),
date_trunc('hour', NOW()),
date_trunc('hour', $1::timestamp),
date_trunc('hour', $2::timestamp),
'1 hour'
) timestamp
LEFT JOIN (
Expand All @@ -76,13 +76,17 @@ def index
) sources
GROUP BY date_trunc('hour', scheduled_at), queue_name
) sources ON sources.scheduled_at = timestamp
ORDER BY timestamp DESC
ORDER BY timestamp ASC
SQL

current_time = Time.current
binds = [[nil, current_time - 1.day], [nil, current_time]]
job_data = GoodJob::Job.connection.exec_query(count_query, "GoodJob Dashboard Chart", binds)

queue_names = job_data.map { |d| d['queue_name'] }.uniq
labels = []
queues_data = job_data.to_a.group_by { |d| d['timestamp'] }.each_with_object({}) do |(timestamp, values), hash|
labels << timestamp.in_time_zone.to_s
labels << timestamp.in_time_zone.strftime('%H:%M %z')
queue_names.each do |queue_name|
(hash[queue_name] ||= []) << values.find { |d| d['queue_name'] == queue_name }&.[]('count')
end
Expand Down
2 changes: 1 addition & 1 deletion spec/test_app/db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
start_date = 7.days.ago
time_increments = (1.minute..90.minutes).to_a
time_increments = (1.minute..10.minutes).to_a
job_classes = ['ExampleJob', 'OtherJob']
queue_names = ["default", "mice", "elephants"]

Expand Down

0 comments on commit 936ef93

Please sign in to comment.