Allow AMI and Security Group selection (in combination with PR on Tango)
Description
Allow user to choose an AMI and Security Group EC2 Settings. Options are pooled from Tango.
Motivation and Context
#2272
How Has This Been Tested?
Ensured AMI and Security Group lists were properly pooled from Tango. Change autograder settings and grade various submissions, ensure the AMI and Security Group changes carry through.
Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
📝 Walkthrough
Walkthrough
The pull request introduces enhanced autograder configuration with EC2-specific options. A new JavaScript file adds a callback for toggling access key fields based on a checkbox. Controller actions are updated to initialize and permit new attributes, and additional Tango information is extracted in jobs actions. The helper method updating job properties now incorporates EC2 configurations. New view partials are created for basic and EC2 settings and integrated into a tabbed interface. Feature flags for EC2 SSH are added to environment configurations, and migrations along with schema updates introduce new columns, adjust data types, and add foreign keys.
Changes
| File(s) | Change Summary |
|---|---|
app/assets/javascripts/autograder.js |
New JavaScript file that initializes a callback on document ready to toggle the autograder access key fields based on the checkbox state. |
app/controllers/autograders_controller.rb and app/controllers/jobs_controller.rb |
Controllers updated: autograders now initialize and permit new attributes (access_key, access_key_id, instance_type, ami, security_group), and jobs extract additional Tango info (tagged_amis, security_groups). |
app/helpers/assessment_autograde_core.rb |
Modified tango_add_job method to append EC2-related properties (accessKey, accessKeyId, instanceType, ami, security_group) to the job properties before JSON conversion. |
app/views/autograders/_basic_settings.html.erb, app/views/autograders/_ec2_settings.html.erb, app/views/autograders/_form.html.erb |
New view partials for basic and EC2 settings added; existing autograder form restructured into a tabbed interface that conditionally renders these partials. |
config/environments/development.rb, config/environments/production.rb.template |
Introduced new feature flag config.x.ec2_ssh (set to true in development and false in production) to control EC2 SSH functionality. |
db/migrate/20241205233214_add_ec2_ssh_fields_to_autograders.rb, db/migrate/20241211042124_add_use_access_key_to_autograder.rb |
New migrations adding columns to the autograders table: instance_type, access_key, access_key_id (default empty strings) and use_access_key (boolean, default false). |
db/schema.rb |
Schema version updated with new autograder columns, column type modifications (e.g., bigint to integer), removal of certain default values, added precision adjustments, and new foreign key constraints. |
Sequence Diagram(s)
sequenceDiagram
participant U as User
participant CB as Checkbox (#autograder_use_access_key)
participant JS as Autograder Callback
participant AK as Input Field (#autograder_access_key)
participant AID as Input Field (#autograder_access_key_id)
Note over JS: Callback attached on document ready
U->>CB: Toggle checkbox
CB->>+JS: Trigger change event
alt Checkbox is checked
JS->>AK: Enable field
JS->>AID: Enable field
else Checkbox is unchecked
JS->>AK: Disable field and clear value
JS->>AID: Disable field and clear value
end
[!TIP]
⚡💬 Agentic Chat (Pro Plan, General Availability)
- We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
📜 Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 398b5c59af685f894cf97876d4412a4a39f5f054 and b75cf0e56695494d5defc80ebe796f43be50aeca.
📒 Files selected for processing (12)
app/assets/javascripts/autograder.js(1 hunks)app/controllers/autograders_controller.rb(3 hunks)app/controllers/jobs_controller.rb(1 hunks)app/helpers/assessment_autograde_core.rb(1 hunks)app/views/autograders/_basic_settings.html.erb(1 hunks)app/views/autograders/_ec2_settings.html.erb(1 hunks)app/views/autograders/_form.html.erb(1 hunks)config/environments/development.rb(1 hunks)config/environments/production.rb.template(1 hunks)db/migrate/20241205233214_add_ec2_ssh_fields_to_autograders.rb(1 hunks)db/migrate/20241211042124_add_use_access_key_to_autograder.rb(1 hunks)db/schema.rb(10 hunks)
🧰 Additional context used
🪛 RuboCop (1.73)
db/schema.rb
[convention] 14-15: Extra empty line detected at block body beginning.
(Layout/EmptyLinesAroundBlockBody)
🪛 GitHub Actions: Ruby on Rails CI
db/schema.rb
[error] 444-444: ActiveRecord::MismatchedForeignKey: Column blob_id on table active_storage_attachments does not match column id on active_storage_blobs, which has type bigint. To resolve this issue, change the type of the blob_id column on active_storage_attachments to be :bigint.
🔇 Additional comments (16)
db/migrate/20241211042124_add_use_access_key_to_autograder.rb (1)
1-5: LGTM! Migration to adduse_access_keyboolean flag.This migration properly adds a boolean column with a default value of
false, which is good practice as it ensures existing records have a consistent state after migration.config/environments/development.rb (1)
77-79: LGTM! Feature flag for EC2 autograder.The feature flag is appropriately placed with other feature flags and clearly commented. Setting it to
truein development enables testing of the EC2 SSH functionality.config/environments/production.rb.template (1)
91-93: LGTM! Feature flag disabled by default in production.Good practice to have the feature disabled by default in production. This allows for controlled rollout and testing before enabling it for all production users.
app/assets/javascripts/autograder.js (2)
3-13: Well-structured access key toggle functionality.The callback function correctly toggles and clears the access key fields based on the checkbox state.
15-17: Good implementation of event handling and initial state.The code properly binds the callback to the change event and initializes the field state based on the checkbox's initial value.
app/controllers/jobs_controller.rb (1)
168-171: Good defensive programming for AMI and security group retrieval.The implementation properly retrieves the tagged AMIs and security groups from Tango with a fallback to empty arrays, ensuring robust handling of missing data.
app/views/autograders/_form.html.erb (2)
1-17: Well-implemented tabbed interface with dynamic tab generation.The code creates a clean, responsive tabbed interface that dynamically includes tabs based on configuration settings. It also correctly maintains the active tab state.
19-34: Good use of partials for content organization.The implementation properly separates concerns by using dedicated partials for different sections of the form, improving maintainability and readability.
app/controllers/autograders_controller.rb (3)
19-23: New EC2 configuration fields properly initialized.These new fields support the feature for allowing AMI and Security Group selection, as described in the PR objectives. The initialization values provide sensible defaults.
42-44: Good addition of Tango information retrieval.Retrieving the tagged AMIs and security groups from Tango will populate the dropdown options in the UI. The fallback to empty arrays is a good defensive programming practice.
123-124: Properly updated strong parameters.The autograder_params method has been updated to permit the new EC2 configuration attributes, which is required for mass assignment to work properly.
app/views/autograders/_basic_settings.html.erb (1)
1-37: Well-structured basic settings template.This new template cleanly separates basic autograder settings from the EC2-specific settings. The form includes all necessary fields with appropriate help text, and provides good UX for file operations.
app/helpers/assessment_autograde_core.rb (2)
170-182: EC2 configuration properly integrated into job properties.The conditional check for EC2 SSH feature flag ensures backward compatibility, and the proper handling of access keys is a good security practice.
184-184: Job properties conversion to JSON moved outside the conditional block.This change ensures the job_properties are always converted to JSON before being sent to Tango, regardless of whether EC2 config is enabled.
db/schema.rb (2)
13-13: Schema version updated correctly.The schema version reflects the latest migrations applied to the database.
152-157: New autograders table columns support EC2 configuration.These columns properly store the EC2-specific settings with appropriate default values matching the controller initialization.
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai planto trigger planning for file edits and PR creation.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
As discussed offline, this results in an error, unable to reproduce currently.