From c0382b7a5ae2e59a0b7c615dcae8ba1ed54eed38 Mon Sep 17 00:00:00 2001 From: Luca Bello <36242061+lucabello@users.noreply.github.com> Date: Fri, 6 Dec 2024 17:05:30 +0100 Subject: [PATCH] feat: add exclude-list for logs in /var/log (#216) * feat: add exclude-list for logs in /var/log * improve config option docs * improve config option docs * rename exclude_files to path_exclude --- charmcraft.yaml | 14 ++++++++++++++ src/charm.py | 1 + 2 files changed, 15 insertions(+) diff --git a/charmcraft.yaml b/charmcraft.yaml index 7354293..be52eb4 100644 --- a/charmcraft.yaml +++ b/charmcraft.yaml @@ -210,3 +210,17 @@ config: Ref: https://grafana.com/docs/agent/latest/static/configuration/flags/#report-information-usage type: boolean default: true + path_exclude: + description: > + Glob for a set of log files present in `/var/log` that should be ignored by Grafana Agent. + + For example, `/var/log/**/{app_one,app_two}.log` will result in the agent ignoring both + `/var/log/app_one.log` and `/var/log/app_two.log`. + + Note that the value you provide here is not interpreted as a path, but rather as a glob matcher. + Specifically, if you want to exclude logs in the `/var/log/test` folder, you should set the + config to `/var/log/test/**`. + + Ref (__path_exclude__): https://grafana.com/docs/loki/latest/send-data/promtail/scraping/ + type: string + default: "" diff --git a/src/charm.py b/src/charm.py index 3056a2a..e59f406 100755 --- a/src/charm.py +++ b/src/charm.py @@ -474,6 +474,7 @@ def _additional_log_configs(self) -> List[Dict[str, Any]]: "targets": ["localhost"], "labels": { "__path__": "/var/log/**/*log", + "__path_exclude__": self.model.config.get("path_exclude"), "job": "varlog", **self._own_labels, },