-
Notifications
You must be signed in to change notification settings - Fork 1
Add comprehensive logs functionality with real-time streaming #20
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
Conversation
Add new logs subcommand that accepts cluster/service parameters and displays logs for the specified ECS service. Currently includes placeholder implementation that will be extended with actual log tailing functionality.
…eaming - Add GetServiceLogs function to retrieve logs from all running service tasks - Implement TailServiceLogs using AWS StartLiveTail API for real-time streaming - Add 5-minute default time window for log retrieval to improve performance - Support log stream prefix patterns to automatically capture all task streams - Add proper AWS account ID resolution using STS for StartLiveTail ARN requirements - Integrate CloudWatch Logs types and STS client in AWSClients structure This provides both one-shot log viewing and real-time log tailing capabilities for ECS services, replacing inefficient polling with proper streaming.
…usability - Extract core CloudWatch log streaming logic into TailLogGroups function - Keep TailServiceLogs as wrapper handling ECS-specific logic - Remove unused ServiceName field from ExecuteResult struct - Fix compilation issues in cmd/run.go and execute.go - Improve separation of concerns and code reusability
…pletion - Replace polling-based log retrieval with real-time streaming - Use TailLogGroups for more efficient CloudWatch API usage - Add goroutine for concurrent log collection while monitoring task status - Improve user experience with real-time log output - Add informative message about CTRL+C behavior - Remove redundant service loading message from run command
Remove separate getTaskLogs function since it was only used in one place. Merge the logic directly into GetServiceLogs to reduce complexity and eliminate unnecessary function overhead. - Remove 52 lines of code by eliminating getTaskLogs function - Inline log filtering logic directly in GetServiceLogs task loop - Preserve identical functionality and error handling - Improve code maintainability with single-purpose function
- Extract partition from caller's ARN to handle aws-cn, aws-us-gov partitions - Create dedicated arn.go with partition-aware ARN utilities - Replace hardcoded "aws" partition with dynamic extraction - Ensure compatibility across all AWS regions and partitions
- Add comprehensive logs section describing CloudWatch integration - Include examples for both basic and follow mode usage - Document automatic log stream discovery and chronological display
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.
Pull Request Overview
This PR adds comprehensive logging functionality to RunECS with real-time streaming capabilities, including a new logs command for viewing CloudWatch logs from ECS services and support for AWS partitions.
Key changes:
- Added new
logscommand with real-time streaming support via-f/--followflag - Implemented CloudWatch log group and stream discovery for ECS services
- Enhanced ARN handling with AWS partition support for multi-region compatibility
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| cmd/logs.go | New logs command implementation with follow mode and signal handling |
| internal/ecs/logs.go | Core logging functionality with service log retrieval and real-time tailing |
| internal/ecs/arn.go | New ARN utilities for partition extraction and ARN construction |
| internal/ecs/types.go | Added STS client and log stream prefix type definitions |
| internal/ecs/client.go | Added STS client initialization |
| internal/ecs/execute.go | Refactored to use new logging infrastructure with real-time streaming |
| internal/ecs/utils.go | Moved ARN extraction function to dedicated arn.go file |
| cmd/run.go | Refactored flag handling to use cobra's GetBool/GetString methods |
| cmd/deploy.go | Refactored flag handling to use cobra's GetBool/GetString methods |
| README.md | Updated documentation with logs command examples |
Comments suppressed due to low confidence (1)
internal/ecs/logs.go:88
- The extractARNResource function returns two values (string, error), but only the error is being checked. The returned string value should be assigned to processID.
processID, err := extractARNResource(taskArn)
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Add structured logging with slog for better debugging of CloudWatch Logs stream issues. Replace silent returns with proper error, warning, and debug messages including context information. - Add error constants for stream error categorization - Log stream errors at ERROR level with error details - Log nil events at DEBUG level (common in streaming) - Log unexpected event types at WARN level with type info - Include context in all log messages for easier debugging
Summary
logscommand for viewing ECS service logs from CloudWatch-f/--followflagKey Features
runecs logs --service cluster/serviceshows logs from the last hourrunecs logs -f --service cluster/serviceprovides live log tailingImplementation Details
cmd/logs.gocommand with follow flag supportinternal/ecs/logs.gowith comprehensive logging functionality:GetServiceLogs()for fetching historical logsTailServiceLogs()for real-time streamingTailLogGroups()for generic CloudWatch log group tailinginternal/ecs/arn.goTest Plan