Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@meap
Copy link
Owner

@meap meap commented Aug 17, 2025

Summary

  • Add new logs command for viewing ECS service logs from CloudWatch
  • Implement real-time log streaming with -f/--follow flag
  • Support for AWS partitions (aws, aws-cn, aws-us-gov) in log group ARN construction
  • Automatic discovery of CloudWatch log groups and streams for ECS services

Key Features

  • Basic log viewing: runecs logs --service cluster/service shows logs from the last hour
  • Real-time streaming: runecs logs -f --service cluster/service provides live log tailing
  • Multi-task support: Aggregates logs from all running tasks in a service
  • Chronological ordering: Displays logs sorted by timestamp across all tasks
  • AWS partition support: Works across different AWS partitions (standard, China, GovCloud)

Implementation Details

  • New cmd/logs.go command with follow flag support
  • Enhanced internal/ecs/logs.go with comprehensive logging functionality:
    • GetServiceLogs() for fetching historical logs
    • TailServiceLogs() for real-time streaming
    • TailLogGroups() for generic CloudWatch log group tailing
  • Improved ARN handling with partition support in internal/ecs/arn.go
  • Signal handling for graceful shutdown on Ctrl+C
  • Robust error handling for missing log configurations

Test Plan

  • Test basic log viewing for services with CloudWatch logging
  • Test real-time log streaming with follow mode
  • Test graceful shutdown with Ctrl+C
  • Test with services having multiple running tasks
  • Test error handling for services without CloudWatch logging
  • Test AWS partition support across different regions

meap added 8 commits August 17, 2025 14:54
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
@meap meap changed the title ✨ feat: add comprehensive logs functionality with real-time streaming Add comprehensive logs functionality with real-time streaming Aug 17, 2025
@meap meap self-assigned this Aug 17, 2025
@meap meap requested a review from Copilot August 17, 2025 08:35
Copy link

Copilot AI left a 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 logs command with real-time streaming support via -f/--follow flag
  • 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
@meap meap merged commit ed7a9d1 into main Aug 17, 2025
@meap meap deleted the meap/tail-logs branch August 17, 2025 08:42
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.

2 participants