From d4dbe48400f86510cb480ab02bc8f68252906de3 Mon Sep 17 00:00:00 2001 From: Diogenes Pelisson Date: Tue, 21 Apr 2020 19:54:44 -0300 Subject: [PATCH] changes --- defaults/main.yml | 38 +++++++++++++++++++------------------- tasks/install.yml | 1 + tasks/preflight.yml | 14 +++++++------- templates/promtail.yml.j2 | 4 ++++ 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 287184d..a969aa0 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -17,12 +17,12 @@ loki_tags: [] loki_listen_address: 127.0.0.1 loki_listen_port: 3100 +promtail_listen_address: "{{ loki_listen_address }}" loki_binary_local_dir: '' loki_target: all -loki_auth_enabled: false - +loki_auth_enabled: 'false' loki_server_config: http_listen_address: "{{ loki_listen_address }}" http_listen_port: "{{ loki_listen_port }}" @@ -57,15 +57,19 @@ loki_schema_config: object_store: filesystem schema: v11 index: - prefix: loki + prefix: index_ period: 168h chunks: - prefix: loki + prefix: index_ period: 168h row_shards: 16 -loki_limits_config: [] +loki_limits_config: + enforce_metric_name: false + reject_old_samples: true + reject_old_samples_max_age: 168h + loki_frontend_worker_config: [] loki_runtime_config: [] loki_table_manager_config: @@ -87,27 +91,23 @@ promtail_client_config: - url: "http://{{ loki_listen_address }}:{{ loki_listen_port }}/loki/api/v1/push" promtail_server_config: + http_listen_address: "{{ promtail_listen_address }}" http_listen_port: 9080 + grpc_listen_address: "{{ promtail_listen_address }}" grpc_listen_port: 0 promtail_scrape_config: - - job_name: system - pipeline_stages: - static_configs: - - targets: - - localhost - labels: - job: varlogs - host: "{{ ansible_hostname }}" - __path__: /var/log/*.log - - job_name: journal journal: - max_age: 12h labels: job: systemd-journal + host: "{{ ansible_hostname }}" + max_age: 12h relabel_configs: - - source_labels: ['__journal__systemd_unit'] - target_label: 'unit' + - source_labels: + - __journal__systemd_unit + target_label: unit -promtail_target_config: [] \ No newline at end of file +promtail_target_config: [] +promtail_positions_config: + filename: /tmp/positions.yaml \ No newline at end of file diff --git a/tasks/install.yml b/tasks/install.yml index 55b5168..c4f8173 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -25,6 +25,7 @@ - "{{ loki_storage_dir }}" - "{{ loki_storage_dir }}/index" - "{{ loki_storage_dir }}/chunks" + when: ('loki' in loki_bins) - name: create loki configuration directories file: diff --git a/tasks/preflight.yml b/tasks/preflight.yml index 7ee819c..549e34b 100644 --- a/tasks/preflight.yml +++ b/tasks/preflight.yml @@ -1,8 +1,8 @@ --- -# - name: Assert usage of systemd as an init system -# assert: -# that: ansible_service_mgr == 'systemd' -# msg: "This module only works with systemd" +- name: Assert usage of systemd as an init system + assert: + that: ansible_service_mgr == 'systemd' + msg: "This module only works with systemd" - block: - name: Get latest release @@ -20,7 +20,7 @@ until: _latest_release.status == 200 retries: 5 - - name: "Set loki version to {{ _latest_release.json.tag_name[1:] }}" + - name: Set loki version to {{ _latest_release.json.tag_name[1:] }} set_fact: loki_version: "{{ _latest_release.json.tag_name[1:] }}" when: @@ -28,12 +28,12 @@ - loki_binary_local_dir | length == 0 - block: - - name: "Get checksum list" + - name: Get checksum list set_fact: __loki_checksums: "{{ lookup('url', 'https://github.com/grafana/loki/releases/download/v' + loki_version + '/SHA256SUMS', wantlist=True) | list }}" run_once: true - - name: "Get checksum for {{ item[1] }} in {{ go_arch }} architecture" + - name: Get checksum for bins set_fact: __loki_bins_checksum: "{{ __loki_bins_checksum | default({}) | combine({item[1]: item[0].split()[0]}) }}" loop: "{{ lookup('nested', __loki_checksums, loki_bins, wantlist=True) }}" diff --git a/templates/promtail.yml.j2 b/templates/promtail.yml.j2 index 7d81b0b..4b0f634 100644 --- a/templates/promtail.yml.j2 +++ b/templates/promtail.yml.j2 @@ -5,6 +5,10 @@ server: {{ promtail_server_config | to_nice_yaml(indent=2) | indent(2, False) }} {% endif %} +{% if promtail_positions_config != [] %} +positions: + {{ promtail_positions_config | to_nice_yaml(indent=2) | indent(2, False) }} +{% endif %} {% if promtail_client_config != [] %} clients: {{ promtail_client_config | to_nice_yaml(indent=2) | indent(2, False) }}