diff options
-rw-r--r-- | ansible/plays/otelcol-contrib.yml | 29 | ||||
-rw-r--r-- | ansible/plays/templates/otelcol-contrib/config.yaml | 65 | ||||
-rw-r--r-- | terraform/hash-loki/loki-config.yaml | 21 | ||||
-rw-r--r-- | terraform/hash-loki/loki.tf | 13 | ||||
-rw-r--r-- | terraform/hash-loki/main.tf | 4 |
5 files changed, 130 insertions, 2 deletions
diff --git a/ansible/plays/otelcol-contrib.yml b/ansible/plays/otelcol-contrib.yml new file mode 100644 index 0000000..f667337 --- /dev/null +++ b/ansible/plays/otelcol-contrib.yml @@ -0,0 +1,29 @@ +- hosts: + - coregonus + - hash + - knot + tasks: + + # otelcol-contrib.deb needs to be installed first + # adduser otelcol-contrib systemd-journal + + - name: /etc/otelcol-contrib/config.yaml + become: yes + template: + src: otelcol-contrib/config.yaml + dest: /etc/otelcol-contrib/config.yaml + notify: systemctl restart otelcol-contrib + + - name: mkdir /var/lib/otelcol/file_storage + become: yes + file: + path: /var/lib/otelcol/file_storage + owner: otelcol-contrib + notify: systemctl restart otelcol-contrib + + handlers: + - name: systemctl restart otelcol-contrib + become: yes + systemd: + service: otelcol-contrib + state: restarted diff --git a/ansible/plays/templates/otelcol-contrib/config.yaml b/ansible/plays/templates/otelcol-contrib/config.yaml new file mode 100644 index 0000000..671dbaa --- /dev/null +++ b/ansible/plays/templates/otelcol-contrib/config.yaml @@ -0,0 +1,65 @@ +receivers: + journald: + priority: debug + +exporters: + debug: + verbosity: detailed + + nop: + + otlphttp/hash: + endpoint: https://loki.trygvis.io/otlp + +extensions: + file_storage/journald: + +processors: + batch: {} + + transform/severity_parse: + log_statements: + - context: log + statements: + - set(resource.attributes["service.namespace"], "systemd") + - set(resource.attributes["service.name"], body["_SYSTEMD_UNIT"]) + - set(resource.attributes["systemd_unit"], body["_SYSTEMD_UNIT"]) + - set(resource.attributes["systemd_slice"], body["_SYSTEMD_SLICE"]) + - set(resource.attributes["node"], body["_HOSTNAME"]) + + - set(severity_number, SEVERITY_NUMBER_TRACE) where body["PRIORITY"] == "7" + - set(severity_text, "debug") where body["PRIORITY"] == "7" + - set(severity_number, SEVERITY_NUMBER_DEBUG) where body["PRIORITY"] == "6" + - set(severity_text, "info") where body["PRIORITY"] == "6" + - set(severity_number, SEVERITY_NUMBER_INFO) where body["PRIORITY"] == "5" + - set(severity_text, "notice") where body["PRIORITY"] == "5" + - set(severity_number, SEVERITY_NUMBER_WARN) where body["PRIORITY"] == "4" + - set(severity_text, "warning") where body["PRIORITY"] == "4" + - set(severity_number, SEVERITY_NUMBER_ERROR) where body["PRIORITY"] == "3" + - set(severity_text, "err") where body["PRIORITY"] == "3" + - set(severity_number, SEVERITY_NUMBER_FATAL) where body["PRIORITY"] == "2" + - set(severity_text, "crit") where body["PRIORITY"] == "2" + - set(severity_number, SEVERITY_NUMBER_FATAL) where body["PRIORITY"] == "1" + - set(severity_text, "alert") where body["PRIORITY"] == "1" + - set(severity_number, SEVERITY_NUMBER_FATAL) where body["PRIORITY"] == "0" + - set(severity_text, "emerg") where body["PRIORITY"] == "0" + + - set(body, body["MESSAGE"]) + +service: +# telemetry: +# logs: +# level: debug + extensions: + - file_storage/journald + pipelines: + logs: + receivers: + - journald + processors: + - transform/severity_parse + - batch + exporters: +# - debug +# - nop + - otlphttp/hash diff --git a/terraform/hash-loki/loki-config.yaml b/terraform/hash-loki/loki-config.yaml index d21d405..72e68b0 100644 --- a/terraform/hash-loki/loki-config.yaml +++ b/terraform/hash-loki/loki-config.yaml @@ -50,3 +50,24 @@ ruler: # If you would like to disable reporting, uncomment the following lines: analytics: reporting_enabled: false + +distributor: + otlp_config: + default_resource_attributes_as_index_labels: + - cloud.availability_zone + - cloud.region + - container.name + - deployment.environment + - k8s.cluster.name + - k8s.container.name + - k8s.cronjob.name + - k8s.daemonset.name + - k8s.deployment.name + - k8s.job.name + - k8s.namespace.name + - k8s.pod.name + - k8s.replicaset.name + - k8s.statefulset.name + - service.instance.id + - service.name + - service.namespace diff --git a/terraform/hash-loki/loki.tf b/terraform/hash-loki/loki.tf index b7bb60b..1e09037 100644 --- a/terraform/hash-loki/loki.tf +++ b/terraform/hash-loki/loki.tf @@ -1,5 +1,5 @@ resource "docker_image" "loki" { - name = "grafana/loki:3.2.1" + name = "grafana/loki:3.3.0" } resource "docker_volume" "loki" { @@ -12,6 +12,10 @@ resource "docker_container" "loki" { privileged = false must_run = true + command = [ + "-config.file=${local.container_config_dir}/loki-config.yaml" + ] + network_mode = "bridge" networks_advanced { @@ -39,6 +43,13 @@ resource "docker_container" "loki" { env = [ ] + mounts { + source = local.host_config_dir + target = local.container_config_dir + type = "bind" + read_only = false + } + volumes { volume_name = docker_volume.loki.name container_path = "/loki" diff --git a/terraform/hash-loki/main.tf b/terraform/hash-loki/main.tf index a393467..7f00e45 100644 --- a/terraform/hash-loki/main.tf +++ b/terraform/hash-loki/main.tf @@ -20,7 +20,9 @@ terraform { } locals { - host = "hash.trygvis.io" + host = "hash.trygvis.io" + host_config_dir = "/etc/docker-service/loki" + container_config_dir = "/config" } provider "docker" { |