From e477ae9d4119308907c2ecbc2c54e82f6e0ebb11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eirik=20=C3=98verby?= Date: Thu, 31 Aug 2023 17:37:16 +0200 Subject: [PATCH 1/4] Make names lowercase to avoid ballooning metrics --- collectors/names_collector.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/collectors/names_collector.go b/collectors/names_collector.go index eaa84cb..6361eee 100644 --- a/collectors/names_collector.go +++ b/collectors/names_collector.go @@ -99,9 +99,9 @@ func NewNamesCollector(namespace string, sender *chan string, matcher *util.LogM if info.Matched { totalMetric.Add(1) if config.captureClient { - namesMetric.WithLabelValues(info.QueryName, info.QueryClient).Add(1) + namesMetric.WithLabelValues(strings.ToLower(info.QueryName), info.QueryClient).Add(1) } else { - namesMetric.WithLabelValues(info.QueryName).Add(1) + namesMetric.WithLabelValues(strings.ToLower(info.QueryName)).Add(1) } } } From 029e58fdeba6de96a698f9fbe03d09004ce5174e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eirik=20=C3=98verby?= Date: Thu, 31 Aug 2023 17:39:49 +0200 Subject: [PATCH 2/4] Import strings --- collectors/names_collector.go | 1 + 1 file changed, 1 insertion(+) diff --git a/collectors/names_collector.go b/collectors/names_collector.go index 6361eee..333f940 100644 --- a/collectors/names_collector.go +++ b/collectors/names_collector.go @@ -3,6 +3,7 @@ package collectors import ( "bufio" "os" + "strings" "github.com/DRuggeri/bind_query_exporter/util" "github.com/prometheus/client_golang/prometheus" From c6b028754ee868247043d4e5b2f7d0b1f016bd5f Mon Sep 17 00:00:00 2001 From: ltning Date: Fri, 1 Sep 2023 11:10:18 +0000 Subject: [PATCH 3/4] Move lowercasing to inc/excl file read and matching --- collectors/names_collector.go | 8 ++++---- util/LogMatcher.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/collectors/names_collector.go b/collectors/names_collector.go index 333f940..f358e43 100644 --- a/collectors/names_collector.go +++ b/collectors/names_collector.go @@ -3,7 +3,7 @@ package collectors import ( "bufio" "os" - "strings" + "strings" "github.com/DRuggeri/bind_query_exporter/util" "github.com/prometheus/client_golang/prometheus" @@ -100,9 +100,9 @@ func NewNamesCollector(namespace string, sender *chan string, matcher *util.LogM if info.Matched { totalMetric.Add(1) if config.captureClient { - namesMetric.WithLabelValues(strings.ToLower(info.QueryName), info.QueryClient).Add(1) + namesMetric.WithLabelValues(info.QueryName, info.QueryClient).Add(1) } else { - namesMetric.WithLabelValues(strings.ToLower(info.QueryName)).Add(1) + namesMetric.WithLabelValues(info.QueryName).Add(1) } } } @@ -127,7 +127,7 @@ func makeList(fileName string) (map[string]bool, error) { scanner := bufio.NewScanner(file) for scanner.Scan() { log.Debugln(" ", scanner.Text()) - result[scanner.Text()] = true + result[strings.ToLower(scanner.Text())] = true } if err := scanner.Err(); err != nil { diff --git a/util/LogMatcher.go b/util/LogMatcher.go index f1c269a..1a0fa7b 100644 --- a/util/LogMatcher.go +++ b/util/LogMatcher.go @@ -41,7 +41,7 @@ func (m LogMatcher) ExtractInfo(line string) LogMatch { if len(match) > 0 { result.Matched = true result.QueryClient = match[1] - result.QueryName = match[2] + result.QueryName = strings.ToLower(match[2]) result.QueryType = match[3] /* Check if we should avoid a DNS lookup since this name is not From d181a7303d6203dfd72fc339d7242c9f56fb0b5e Mon Sep 17 00:00:00 2001 From: ltning Date: Fri, 1 Sep 2023 11:11:26 +0000 Subject: [PATCH 4/4] Whitespace fix --- collectors/names_collector.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collectors/names_collector.go b/collectors/names_collector.go index f358e43..fb481e8 100644 --- a/collectors/names_collector.go +++ b/collectors/names_collector.go @@ -3,7 +3,7 @@ package collectors import ( "bufio" "os" - "strings" + "strings" "github.com/DRuggeri/bind_query_exporter/util" "github.com/prometheus/client_golang/prometheus"