Skip to content

R71968 r72115 fix cloudwatch nginx logs pr 2.x #2361

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

Merged
merged 9 commits into from
Mar 13, 2025
6 changes: 6 additions & 0 deletions roles/aws/aws_ec2_autoscale_cluster/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ aws_ec2_autoscale_cluster:
health_check_timeout: 5
health_check_healthy_count: 5
health_check_unhealthy_count: 2
## Target Group Stickiness. Disabled by default unless set otherwise. Uncomment if needed:
# target_group_stickiness_enabled: true
# target_group_stickiness_type: "lb_cookie" # Valid values are lb_cookie, app_cookie or source_ip.
# target_group_stickiness_app_cookie_name: "my_app_cookie"
# target_group_stickiness_app_cookie_duration: 86400
# target_group_stickiness_lb_cookie_duration: 86400
# ALB settings
create_elb: true # determines whether an ELB (currently, this is an ALB) is created as part of the ASG. This needs to be `true` in order to create a CloudFront distribution.
alb_idle_timeout: 60
Expand Down
5 changes: 5 additions & 0 deletions roles/aws/aws_ec2_autoscale_cluster/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@
health_check_timeout: "{{ aws_ec2_autoscale_cluster.health_check_timeout }}"
healthy_threshold_count: "{{ aws_ec2_autoscale_cluster.health_check_healthy_count }}"
unhealthy_threshold_count: "{{ aws_ec2_autoscale_cluster.health_check_unhealthy_count }}"
stickiness_enabled: "{{ aws_ec2_autoscale_cluster.target_group_stickiness_enabled | default(omit) }}"
stickiness_type: "{{ aws_ec2_autoscale_cluster.target_group_stickiness_type | default(omit) }}"
stickiness_app_cookie_name: "{{ aws_ec2_autoscale_cluster.target_group_stickiness_app_cookie_name | default(omit) }}"
stickiness_app_cookie_duration: "{{ aws_ec2_autoscale_cluster.target_group_stickiness_app_cookie_duration | default(omit) }}"
stickiness_lb_cookie_duration: "{{ aws_ec2_autoscale_cluster.target_group_stickiness_lb_cookie_duration | default(omit) }}"
modify_targets: false
register: _aws_ec2_target_group_created
when:
Expand Down
6 changes: 6 additions & 0 deletions roles/aws/aws_elb/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ aws_elb:
# - example-server-two
targets_port: 80 # Port to forward to on target servers.
modify_targets: false # Set to true if this is a standalone ELB, so the list of targets in the target group can be updated.
## Target Group Stickiness. Disabled by default unless set otherwise. Uncomment if needed:
# stickiness_enabled: true
# stickiness_type: "lb_cookie" # Valid values are lb_cookie, app_cookie or source_ip.
# stickiness_app_cookie_name: "my_app_cookie"
# stickiness_app_cookie_duration: 86400
# stickiness_lb_cookie_duration: 86400
# ELB settings
idle_timeout: 60
ip_address_type: "ipv4" # Can be 'ipv4' or 'dualstack' (the latter includes IPv4 and IPv6 addresses).
Expand Down
5 changes: 5 additions & 0 deletions roles/aws/aws_elb/tasks/target_group.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@
health_check_timeout: "{{ target_group.health_check_timeout }}"
healthy_threshold_count: "{{ target_group.health_check_healthy_count }}"
unhealthy_threshold_count: "{{ target_group.health_check_unhealthy_count }}"
stickiness_enabled: "{{ target_group.stickiness_enabled | default(omit) }}"
stickiness_type: "{{ target_group.stickiness_type | default(omit) }}"
stickiness_app_cookie_name: "{{ target_group.stickiness_app_cookie_name | default(omit) }}"
stickiness_app_cookie_duration: "{{ target_group.stickiness_app_cookie_duration | default(omit) }}"
stickiness_lb_cookie_duration: "{{ target_group.stickiness_lb_cookie_duration | default(omit) }}"
modify_targets: "{{ target_group.modify_targets }}"
targets: "{{ _targets }}"
2 changes: 0 additions & 2 deletions roles/debian/nginx/templates/cloudwatch-main.json.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
### {{ ansible_managed }}

{
"logs": {
"logs_collected": {
Expand Down
2 changes: 0 additions & 2 deletions roles/debian/nginx/templates/cloudwatch-vhost.json.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
### {{ ansible_managed }}

{
"logs": {
"logs_collected": {
Expand Down
3 changes: 3 additions & 0 deletions roles/debian/php-fpm/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ php:
max_accelerated_files: 2000
validate_timestamps: 1
clear_env: "yes"
# Cloudwatch log settings.
log_group_prefix: ""
log_stream_name: example
26 changes: 26 additions & 0 deletions roles/debian/php-fpm/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,29 @@
with_items: "{{ php.version }}"
loop_control:
loop_var: version

- name: Check if we have an AWS Cloudwatch folder.
ansible.builtin.stat:
path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d
register: _php_cloudwatch_dir

- name: Generate AWS Cloudwatch config for a single, fixed port PHP version.
ansible.builtin.template:
src: cloudwatch-php-fpm-fixedport.json.j2
dest: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/php-fpm.json
force: true
when:
- _php_cloudwatch_dir.stat.isdir is defined and _php_cloudwatch_dir.stat.isdir
- php.fpm.tcp_port | length > 0

- name: Generate AWS Cloudwatch config for dynamic PHP versioning.
ansible.builtin.template:
src: cloudwatch-php-fpm.json.j2
dest: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/php-fpm.json
force: true
with_items: "{{ php.version }}"
when:
- _php_cloudwatch_dir.stat.isdir is defined and _php_cloudwatch_dir.stat.isdir
- php.fpm.tcp_port | length == 0
loop_control:
loop_var: version
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"logs": {
"logs_collected": {
"files": {
"collect_list": [
{
"file_path": "/var/log/php{{ php.version[0] }}-fpm.log",
{% if php.fpm.log_group_prefix is defined and php.fpm.log_group_prefix|length %}
"log_group_name": "{{ php.fpm.log_group_prefix }}php{{ php.version[0] }}",
{% else %}
"log_group_name": "php",
{% endif %}
{% if php.fpm.log_stream_name is defined and php.fpm.log_stream_name|length %}
"log_stream_name": "{{ php.fpm.log_stream_name }}"
{% else %}
"log_stream_name": "php-fpm"
{% endif %}
},
{
"file_path": "{{ php.fpm.slowlog_file_directory }}/php{{ php.version[0] }}-fpm.slow.log",
{% if php.fpm.log_group_prefix is defined and php.fpm.log_group_prefix|length %}
"log_group_name": "{{ php.fpm.log_group_prefix }}php{{ php.version[0] }}",
{% else %}
"log_group_name": "php",
{% endif %}
{% if php.fpm.log_stream_name is defined and php.fpm.log_stream_name|length %}
"log_stream_name": "{{ php.fpm.log_stream_name }}-slowlog"
{% else %}
"log_stream_name": "php-fpm-slowlog"
{% endif %}
}
]
}
}
}
}
36 changes: 36 additions & 0 deletions roles/debian/php-fpm/templates/cloudwatch-php-fpm.json.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"logs": {
"logs_collected": {
"files": {
"collect_list": [
{
"file_path": "/var/log/php{{ version }}-fpm.log",
{% if php.fpm.log_group_prefix is defined and php.fpm.log_group_prefix|length %}
"log_group_name": "{{ php.fpm.log_group_prefix }}php{{ version }}",
{% else %}
"log_group_name": "php",
{% endif %}
{% if php.fpm.log_stream_name is defined and php.fpm.log_stream_name|length %}
"log_stream_name": "{{ php.fpm.log_stream_name }}"
{% else %}
"log_stream_name": "php-fpm"
{% endif %}
},
{
"file_path": "{{ php.fpm.slowlog_file_directory }}/php{{ version }}-fpm.slow.log",
{% if php.fpm.log_group_prefix is defined and php.fpm.log_group_prefix|length %}
"log_group_name": "{{ php.fpm.log_group_prefix }}php{{ version }}",
{% else %}
"log_group_name": "php",
{% endif %}
{% if php.fpm.log_stream_name is defined and php.fpm.log_stream_name|length %}
"log_stream_name": "{{ php.fpm.log_stream_name }}-slowlog"
{% else %}
"log_stream_name": "php-fpm-slowlog"
{% endif %}
}
]
}
}
}
}
Loading