From 237dd1d4f38faa724faee3dee1e45286430bf437 Mon Sep 17 00:00:00 2001 From: Antal Nemes Date: Thu, 25 Apr 2024 10:45:28 +0200 Subject: [PATCH] ignore orphaned counters The purpose of this module is to expose metrics for prometheus. As such, we are building time series from the counters. This means we should not expose metrics that do not exist anymore: configured out from syslog-ng and reloaded. This patch filters out orphan counters. Signed-off-by: Antal Nemes --- pkg/syslog-ng-ctl/stats.go | 19 +++++++++++-------- pkg/syslog-ng-ctl/stats_test.go | 12 ++++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/pkg/syslog-ng-ctl/stats.go b/pkg/syslog-ng-ctl/stats.go index 658a754..e0da51c 100644 --- a/pkg/syslog-ng-ctl/stats.go +++ b/pkg/syslog-ng-ctl/stats.go @@ -76,14 +76,17 @@ func parseStats(rsp string) (stats []Stat, errs error) { errs = errors.Join(errs, err) continue } - stats = append(stats, Stat{ - SourceName: fields[0], - SourceID: fields[1], - SourceInstance: fields[2], - SourceState: SourceState(fields[3][0]), - Type: fields[4], - Number: num, - }) + + if fields[3] != string(SourceStateOrphaned) { + stats = append(stats, Stat{ + SourceName: fields[0], + SourceID: fields[1], + SourceInstance: fields[2], + SourceState: SourceState(fields[3][0]), + Type: fields[4], + Number: num, + }) + } } return } diff --git a/pkg/syslog-ng-ctl/stats_test.go b/pkg/syslog-ng-ctl/stats_test.go index 198a913..c7edb57 100644 --- a/pkg/syslog-ng-ctl/stats_test.go +++ b/pkg/syslog-ng-ctl/stats_test.go @@ -56,6 +56,18 @@ src.internal;s_src#1;;a;processed;59 src.internal;s_src#1;;a;stamp;1673105444 destination;d_newserr;;a;processed;0 global;scratch_buffers_bytes;;a;queued;0 +dst.network;#anon-destination0#0;tcp,localhost:1234;o;eps_last_1h;0 +dst.network;#anon-destination0#0;tcp,localhost:1234;o;eps_last_24h;0 +dst.network;#anon-destination0#0;tcp,localhost:1234;o;dropped;0 +dst.network;#anon-destination0#0;tcp,localhost:1234;o;processed;0 +dst.network;#anon-destination0#0;tcp,localhost:1234;o;queued;0 +dst.network;#anon-destination0#0;tcp,localhost:1234;o;memory_usage;0 +dst.network;#anon-destination0#0;tcp,localhost:1234;o;written;0 +dst.network;#anon-destination0#0;tcp,localhost:1234;o;truncated_bytes;0 +dst.network;#anon-destination0#0;tcp,localhost:1234;o;eps_since_start;0 +dst.network;#anon-destination0#0;tcp,localhost:1234;o;msg_size_max;0 +dst.network;#anon-destination0#0;tcp,localhost:1234;o;truncated_count;0 +dst.network;#anon-destination0#0;tcp,localhost:1234;o;msg_size_avg;0 . ` expected := []Stat{