From 3df0a61181719eb92312de6964e0742979db8ca2 Mon Sep 17 00:00:00 2001
From: Florian Sesser <florian@private.storage>
Date: Sat, 3 Sep 2022 08:29:12 +0000
Subject: [PATCH] Monitoring: Tahoe CAs via Loki: Try to get timestamps from
 filenames

I hoped if I set correct timestamps from the RFC3339-like one
we have in the CAs' filenames, the problem of Loki being somehow
overwhelmed and presenting me all and every tahoe corruption advisory
for any time I ask would maybe go away.
But I can't even get the timestamp parsing to run, and Loki misbehaves
in so many ways, I'll just drop the effort of scraping tahoe CAs
with Promtail/Loki alltogether.
---
 morph/lib/storage.nix | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/morph/lib/storage.nix b/morph/lib/storage.nix
index dc7e6c61..8b0b35db 100644
--- a/morph/lib/storage.nix
+++ b/morph/lib/storage.nix
@@ -51,15 +51,26 @@ in {
       promtail.extraScrapeConfigs = [
         {
           job_name = "tahoe-corruption-advisories";
-          static_configs = [
-            {
-              labels = {
-                job = "tahoe-corruption-advisories";
-                host = config.networking.hostName;
-                __path__ = "/storage/corruption-advisories/*";
-              };
-            }
-          ];
+          static_configs = [{
+            labels = {
+              job = "tahoe-corruption-advisories";
+              host = config.networking.hostName;
+              __path__ = "/storage/corruption-advisories/*";
+            };
+          }];
+          relabel_configs = [{
+            source_labels = [ "filename" ];
+            regex = "/storage/corruption-advisories/(.{24}).*";
+            target_label = "filename_timestamp";
+          }];
+          pipeline_stages = [{
+            timestamp = {
+              # Example: 2021-08-02T160728.654321--xyz123abc321xyz123abc321xy-4
+              # i.e. not quite RFC3339Nano
+              source = "filename_timestamp";
+              format = "2006-01-02T150405.999999";
+            };
+          }];
         }
       ];
     };
-- 
GitLab