From ca634746316b05c581cb7963fc46b3b8c8525beb Mon Sep 17 00:00:00 2001 From: Per Abich Date: Mon, 24 Feb 2020 16:26:35 +0100 Subject: [PATCH] Fixing issue with collecting delays (cherry picked from commit 384943fe47c327667fbb21e5ec5ea40e048454a1) --- postfix_exporter.go | 8 ++++---- postfix_exporter_test.go | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/postfix_exporter.go b/postfix_exporter.go index 46714d7..acc553f 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -347,10 +347,10 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { } case "smtp": if smtpMatches := lmtpPipeSMTPLine.FindStringSubmatch(remainder); smtpMatches != nil { - addToHistogramVec(e.smtpDelays, smtpMatches[2], "before_queue_manager") - addToHistogramVec(e.smtpDelays, smtpMatches[3], "queue_manager") - addToHistogramVec(e.smtpDelays, smtpMatches[4], "connection_setup") - addToHistogramVec(e.smtpDelays, smtpMatches[5], "transmission") + addToHistogramVec(e.smtpDelays, smtpMatches[2], "before_queue_manager", "") + addToHistogramVec(e.smtpDelays, smtpMatches[3], "queue_manager", "") + addToHistogramVec(e.smtpDelays, smtpMatches[4], "connection_setup", "") + addToHistogramVec(e.smtpDelays, smtpMatches[5], "transmission", "") if smtpMatches := smtpStatusDeferredLine.FindStringSubmatch(remainder); smtpMatches != nil { e.smtpStatusDeferred.Inc() } diff --git a/postfix_exporter_test.go b/postfix_exporter_test.go index a56309d..67c32e4 100644 --- a/postfix_exporter_test.go +++ b/postfix_exporter_test.go @@ -152,6 +152,21 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { smtpTLSConnects: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"Verified", "TLSv1.2", "ECDHE-RSA-AES256-GCM-SHA384", "256", "256"}), }, }, + { + name: "Testing delays", + args: args{ + line: []string{ + "Feb 24 16:18:40 letterman postfix/smtp[59649]: 5270320179: to=, relay=mail.telia.com[81.236.60.210]:25, delay=2017, delays=0.1/2017/0.03/0.05, dsn=2.0.0, status=sent (250 2.0.0 6FVIjIMwUJwU66FVIjAEB0 mail accepted for delivery)", + }, + removedCount: 0, + saslFailedCount: 0, + outgoingTLS: 0, + smtpdMessagesProcessed: 0, + }, + fields: fields{ + smtpDelays: prometheus.NewHistogramVec(prometheus.HistogramOpts{}, []string{"stage"}), + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {