Skip to content

Add Lambda-based compilation endpoint system #1676

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

partouf
Copy link
Member

@partouf partouf commented Jun 24, 2025

Summary

This PR implements a Lambda-based compilation endpoint system to handle /api/compilers/<compilerid>/compile and /api/compilers/<compilerid>/cmake endpoints. This is part of the infrastructure work to support the compilation queue system described in compiler-explorer/compiler-explorer#7864.

Key Features

Lambda Functions: Python 3.12 Lambda functions for beta, staging, and prod environments
SQS Integration: FIFO queues for reliable message handling with 30-minute retention
WebSocket Response Handling: Async response retrieval from events system with configurable retry logic
Content Negotiation: Support for both JSON and plain text requests/responses based on Accept headers
ALB Integration: Target groups and listener rules for routing (beta active, staging/prod prepared)
Comprehensive Testing: 23 unit tests covering all scenarios including error cases
Terraform Infrastructure: Modular configuration split into logical files (security, ALB, SQS, Lambda)

Architecture

  1. ALB routes compilation requests to Lambda functions
  2. Lambda adds GUID and compiler ID, sends to SQS queue
  3. Lambda waits for WebSocket response from events system
  4. Returns compilation result to client with proper formatting

Implementation Details

Timeout: 90 seconds for WebSocket response, 120 seconds Lambda timeout
Retry Logic: Configurable retry count (default: 2) for WebSocket connections
Request Handling: Preserves original headers and supports both JSON/plain text bodies
Response Formatting: JSON response by default, plain text assembly when Accept: text/plain
Environment Configuration: Separate queues and WebSocket URLs per environment

Testing

All functionality is covered by unit tests including:

  • Request parsing (JSON/plain text)
  • WebSocket communication scenarios
  • Error handling and timeouts
  • Content negotiation
  • SQS message formatting

Deployment

Beta Environment: Ready for immediate deployment with active listener rules
Staging/Production: Infrastructure ready, listener rules commented out for gradual rollout
Makefile Integration: Build, test, and upload targets integrated with existing workflow

Related to: compiler-explorer/compiler-explorer#7864

Test plan

  • Deploy to beta environment and verify Lambda functions are created
  • Test compilation requests via /beta/api/compilers/gcc/compile endpoint
  • Verify SQS message format matches expected structure for queue consumers
  • Test both JSON and plain text request/response scenarios
  • Monitor CloudWatch logs for proper error handling
  • Validate WebSocket connectivity to events system

🤖 Generated with Claude Code

partouf and others added 4 commits June 24, 2025 23:54
Implements Lambda functions to handle /api/compilers/<compilerid>/compile and
/api/compilers/<compilerid>/cmake endpoints via SQS queues and WebSocket responses.

Features:
- Python Lambda functions for beta/staging/prod environments
- SQS FIFO queues for reliable message handling
- ALB integration with target groups and listener rules
- Support for both JSON and plain text requests/responses
- Content negotiation based on Accept headers
- Comprehensive test coverage with 23 unit tests
- Terraform infrastructure split into logical modules
- Makefile integration for build, test, and deployment

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
…umentation

Features:
- Beta environment auto-scaling based on compilation queue depth (3 msg/instance target)
- Blue-green ASG support with shared queue monitoring
- Comprehensive Lambda compilation workflow documentation
- Code formatting and linting fixes for Lambda function

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Remove hardcoded environment constraints and path pattern logic:
- Remove environment validation restricting to beta/staging/prod
- Add alb_path_patterns variable for flexible path configuration
- Replace hardcoded prod vs non-prod path logic with user-defined patterns
- Update all environment configurations to specify explicit path patterns
- Update documentation and examples to reflect generic approach

Benefits:
- Module can be used with any environment name (dev, test, local, etc.)
- Supports custom path patterns and URL schemes
- Truly reusable across different projects and use cases
- Follows Terraform module best practices for genericity

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@partouf partouf marked this pull request as draft June 24, 2025 23:21
partouf and others added 2 commits June 25, 2025 00:38
Correct WebSocket URLs to match existing infrastructure pattern:
- Beta: wss://events.compiler-explorer.com/beta
- Staging: wss://events.compiler-explorer.com/staging
- Production: wss://events.compiler-explorer.com/prod

This aligns with the AArch64 execution workflow which uses the same
events.compiler-explorer.com WebSocket infrastructure for receiving
asynchronous execution results.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Set visibility timeout to 5 seconds (down from 2 minutes)
- Set message retention to 60 seconds (down from 30 minutes)

These shorter timeouts are more appropriate for the Lambda-based
compilation system where fast message processing and quick cleanup
of unprocessed messages is desired.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@junlarsen junlarsen self-requested a review June 27, 2025 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant