Skip to content

Commit

Permalink
PMM-9315 Modify nginx config files instead of replacing
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff committed Nov 13, 2024
1 parent 083c72d commit 5731d53
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 337 deletions.
12 changes: 12 additions & 0 deletions build/ansible/roles/loki/files/json_log_format.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'time="$time_iso8601" '
'host=$http_host '
'remote_addr=$remote_addr '
'request_method=$request_method '
'request="$request_uri" '
'request_time=$request_time '
'body_bytes_sent=$body_bytes_sent '
'server_protocol="$server_protocol" '
'status=$status '
'http_referrer="$http_referer" '
'http_x_forwarded_for="$http_x_forwarded_for" '
'http_user_agent="$http_user_agent"';
7 changes: 7 additions & 0 deletions build/ansible/roles/loki/files/loki_location.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Loki
location = /loki/api/v1/push {
proxy_pass http://127.0.0.1:3100/$request_uri;
proxy_read_timeout 600;
proxy_set_header Connection "";
client_body_buffer_size 2m;
}
62 changes: 0 additions & 62 deletions build/ansible/roles/loki/files/nginx.conf

This file was deleted.

263 changes: 0 additions & 263 deletions build/ansible/roles/loki/files/pmm.conf

This file was deleted.

40 changes: 28 additions & 12 deletions build/ansible/roles/loki/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,32 @@
owner: pmm
group: pmm

- name: Override pmm.conf file
copy:
src: pmm.conf
dest: /etc/nginx/conf.d/pmm.conf
owner: pmm
group: pmm
- name: Remove the end of log_format line in nginx.conf
command: sed -i 's/^\([[:space:]]*log_format main\).*/\1/' /etc/nginx/nginx.conf

- name: Override nginx.conf file
copy:
src: nginx.conf
dest: /etc/nginx/nginx.conf
owner: pmm
group: pmm
- name: Remove the log_format in nginx.conf
command: sed -i '/log_format/{n;N;d;}' /etc/nginx/nginx.conf

- name: Replace the original log_format with a json one
blockinfile:
path: /etc/nginx/nginx.conf
marker: "{mark}"
marker_begin: "#LOG_FORMAT_BEGIN"
marker_end: "#LOG_FORMAT_END"
insertafter: "log_format"
block: "{{ lookup('ansible.builtin.file', '/opt/ansible/roles/loki/files/json_log_format.conf') }}"

- name: Remove ansible markers from nginx.conf
command: sed -i '/^#LOG_FORMAT_.*/d' /etc/nginx/nginx.conf

- name: Add Loki location to pmm.conf
blockinfile:
path: /etc/nginx/conf.d/pmm.conf
marker: "{mark}"
marker_begin: "#LOKI_LOCATION_BEGIN"
marker_end: "#LOKI_LOCATION_END"
insertbefore: "# Swagger UI"
block: "{{ lookup('ansible.builtin.file', '/opt/ansible/roles/loki/files/loki_location.conf') }}"

- name: Remove ansible markers from pmm.conf
command: sed -i '/^#LOKI_LOCATION_.*/d'/etc/nginx/conf.d/pmm.conf
Loading

0 comments on commit 5731d53

Please sign in to comment.