Skip to content
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

feat: enable log rotation + install CW Agent #48

Merged
merged 2 commits into from
Jan 6, 2025
Merged

Conversation

gberenice
Copy link
Member

@gberenice gberenice commented Jan 5, 2025

what

  • Adds configuration in user data to set a maximum journal size and log retention period. This ensures logs rotate properly and prevents the disk from filling.
  • Installs the CloudWatch Agent with default settings to collect and report metrics to AWS CloudWatch.
  • Bumps SSM Agent version to fetch AL2023 + update instance type that supports new AMIs.

why

  • Tailscale runs as a systemd service, and by default, system logs can grow without bound.

references

Summary by CodeRabbit

  • Documentation

    • Added a new section on system logging and monitoring setup for Tailscale
    • Updated README with clearer instructions for logging configuration
    • Refined input variable descriptions
  • New Features

    • Introduced configuration options for journald log management
    • Added CloudWatch Agent installation and metrics reporting
    • Enhanced system logging capabilities
  • Chores

    • Updated module and provider version constraints
    • Changed default instance type from t3.nano to t4g.nano
    • Improved IAM role permissions for CloudWatch integration

@gberenice gberenice requested a review from a team as a code owner January 5, 2025 09:44
Copy link

coderabbitai bot commented Jan 5, 2025

Walkthrough

The pull request introduces enhancements to the Tailscale Subnet Router module, focusing on system logging, monitoring, and configuration management. Key changes include updating the module version, adding new input variables for journald settings, modifying the instance type, and improving the user data script. The modifications aim to provide more flexible logging configuration, better system resource management, and enhanced CloudWatch integration.

Changes

File Changes
README.md - Added "System Logging and Monitoring Setup" section
- Updated provider version constraints
- Added new input variables
- Updated module version to 1.3.0
main.tf - Updated Tailscale module version
- Added CloudWatch Agent IAM policy attachment
userdata.sh.tmpl - Added IP forwarding configuration
- Implemented journald settings
- Installed CloudWatch Agent
- Enhanced Tailscale installation process
variables.tf - Changed default instance type to t4g.nano
- Added journald_system_max_use variable
- Added journald_max_retention_sec variable

Sequence Diagram

sequenceDiagram
    participant EC2 as Tailscale Subnet Router
    participant CW as CloudWatch
    participant Journald as System Logging

    EC2->>Journald: Configure log retention
    EC2->>Journald: Set max disk usage
    EC2->>CW: Install CloudWatch Agent
    EC2->>CW: Report system metrics
    EC2->>Tailscale: Initialize service
Loading

Possibly Related PRs

  • /terraform-aws-tailscale#41: Introduces SSM state storage support for tailscaled
  • /terraform-aws-tailscale#44: Improves userdata.sh.tmpl script for Tailscale configuration

Poem

🌐 Tailscale's dance of bits and bytes,
Logging journeys, CloudWatch's delights,
Routers spinning, metrics in flight,
Configuration's elegant might,
A subnet's symphony takes flight! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 @coderabbitai in 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 @coderabbitai in 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 pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
userdata.sh.tmpl (1)

17-27: Consider adding a sanity check before restarting journald.

While creating the config directory and installing these drop-ins is straightforward, you might log a validation step to check if the file was written correctly before calling systemctl restart systemd-journald.

variables.tf (1)

118-128: Configurable journald retention is a helpful addition.

Exposing journald limits via variables is a solid approach for controlling log growth. You might document recommended values for various workloads or highlight potential constraints for smaller instance types.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a272b79 and f7dead3.

📒 Files selected for processing (4)
  • README.md (4 hunks)
  • main.tf (3 hunks)
  • userdata.sh.tmpl (2 hunks)
  • variables.tf (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
main.tf (1)

Pattern **/*.tf: You're a Terraform expert who has thoroughly studied all the documentation from Hashicorp https://developer.hashicorp.com/terraform/docs and OpenTofu https://opentofu.org/docs/.
You have a strong grasp of Terraform syntax and prioritize providing accurate and insightful code suggestions.
As a fan of the Cloud Posse / SweetOps ecosystem, you incorporate many of their best practices https://docs.cloudposse.com/best-practices/terraform/ while balancing them with general Terraform guidelines.

variables.tf (1)

Pattern **/*.tf: You're a Terraform expert who has thoroughly studied all the documentation from Hashicorp https://developer.hashicorp.com/terraform/docs and OpenTofu https://opentofu.org/docs/.
You have a strong grasp of Terraform syntax and prioritize providing accurate and insightful code suggestions.
As a fan of the Cloud Posse / SweetOps ecosystem, you incorporate many of their best practices https://docs.cloudposse.com/best-practices/terraform/ while balancing them with general Terraform guidelines.

🔇 Additional comments (13)
userdata.sh.tmpl (3)

11-16: Good use of Administrator drop-ins for journald.

This approach to placing the custom journald config in /etc/systemd/journald.conf.d with a high precedence filename (99-custom.conf) is a clean way to override default settings.


57-61: Great use of a retry mechanism for CloudWatch Agent installation.

The retry command ensures resilience in case of transient network failures. Confirm that this step is being logged or monitored so any persistent install failures are visible.


62-62: Confirm Tailscale has enough disk space under journald constraints.

Ensure that the journald limits (e.g., 200M) do not negatively impact Tailscale’s logs during peak usage or debugging sessions.

main.tf (3)

29-31: Good practice: externalizing journald parameters.

Passing journald_system_max_use and journald_max_retention_sec via locals helps keep the user data flexible.


40-40: Module version upgraded to 1.3.0.

Since the update includes journald configurations and CloudWatch Agent setup, make sure to document any new usage assumptions for downstream users.


127-131: CloudWatchAgentServerPolicy role attachment looks correct.

Attaching this policy to the same role used by the Tailscale instance is a clean way to provide CloudWatch Agent permissions without introducing extra roles.

variables.tf (1)

83-83: Switching instance type to t4g.nano.

Note that t4g.* is ARM-based. Ensure your software suite (including Tailscale dependencies or any other native binaries) is compatible with ARM architecture.

README.md (6)

62-69: Clear explanation of the new system logging and monitoring setup.

Documenting journald retention and CloudWatch Agent installation ensures that users understand and can easily customize these new features.


82-85: Updated provider constraints appear consistent.

Specifying a minimum supported provider version helps users avoid unexpected compatibility issues.


93-93: Module version reference (1.3.0).

Ensure you’ve tested a full run with this version to confirm stable provisioning.


98-102: Resource listing includes the new IAM policy attachment.

Nicely documented in the table, ensuring discoverability of the new resource.


126-128: Updated instance_type and journald variables.

These new variable defaults reinforce the changes in the user data script, ensuring consistent behavior out of the box.


147-147: Enhanced explanation of ssm_state_enabled.

The updated description helps users better understand storing Tailscale state in AWS SSM, complementing the journald and CloudWatch enhancements.

Copy link
Member

@Sytten Sytten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, love it!

@gberenice gberenice merged commit 560774b into main Jan 6, 2025
3 checks passed
@gberenice gberenice deleted the feature/log-rotation branch January 6, 2025 09:58
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