Skip to content

Commit

Permalink
Added metrics feature toogle to configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
abujeda committed Nov 18, 2024
1 parent 3c30dcc commit 40270c0
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 59 deletions.
28 changes: 22 additions & 6 deletions dev/metrics/initializers/sessions_helper_extension.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
# Slurm Adapter Extensions to extract metrics with sacct
# SessionsHelper Extensions to add job metrics to session card in OODv3.x
Rails.application.config.after_initialize do
Rails.logger.info 'Executing Sessions Helper extension ...'
module BatchConnect::SessionsHelper
# UPDATE SUPPORT TICKET PARTIAL TO ADD JOB METRICS
# BETTER THAN UPDATE OTHER METHOD MORE LIKELY TO CHANGE
def support_ticket(session)
render(partial: 'batch_connect/sessions/card/support_ticket', locals: { session: session })
render(partial: 'batch_connect/sessions/card/session_job_metrics', locals: { session: session }) if session.completed?
# UPDATE session_view TO ADD JOB METRICS PARTIAL
def session_view(session)
capture do
concat(
content_tag(:div) do
concat content_tag(:div, cancel_or_delete(session), class: 'float-right')
concat host(session)
concat created(session)
concat render_session_time(session)
concat id(session)
concat support_ticket(session) unless @user_configuration.support_ticket.empty?
if SlurmMetrics::MetricsHelper.new.metrics_enabled? && session.completed?
concat render(partial: 'batch_connect/sessions/card/session_job_metrics', locals: { session: session })
end
concat display_choices(session)
safe_concat custom_info_view(session) if session.app.session_info_view
safe_concat completed_view(session) if session.app.session_completed_view && session.completed?
end
)
concat content_tag(:div) { yield }
end
end
end

Expand Down
5 changes: 5 additions & 0 deletions dev/metrics/lib/slurm_metrics/metrics_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,10 @@ def format_duration(seconds)
def metrics_waiting_elapsed(completed_time)
Time.now.to_i - completed_time > 10
end

def metrics_enabled?
metrics_configuration = ::Configuration.config.fetch(:metrics_enabled, true)
::Configuration.send(:to_bool, metrics_configuration)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<%= render_card_partial('id', session) %>
<%= render_card_partial('support_ticket', session) if Configuration.support_ticket_enabled? %>
<%= render_card_partial('display_choices', session) %>
<%= render_card_partial('session_job_metrics', session) if session.completed?%>
<%= render_card_partial('session_job_metrics', session) if SlurmMetrics::MetricsHelper.new.metrics_enabled? && session.completed?%>
<%= render_card_partial('custom_info_view', session) if session.app.session_info_view %>
<%= render_card_partial('completed_view', session) if session.app.session_completed_view && session.completed? %>
<%= render_connection(session) %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<style>

table.metrics th {
font-size: 0.9rem;
}
table.metrics td {
font-size: 0.8rem;
}

.job-metrics i.app-icon {
width: 0.8rem;
height: 0.8rem;
font-size: 0.8rem;
vertical-align: 1px;
color: #6c757d;
}

div.job-metric-details {
overflow: hidden;
}

div.job-metric-details [title]{
cursor: default;
}

div.job-metric-details table {
margin-top: 0.5rem;
}

div.job-metric-details .text-dark {
--bs-text-opacity: 0.8;
}

p.job-metrics-description {
cursor: pointer;
margin: 0;
}

p[aria-expanded=true] .closed {
display: none;
}

p[aria-expanded=false] .open {
display: none;
}

</style>
Original file line number Diff line number Diff line change
@@ -1,52 +1,5 @@
<style>

table.metrics th {
font-size: 0.9rem;
}
table.metrics td {
font-size: 0.8rem;
}

.job-metrics i.app-icon {
width: 0.8rem;
height: 0.8rem;
font-size: 0.8rem;
vertical-align: 1px;
color: #6c757d;
}

div.job-metric-details {
overflow: hidden;
}

div.job-metric-details [title]{
cursor: default;
}

div.job-metric-details table {
margin-top: 0.5rem;
}

div.job-metric-details .text-dark {
--bs-text-opacity: 0.8;
}

p.job-metrics-description {
cursor: pointer;
margin: 0;
}

p[aria-expanded=true] .closed {
display: none;
}

p[aria-expanded=false] .open {
display: none;
}

</style>
<script>
// TESTED WITH OOD 3.x and 4.0
// TESTED WITH OOD 4.0
// OVERRIDE OOD replaceHTML FUNCTION TO INTERCEPT THE AJAX RESPONSE FOR THE SESSION CARDS.
// WE WANT TO KEEP THE METRICS COLLAPSABLE STATE BETWEEN AJAX REFRESH
const originalFunction = window.replaceHTML;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<hr>

<% unless metrics_helper.metrics_waiting_elapsed(session.completed_at) %>
<p>
<p class="metrics-waiting">
<strong>Job Efficiency: </strong>
Waiting for Slurm to calculate metrics ...
</p>
Expand Down
3 changes: 2 additions & 1 deletion dev/metrics/views/batch_connect/sessions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

<%= javascript_include_tag 'batch_connect_sessions', nonce: true %>

<%= render partial: '/batch_connect/sessions/card/session_card_assets' %>
<%= render partial: '/batch_connect/sessions/card/session_card_css' if SlurmMetrics::MetricsHelper.new.metrics_enabled? %>
<%= render partial: '/batch_connect/sessions/card/session_card_js' if SlurmMetrics::MetricsHelper.new.metrics_enabled? %>

<%= render partial: 'batch_connect/shared/breadcrumb',
locals: {
Expand Down
2 changes: 1 addition & 1 deletion dev/metrics/views/batch_connect/sessions/index.v3.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<%= javascript_include_tag 'batch_connect_sessions', nonce: true %>

<%= render partial: '/batch_connect/sessions/card/session_card_assets' %>
<%= render partial: '/batch_connect/sessions/card/session_card_css' if SlurmMetrics::MetricsHelper.new.metrics_enabled? %>

<%= render partial: 'batch_connect/shared/breadcrumb',
locals: {
Expand Down
3 changes: 2 additions & 1 deletion dev/metrics/views/batch_connect/sessions/index.v3.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<% @sessions.each do |session| %>
sessions.push('<%= session.id %>');
$target = $('#id_<%= session.id %>');
if ( $target.data('hash') !== '<%= session.to_hash %>' ) {
$metricsWaiting = $target.find('p.metrics-waiting')
if ( $target.data('hash') !== '<%= session.to_hash %>' || $metricsWaiting.length ) {
$target.replaceWith('<%= j render(partial: "panel", locals: { session: session }) %>');
}
<% end %>
Expand Down

0 comments on commit 40270c0

Please sign in to comment.