From 05b1e8da071593790dd85813b6cdbd56a2c682a4 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Sun, 14 Apr 2024 17:48:46 -0500 Subject: [PATCH] loki: flesh out role --- roles/loki/defaults/main.yaml | 72 ++++++++++++++++++---------- roles/loki/handlers/main.yaml | 2 +- roles/loki/tasks/configure.yaml | 24 ++++++---- roles/loki/templates/config.yaml.j2 | 55 +++++++++++++++++++++ roles/loki/templates/loki.service.j2 | 14 +++--- roles/loki/templates/loki.yaml.j2 | 30 ------------ 6 files changed, 125 insertions(+), 72 deletions(-) create mode 100644 roles/loki/templates/config.yaml.j2 delete mode 100644 roles/loki/templates/loki.yaml.j2 diff --git a/roles/loki/defaults/main.yaml b/roles/loki/defaults/main.yaml index 8d5aa44..aefd06b 100644 --- a/roles/loki/defaults/main.yaml +++ b/roles/loki/defaults/main.yaml @@ -26,12 +26,17 @@ loki_user_shell: /usr/sbin/nologin loki_group: loki loki_group_state: "{{ loki_user_state | default('present') }}" -loki_config_path: /etc/loki.yaml - loki_var_path: /var/lib/loki loki_var_owner: "{{ loki_user }}" loki_var_group: "{{ loki_group }}" -loki_var_mode: "0755" +loki_var_mode: "0700" + +loki_etc_path: /etc/loki +loki_etc_owner: "{{ loki_user }}" +loki_etc_group: "{{ loki_group }}" +loki_etc_mode: "0755" + +loki_config_path: "{{ loki_etc_path }}/config.yaml" loki_bin_path: /usr/local/bin @@ -39,36 +44,51 @@ loki_auth_enabled: false loki_server: http_listen_port: 3100 + grpc_listen_port: 9096 -loki_ingester: - lifecycler: - address: 127.0.0.1 - ring: - kvstore: - store: inmemory - replication_factor: 1 - final_sleep: 0s - chunk_idle_period: 5m - chunk_retain_period: 30s +loki_common: + instance_addr: 127.0.0.1 + path_prefix: "{{ loki_var_path }}" + storage: + filesystem: + chunks_directory: "{{ loki_var_path }}/chunks" + rules_directory: "{{ loki_var_path }}/rules" + replication_factor: 1 + ring: + kvstore: + store: inmemory + +loki_query_range: + results_cache: + cache: + embedded_cache: + enabled: true + max_size_mb: 100 + +# loki_storage_config: +# {} loki_schema_config: configs: - - from: 2020-05-15 - store: boltdb - object_store: filesystem + - from: 2020-10-24 + store: boltdb-shipper + object_store: gcs schema: v11 index: prefix: index_ - period: 168h + period: 24h -loki_storage_config: - boltdb: - directory: "{{ loki_var_path }}/index" - filesystem: - directory: "{{ loki_var_path }}/chunks" +loki_ruler: + alertmanager_url: http://localhost:9093 + +# loki_query_scheduler: +# {} + +# loki_querier: +# {} + +# loki_compactor: +# {} loki_limits_config: - enforce_metric_name: false - reject_old_samples: true - reject_old_samples_max_age: 168h - ingestion_burst_size_mb: 16 + retention_period: 744h \ No newline at end of file diff --git a/roles/loki/handlers/main.yaml b/roles/loki/handlers/main.yaml index 52aefa8..c03ed33 100644 --- a/roles/loki/handlers/main.yaml +++ b/roles/loki/handlers/main.yaml @@ -3,4 +3,4 @@ systemd: name: loki.service daemon_reload: true - state: restarted + state: restarted \ No newline at end of file diff --git a/roles/loki/tasks/configure.yaml b/roles/loki/tasks/configure.yaml index 7ae94b6..3126249 100644 --- a/roles/loki/tasks/configure.yaml +++ b/roles/loki/tasks/configure.yaml @@ -15,14 +15,13 @@ home: "{{ loki_var_path }}" state: "{{ loki_user_state | default('present') }}" -- name: configure - template: - src: loki.yaml.j2 - dest: "{{ loki_config_path }}" - owner: root - group: root - mode: 0444 - notify: restart loki +- name: create etc path + file: + path: "{{ loki_etc_path }}" + state: directory + owner: "{{ loki_etc_owner }}" + group: "{{ loki_etc_group }}" + mode: "{{ loki_etc_mode }}" - name: create var path file: @@ -32,6 +31,15 @@ group: "{{ loki_var_group }}" mode: "{{ loki_var_mode }}" +- name: configure + template: + src: config.yaml.j2 + dest: "{{ loki_config_path }}" + owner: "{{ loki_user }}" + group: "{{ loki_group }}" + mode: 0400 + notify: restart loki + - name: configure systemd template template: src: "{{ loki_service_name }}.j2" diff --git a/roles/loki/templates/config.yaml.j2 b/roles/loki/templates/config.yaml.j2 new file mode 100644 index 0000000..e97e92e --- /dev/null +++ b/roles/loki/templates/config.yaml.j2 @@ -0,0 +1,55 @@ +{{ ansible_managed | comment }} +--- +{% if loki_auth_enabled is defined %} +auth_enabled: {{ loki_auth_enabled | bool | lower }} +{% endif %} + +{% if loki_server is defined %} +server: + {{ loki_server | to_nice_yaml(indent=2) | indent(2, False) }} +{% endif -%} + +{% if loki_common is defined %} +common: + {{ loki_common | to_nice_yaml(indent=2) | indent(2, False) }} +{% endif -%} + +{% if loki_query_range is defined %} +query_range: + {{ loki_query_range | to_nice_yaml(indent=2) | indent(2, False) }} +{% endif -%} + +{% if loki_storage_config is defined %} +storage_config: + {{ loki_storage_config | to_nice_yaml(indent=2) | indent(2, False) }} +{% endif -%} + +{% if loki_schema_config is defined %} +schema_config: + {{ loki_schema_config | to_nice_yaml(indent=2) | indent(2, False) }} +{% endif -%} + +{% if loki_ruler is defined %} +ruler: + {{ loki_ruler | to_nice_yaml(indent=2) | indent(2, False) }} +{% endif -%} + +{% if loki_query_scheduler is defined %} +query_scheduler: + {{ loki_query_scheduler | to_nice_yaml(indent=2) | indent(2, False) }} +{% endif -%} + +{% if loki_querier is defined %} +querier: + {{ loki_querier | to_nice_yaml(indent=2) | indent(2, False) }} +{% endif -%} + +{% if loki_compactor is defined %} +compactor: + {{ loki_compactor | to_nice_yaml(indent=2) | indent(2, False) }} +{% endif -%} + +{% if loki_limits_config is defined %} +limits_config: + {{ loki_limits_config | to_nice_yaml(indent=2) | indent(2, False) }} +{% endif -%} \ No newline at end of file diff --git a/roles/loki/templates/loki.service.j2 b/roles/loki/templates/loki.service.j2 index ca4057c..799c0d6 100644 --- a/roles/loki/templates/loki.service.j2 +++ b/roles/loki/templates/loki.service.j2 @@ -1,19 +1,19 @@ {{ ansible_managed | comment }} [Unit] -Description=Loki -After=network-online.target +Description=Loki service +After=network.target [Service] Type=simple User={{ loki_user }} -Group={{ loki_group }} ExecStart={{ loki_bin_path }}/loki \ -config.file {{ loki_config_path }} -WorkingDirectory={{ loki_var_path }} -Restart=always -RestartSec=1 +WorkingDirectory={{ loki_var_path }} +TimeoutSec = 120 +Restart = on-failure +RestartSec = 2 [Install] -WantedBy=multi-user.target +WantedBy=multi-user.target \ No newline at end of file diff --git a/roles/loki/templates/loki.yaml.j2 b/roles/loki/templates/loki.yaml.j2 deleted file mode 100644 index 762c220..0000000 --- a/roles/loki/templates/loki.yaml.j2 +++ /dev/null @@ -1,30 +0,0 @@ -{{ ansible_managed | comment }} ---- -{% if loki_auth_enabled is defined %} -auth_enabled: {{ loki_auth_enabled | bool | lower }} -{% endif %} - -{% if loki_server is defined %} -server: - {{ loki_server | to_nice_yaml(indent=2) | indent(2, False) }} -{% endif -%} - -{% if loki_ingester is defined %} -ingester: - {{ loki_ingester | to_nice_yaml(indent=2) | indent(2, False) }} -{% endif -%} - -{% if loki_schema_config is defined %} -schema_config: - {{ loki_schema_config | to_nice_yaml(indent=2) | indent(2, False) }} -{% endif -%} - -{% if loki_storage_config is defined %} -storage_config: - {{ loki_storage_config | to_nice_yaml(indent=2) | indent(2, False) }} -{% endif -%} - -{% if loki_limits_config is defined %} -limits_config: - {{ loki_limits_config | to_nice_yaml(indent=2) | indent(2, False) }} -{% endif -%}