-
Notifications
You must be signed in to change notification settings - Fork 232
Add EC2 autograder features #2281
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
Open
evanyeyeye
wants to merge
20
commits into
master
Choose a base branch
from
ec2-testing
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.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
356f22c
testing ec2, add support on autolab side
20wildmanj 5539c82
add support for EC2 settings in Autolab
20wildmanj a47484c
fix issue with autograder initialization
20wildmanj a7fd8a1
add new option on Tango side to explicitly check for ec2 vmms usage, …
20wildmanj 30cc992
add ec2ssh to prod config
20wildmanj fc35ace
temporary changes to help with testing autolab 3
20wildmanj c3f761b
Revert "temporary changes to help with testing autolab 3"
20wildmanj 0345846
Merge conflicts
KesterTan e663c5d
Merge branch 'master' into ec2-testing
KesterTan 1ae51ed
Minor touchups
evanyeyeye 259f0f2
Merge branch 'ec2-testing' of github.com:autolab/Autolab into ec2-tes…
evanyeyeye afd0665
ec2-dropdown
Futurecomputerfixer b240eaf
fix linting
Futurecomputerfixer 5a93401
fix linting #2
Futurecomputerfixer 6765f5f
Merge branch 'master' into ec2-testing
KesterTan dd823f3
Merge branch 'master' into ec2-testing
KesterTan 7cd6501
encrypt access keys
KesterTan d497e3e
linting
KesterTan 8afbf52
try fix error parsing for scoreboard
Futurecomputerfixer 230a2ee
raise exception if ece2 type dont exist
Futurecomputerfixer 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,42 @@ | ||
| ; | ||
| (function() { | ||
| $(document).ready(function() { | ||
| function access_key_callback() { | ||
| const checked = $(this).prop('checked'); | ||
| const $access_key_field = $('#autograder_access_key'); | ||
| const $access_key_id_field = $('#autograder_access_key_id'); | ||
| $access_key_field.prop('disabled', !checked); | ||
| $access_key_id_field.prop('disabled', !checked); | ||
| if (!checked) { | ||
| $access_key_field.val('', checked); | ||
| $access_key_id_field.val('', checked); | ||
| } | ||
| } | ||
|
|
||
| $('#autograder_use_access_key').on('change', access_key_callback); | ||
| access_key_callback.call($('#autograder_use_access_key')); | ||
|
|
||
| function initializeEC2Dropdown() { | ||
| if ($.fn.tooltip) { | ||
| $('.browser-default[data-tooltip]').tooltip({ | ||
| enterDelay: 300, | ||
| exitDelay: 200, | ||
| position: 'top' | ||
| }); | ||
| } | ||
|
|
||
| $('#autograder_instance_type option').hover( | ||
| function() { $(this).addClass('highlighted-option'); }, | ||
| function() { $(this).removeClass('highlighted-option'); } | ||
| ); | ||
|
|
||
| $('#autograder_instance_type').on('change.ec2-instance', function() { | ||
| const selectedInstance = $(this).val(); | ||
| console.log('Selected EC2 instance type:', selectedInstance); | ||
| }); | ||
| } | ||
|
|
||
| // Initialize the EC2 dropdown functionality | ||
| initializeEC2Dropdown(); | ||
| }); | ||
| })(); |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -270,13 +270,13 @@ def createScoreboardEntry(scores, autoresult) | |
| !@scoreboard || | ||
| [email protected] || | ||
| @scoreboard.colspec.blank? | ||
|
|
||
| # First we need to get the total score | ||
| total = 0.0 | ||
| @assessment.problems.each do |problem| | ||
| total += scores[problem.name].to_f | ||
| end | ||
|
|
||
| # Now build the array of scores | ||
| entry = [] | ||
| entry << total.round(1).to_s | ||
|
|
@@ -285,32 +285,57 @@ def createScoreboardEntry(scores, autoresult) | |
| end | ||
| return entry | ||
| end | ||
|
|
||
| # At this point we have an autograded assessment with a | ||
| # customized scoreboard. Extract the scoreboard entry | ||
| # from the scoreboard array object in the JSON autoresult. | ||
|
|
||
| parsed = ActiveSupport::JSON.decode(autoresult) | ||
|
|
||
| # ensure that the parsed result is a hash with scoreboard field, where scoreboard is an array | ||
| if !parsed || !parsed.is_a?(Hash) || !parsed["scoreboard"] || | ||
| !parsed["scoreboard"].is_a?(Array) | ||
| # If there is no autoresult for this student (typically | ||
| # because their code did not compile or it segfaulted and | ||
| # the instructor's autograder did not catch it) then | ||
| # raise an error, will be handled by caller | ||
| if @cud.instructor? | ||
| (flash.now[:error] = "Error parsing scoreboard for autograded assessment: " \ | ||
| "scoreboard result is not an array. Please ensure that the autograder returns " \ | ||
| "scoreboard results as an array.") | ||
| end | ||
| Rails.logger.error("Scoreboard error in #{@course.name}/#{@assessment.name}: " \ | ||
|
|
||
| begin | ||
| parsed = ActiveSupport::JSON.decode(autoresult) | ||
|
|
||
| # ensure that the parsed result is a hash with scoreboard field, where scoreboard is an array | ||
| if !parsed || !parsed.is_a?(Hash) || !parsed["scoreboard"] || | ||
| !parsed["scoreboard"].is_a?(Array) | ||
| # If there is no autoresult for this student (typically | ||
| # because their code did not compile or it segfaulted and | ||
| # the instructor's autograder did not catch it) then | ||
| # raise an error, will be handled by caller | ||
| if @cud.instructor? | ||
| (flash.now[:error] = "Error parsing scoreboard for autograded assessment: " \ | ||
| "scoreboard result is not an array. Please ensure that the autograder returns " \ | ||
| "scoreboard results as an array.") | ||
| end | ||
| Rails.logger.error("Scoreboard error in #{@course.name}/#{@assessment.name}: " \ | ||
| "Scoreboard result is not an array") | ||
| raise StandardError | ||
| raise StandardError | ||
| end | ||
|
|
||
| # ADDED: Ensure the scoreboard entries align with colspec expectations | ||
| if @scoreboard && [email protected]? | ||
| begin | ||
| colspec_parsed = ActiveSupport::JSON.decode(@scoreboard.colspec) | ||
| if colspec_parsed && colspec_parsed["scoreboard"] && colspec_parsed["scoreboard"].is_a?(Array) | ||
| expected_length = colspec_parsed["scoreboard"].length | ||
| # Ensure the entry has enough elements, pad with nil if needed | ||
| if parsed["scoreboard"].length < expected_length | ||
| Rails.logger.warn("Scoreboard entry too short (#{parsed["scoreboard"].length}) for user, expected #{expected_length}") | ||
| # Pad the array to match expected length | ||
| parsed["scoreboard"] = parsed["scoreboard"].fill(nil, parsed["scoreboard"].length, expected_length - parsed["scoreboard"].length) | ||
| end | ||
| end | ||
| rescue => e | ||
| Rails.logger.error("Error validating scoreboard entry against colspec: #{e.message}") | ||
| end | ||
| end | ||
|
|
||
| return parsed["scoreboard"] | ||
| rescue => e | ||
| # Log the error and re-raise to be handled by the caller | ||
| Rails.logger.error("Error parsing scoreboard JSON: #{e.message}") | ||
| raise | ||
| end | ||
|
|
||
| parsed["scoreboard"] | ||
| end | ||
|
|
||
|
|
||
| # | ||
| # scoreboardOrderSubmissions - This function provides a "<=>" | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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,36 @@ | ||
| <%= f.text_field :autograde_image, display_name: "VM Image", | ||
| help_text: "VM image for autograding (e.g. <kbd>rhel.img</kbd>). #{link_to 'Click here', tango_status_course_jobs_path} to view the list of VM images and pools currently being used".html_safe + | ||
| (Rails.configuration.x.docker_image_upload_enabled.presence ? ", or #{link_to 'click here', course_dockers_path} to upload a new docker image.".html_safe : "."), | ||
| required: true, maxlength: 64 %> | ||
|
|
||
| <%= f.number_field :autograde_timeout, display_name: "Timeout", | ||
| help_text: "Timeout for autograding jobs (secs). Must be between 10s and 900s, inclusive.", min: 10, max: 900 %> | ||
| <%= f.check_box :release_score, | ||
| display_name: "Release Scores?", | ||
| help_text: "Check to release autograded scores to students immediately after autograding (strongly recommended)." %> | ||
|
|
||
| <% help_tar_text = "Tar file exists, upload a file to override." %> | ||
| <% help_makefile_text = "Makefile exists, upload a file to override." %> | ||
| <%= f.file_field :makefile, label_text: "Autograder Makefile", action: :upload, file_exists_text: help_makefile_text, class: "form-file-field", file_exists: @makefile_exists %> | ||
| <%= f.file_field :tar, label_text: "Autograder Tar", action: :upload, file_exists_text: help_tar_text, class: "form-file-field", file_exists: @tar_exists %> | ||
| <p class="help-block"> | ||
| Both of the above files will be renamed upon upload. | ||
| </p> | ||
|
|
||
| <%= f.fields_for :assessment, @assessment do |af| %> | ||
| <%= af.check_box :disable_network, help_text: "Disable network access for autograding containers." %> | ||
| <% end %> | ||
|
|
||
| <%= f.submit "Save Settings" %> | ||
|
|
||
| <%= link_to "Delete Autograder", course_assessment_autograder_path(@course, @assessment), | ||
| method: :delete, class: "btn danger", | ||
| data: { confirm: "Are you sure you want to delete the Autograder for this assesssment?" } %> | ||
|
|
||
| <% unless @makefile_exists.nil? %> | ||
| <%= link_to "Download Makefile", download_file_course_assessment_autograder_path(file_path: @makefile_exists, file_key: 'makefile'), class: "btn" %> | ||
| <% end %> | ||
|
|
||
| <% unless @tar_exists.nil? %> | ||
| <%= link_to "Download Tar", download_file_course_assessment_autograder_path(file_path: @tar_exists, file_key: 'tar'), class: "btn" %> | ||
| <% end %> |
This file contains hidden or 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,100 @@ | ||
| <% content_for :javascripts do %> | ||
| <%= javascript_include_tag "autograder" %> | ||
| <% end %> | ||
|
|
||
| <h4>EC2 Settings</h4> | ||
| <%= f.check_box :use_access_key, | ||
| display_name: "Enable Access Key", | ||
| help_text: "(Optional) Use your own provided access key to authenticate to different EC2 instances than the default one on Tango" %> | ||
| <%= f.password_field :access_key, | ||
| display_name: "Access Key", | ||
| value: nil, | ||
| autocomplete: "new-password", | ||
| placeholder: "Leave blank to keep existing secret" %> | ||
| <%= f.text_field :access_key_id, | ||
| display_name: "Access Key ID", | ||
| value: nil, | ||
| autocomplete: "off", | ||
| placeholder: "Leave blank to keep existing secret" %> | ||
|
|
||
| <% | ||
| # Group EC2 instance options by category for better organization | ||
| ec2_instance_options = [ | ||
| # General Purpose - T2 (burstable) | ||
| ['T2 - General Purpose (Burstable)', [ | ||
| ['t2.nano - 1 vCPU, 0.5 GiB RAM (minimal, lowest cost)', 't2.nano'], | ||
| ['t2.micro - 1 vCPU, 1 GiB RAM (lowest cost, suitable for small jobs)', 't2.micro'], | ||
| ['t2.small - 1 vCPU, 2 GiB RAM (low cost, better for memory-intensive tasks)', 't2.small'], | ||
| ['t2.medium - 2 vCPU, 4 GiB RAM (balanced, good for most autograding tasks)', 't2.medium'], | ||
| ['t2.large - 2 vCPU, 8 GiB RAM (better for memory-heavy workloads)', 't2.large'], | ||
| ['t2.xlarge - 4 vCPU, 16 GiB RAM (good for parallel processing)', 't2.xlarge'], | ||
| ['t2.2xlarge - 8 vCPU, 32 GiB RAM (high performance, burstable)', 't2.2xlarge'] | ||
| ]], | ||
| # General Purpose - T3 (newer generation) | ||
| ['T3 - General Purpose (Newer Generation)', [ | ||
| ['t3.micro - 2 vCPU, 1 GiB RAM (better performance than t2.micro)', 't3.micro'], | ||
| ['t3.small - 2 vCPU, 2 GiB RAM (improved over t2.small)', 't3.small'], | ||
| ['t3.medium - 2 vCPU, 4 GiB RAM (better CPU performance than t2)', 't3.medium'], | ||
| ['t3.large - 2 vCPU, 8 GiB RAM (improved networking)', 't3.large'] | ||
| ]], | ||
| # Compute Optimized | ||
| ['C - Compute Optimized', [ | ||
| ['c5.large - 2 vCPU, 4 GiB RAM (compute-optimized, faster CPU)', 'c5.large'], | ||
| ['c5.xlarge - 4 vCPU, 8 GiB RAM (high compute performance)', 'c5.xlarge'], | ||
| ['c5.2xlarge - 8 vCPU, 16 GiB RAM (very high compute performance)', 'c5.2xlarge'] | ||
| ]], | ||
| # Memory Optimized | ||
| ['R - Memory Optimized', [ | ||
| ['r5.large - 2 vCPU, 16 GiB RAM (memory-optimized, for large datasets)', 'r5.large'], | ||
| ['r5.xlarge - 4 vCPU, 32 GiB RAM (high memory capacity)', 'r5.xlarge'], | ||
| ['r5.2xlarge - 8 vCPU, 64 GiB RAM (very high memory capacity)', 'r5.2xlarge'] | ||
| ]] | ||
| ] | ||
| %> | ||
|
|
||
| <% | ||
| selected_instance_type = @autograder.instance_type | ||
| valid_instance_types = ec2_instance_options.flat_map { |_group, instances| instances.map(&:last) } | ||
| if selected_instance_type.present? && !valid_instance_types.include?(selected_instance_type) | ||
| raise ArgumentError, "Invalid EC2 instance type: #{selected_instance_type}" | ||
| end | ||
| %> | ||
|
|
||
| <div style="margin-bottom: 5px;"><strong>EC2 Instance Type</strong></div> | ||
|
|
||
| <%= f.select :instance_type, | ||
| grouped_options_for_select(ec2_instance_options, @autograder.instance_type), | ||
| { include_blank: false, label: "EC2 Instance Type" }, | ||
| { class: 'browser-default', | ||
| data: { tooltip: "Select an EC2 instance type based on your autograding needs. Larger instances cost more but run faster." }, | ||
| display_name: "EC2 Instance Type" } %> | ||
| <div class="help-text"> | ||
| Choose an instance type based on your autograding requirements: | ||
| <ul class="browser-default" style="margin-top: 5px; margin-left: 15px;"> | ||
| <li><strong>T2 instances</strong>: Burstable performance instances, good for varying workloads | ||
| <ul> | ||
| <li><strong>t2.micro</strong>: Default, lowest cost, suitable for simple autograding</li> | ||
| <li><strong>t2.medium/large</strong>: Better for more complex tests with moderate requirements</li> | ||
| </ul> | ||
| </li> | ||
| <li><strong>T3 instances</strong>: Newer generation with better baseline performance than T2</li> | ||
| <li><strong>C5 (Compute-optimized)</strong>: Best for CPU-bound tasks like compilation, testing algorithms</li> | ||
| <li><strong>R5 (Memory-optimized)</strong>: Best for memory-intensive operations with large datasets</li> | ||
| </ul> | ||
| <div class="recommendation-box" style="background-color: #f5f5f5; padding: 10px; border-left: 4px solid #2196F3; margin-top: 10px;"> | ||
| <strong>Recommendations:</strong> | ||
| <ul class="browser-default" style="margin-top: 5px; margin-left: 15px;"> | ||
| <li>Start with <strong>t2.micro</strong> for basic assignments with minimal resource requirements</li> | ||
| <li>Use <strong>t2.medium</strong> or <strong>t3.medium</strong> for most standard programming assignments</li> | ||
| <li>Choose <strong>c5.xlarge</strong> for computationally intensive tasks (e.g., compiler projects)</li> | ||
| <li>Select <strong>r5.large</strong> for memory-intensive workloads (e.g., large datasets, ML)</li> | ||
| </ul> | ||
| </div> | ||
| <small>Note: Larger instances incur higher AWS costs. <a href='https://aws.amazon.com/ec2/pricing/on-demand/' target='_blank'>View EC2 pricing</a></small> | ||
| </div> | ||
|
|
||
| <%= f.submit "Save Settings" %> | ||
|
|
||
| <%= link_to "Delete Autograder", course_assessment_autograder_path(@course, @assessment), | ||
| method: :delete, class: "btn danger", | ||
| data: { confirm: "Are you sure you want to delete the Autograder for this assesssment?" } %> |
Oops, something went wrong.
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.
Flash message won't be displayed.
The
flash.now[:error]assignment at lines 304-306 won't be visible to users becauseStandardErroris raised immediately after at line 310. This exception is caught by the caller (lines 83-96), which setsgrade[:entry] = []without rendering the flash message. Consider removing the flash assignment since the error is already logged at line 308.Apply this diff to remove the unused flash assignment:
🤖 Prompt for AI Agents