Skip to content

Commit dbfd274

Browse files
R71968 r72115 fix cloudwatch nginx logs pr 2.x (#2361)
* r71968-r72115-fix-cloudwatch-nginx-logs * target group sessions stickiness * r71968-r72115-fix-cloudwatch-nginx-logs * r71968-r72115-fix-cloudwatch-nginx-logs * r71968-r72115-fix-cloudwatch-nginx-logs * r71968-r72115-fix-cloudwatch-nginx-logs-and-add-php-logs
1 parent 42ad035 commit dbfd274

File tree

10 files changed

+123
-4
lines changed

10 files changed

+123
-4
lines changed

roles/aws/aws_ec2_autoscale_cluster/defaults/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ aws_ec2_autoscale_cluster:
144144
health_check_timeout: 5
145145
health_check_healthy_count: 5
146146
health_check_unhealthy_count: 2
147+
## Target Group Stickiness. Disabled by default unless set otherwise. Uncomment if needed:
148+
# target_group_stickiness_enabled: true
149+
# target_group_stickiness_type: "lb_cookie" # Valid values are lb_cookie, app_cookie or source_ip.
150+
# target_group_stickiness_app_cookie_name: "my_app_cookie"
151+
# target_group_stickiness_app_cookie_duration: 86400
152+
# target_group_stickiness_lb_cookie_duration: 86400
147153
# ALB settings
148154
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.
149155
alb_idle_timeout: 60

roles/aws/aws_ec2_autoscale_cluster/tasks/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@
336336
health_check_timeout: "{{ aws_ec2_autoscale_cluster.health_check_timeout }}"
337337
healthy_threshold_count: "{{ aws_ec2_autoscale_cluster.health_check_healthy_count }}"
338338
unhealthy_threshold_count: "{{ aws_ec2_autoscale_cluster.health_check_unhealthy_count }}"
339+
stickiness_enabled: "{{ aws_ec2_autoscale_cluster.target_group_stickiness_enabled | default(omit) }}"
340+
stickiness_type: "{{ aws_ec2_autoscale_cluster.target_group_stickiness_type | default(omit) }}"
341+
stickiness_app_cookie_name: "{{ aws_ec2_autoscale_cluster.target_group_stickiness_app_cookie_name | default(omit) }}"
342+
stickiness_app_cookie_duration: "{{ aws_ec2_autoscale_cluster.target_group_stickiness_app_cookie_duration | default(omit) }}"
343+
stickiness_lb_cookie_duration: "{{ aws_ec2_autoscale_cluster.target_group_stickiness_lb_cookie_duration | default(omit) }}"
339344
modify_targets: false
340345
register: _aws_ec2_target_group_created
341346
when:

roles/aws/aws_elb/defaults/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ aws_elb:
4545
# - example-server-two
4646
targets_port: 80 # Port to forward to on target servers.
4747
modify_targets: false # Set to true if this is a standalone ELB, so the list of targets in the target group can be updated.
48+
## Target Group Stickiness. Disabled by default unless set otherwise. Uncomment if needed:
49+
# stickiness_enabled: true
50+
# stickiness_type: "lb_cookie" # Valid values are lb_cookie, app_cookie or source_ip.
51+
# stickiness_app_cookie_name: "my_app_cookie"
52+
# stickiness_app_cookie_duration: 86400
53+
# stickiness_lb_cookie_duration: 86400
4854
# ELB settings
4955
idle_timeout: 60
5056
ip_address_type: "ipv4" # Can be 'ipv4' or 'dualstack' (the latter includes IPv4 and IPv6 addresses).

roles/aws/aws_elb/tasks/target_group.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,10 @@
3030
health_check_timeout: "{{ target_group.health_check_timeout }}"
3131
healthy_threshold_count: "{{ target_group.health_check_healthy_count }}"
3232
unhealthy_threshold_count: "{{ target_group.health_check_unhealthy_count }}"
33+
stickiness_enabled: "{{ target_group.stickiness_enabled | default(omit) }}"
34+
stickiness_type: "{{ target_group.stickiness_type | default(omit) }}"
35+
stickiness_app_cookie_name: "{{ target_group.stickiness_app_cookie_name | default(omit) }}"
36+
stickiness_app_cookie_duration: "{{ target_group.stickiness_app_cookie_duration | default(omit) }}"
37+
stickiness_lb_cookie_duration: "{{ target_group.stickiness_lb_cookie_duration | default(omit) }}"
3338
modify_targets: "{{ target_group.modify_targets }}"
3439
targets: "{{ _targets }}"

roles/debian/nginx/templates/cloudwatch-main.json.j2

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
### {{ ansible_managed }}
2-
31
{
42
"logs": {
53
"logs_collected": {

roles/debian/nginx/templates/cloudwatch-vhost.json.j2

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
### {{ ansible_managed }}
2-
31
{
42
"logs": {
53
"logs_collected": {

roles/debian/php-fpm/defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ php:
5555
max_accelerated_files: 2000
5656
validate_timestamps: 1
5757
clear_env: "yes"
58+
# Cloudwatch log settings.
59+
log_group_prefix: ""
60+
log_stream_name: example

roles/debian/php-fpm/tasks/main.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,29 @@
5353
with_items: "{{ php.version }}"
5454
loop_control:
5555
loop_var: version
56+
57+
- name: Check if we have an AWS Cloudwatch folder.
58+
ansible.builtin.stat:
59+
path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d
60+
register: _php_cloudwatch_dir
61+
62+
- name: Generate AWS Cloudwatch config for a single, fixed port PHP version.
63+
ansible.builtin.template:
64+
src: cloudwatch-php-fpm-fixedport.json.j2
65+
dest: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/php-fpm.json
66+
force: true
67+
when:
68+
- _php_cloudwatch_dir.stat.isdir is defined and _php_cloudwatch_dir.stat.isdir
69+
- php.fpm.tcp_port | length > 0
70+
71+
- name: Generate AWS Cloudwatch config for dynamic PHP versioning.
72+
ansible.builtin.template:
73+
src: cloudwatch-php-fpm.json.j2
74+
dest: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/php-fpm.json
75+
force: true
76+
with_items: "{{ php.version }}"
77+
when:
78+
- _php_cloudwatch_dir.stat.isdir is defined and _php_cloudwatch_dir.stat.isdir
79+
- php.fpm.tcp_port | length == 0
80+
loop_control:
81+
loop_var: version
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"logs": {
3+
"logs_collected": {
4+
"files": {
5+
"collect_list": [
6+
{
7+
"file_path": "/var/log/php{{ php.version[0] }}-fpm.log",
8+
{% if php.fpm.log_group_prefix is defined and php.fpm.log_group_prefix|length %}
9+
"log_group_name": "{{ php.fpm.log_group_prefix }}php{{ php.version[0] }}",
10+
{% else %}
11+
"log_group_name": "php",
12+
{% endif %}
13+
{% if php.fpm.log_stream_name is defined and php.fpm.log_stream_name|length %}
14+
"log_stream_name": "{{ php.fpm.log_stream_name }}"
15+
{% else %}
16+
"log_stream_name": "php-fpm"
17+
{% endif %}
18+
},
19+
{
20+
"file_path": "{{ php.fpm.slowlog_file_directory }}/php{{ php.version[0] }}-fpm.slow.log",
21+
{% if php.fpm.log_group_prefix is defined and php.fpm.log_group_prefix|length %}
22+
"log_group_name": "{{ php.fpm.log_group_prefix }}php{{ php.version[0] }}",
23+
{% else %}
24+
"log_group_name": "php",
25+
{% endif %}
26+
{% if php.fpm.log_stream_name is defined and php.fpm.log_stream_name|length %}
27+
"log_stream_name": "{{ php.fpm.log_stream_name }}-slowlog"
28+
{% else %}
29+
"log_stream_name": "php-fpm-slowlog"
30+
{% endif %}
31+
}
32+
]
33+
}
34+
}
35+
}
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"logs": {
3+
"logs_collected": {
4+
"files": {
5+
"collect_list": [
6+
{
7+
"file_path": "/var/log/php{{ version }}-fpm.log",
8+
{% if php.fpm.log_group_prefix is defined and php.fpm.log_group_prefix|length %}
9+
"log_group_name": "{{ php.fpm.log_group_prefix }}php{{ version }}",
10+
{% else %}
11+
"log_group_name": "php",
12+
{% endif %}
13+
{% if php.fpm.log_stream_name is defined and php.fpm.log_stream_name|length %}
14+
"log_stream_name": "{{ php.fpm.log_stream_name }}"
15+
{% else %}
16+
"log_stream_name": "php-fpm"
17+
{% endif %}
18+
},
19+
{
20+
"file_path": "{{ php.fpm.slowlog_file_directory }}/php{{ version }}-fpm.slow.log",
21+
{% if php.fpm.log_group_prefix is defined and php.fpm.log_group_prefix|length %}
22+
"log_group_name": "{{ php.fpm.log_group_prefix }}php{{ version }}",
23+
{% else %}
24+
"log_group_name": "php",
25+
{% endif %}
26+
{% if php.fpm.log_stream_name is defined and php.fpm.log_stream_name|length %}
27+
"log_stream_name": "{{ php.fpm.log_stream_name }}-slowlog"
28+
{% else %}
29+
"log_stream_name": "php-fpm-slowlog"
30+
{% endif %}
31+
}
32+
]
33+
}
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)