Skip to content

Commit

Permalink
fix: adapt duration log entries (#104)
Browse files Browse the repository at this point in the history
use strings as duration output, to get duration values and units in json output like it worked in versions before switch to slog

Signed-off-by: Thomas Belian <[email protected]>
  • Loading branch information
bt909 authored Oct 3, 2024
1 parent fd0f5b1 commit 7f67bcb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased / XXXX-XX-XX

* [CHANGE] adapt to slog logging which is introduced by exporter-toolkit https://github.com/bt909/imap-mailstat-exporter/pull/101
* [CHANGE] adapt duration log entries to strings for json output like versions worked before switch to slog https://github.com/bt909/imap-mailstat-exporter/pull/104

* [CHORE] update module github.com/prometheus/exporter-toolkit from v0.12.0 to v0.13.0 https://github.com/bt909/imap-mailstat-exporter/pull/101
* [CHORE] update module github.com/prometheus/client_golang to from v1.20.3 to v1.20.4 https://github.com/bt909/imap-mailstat-exporter/pull/102
Expand Down
6 changes: 3 additions & 3 deletions internal/valuecollect/valuecollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func (valuecollector *imapStatsCollector) Collect(ch chan<- prometheus.Metric) {
}
} else {
c, err = client.DialTLS(serverconnection.String(), nil)
valuecollector.logger.Info("Connection setup", "duration", time.Since(start), "address", valuecollector.configfile.Accounts[account].Mailaddress)
valuecollector.logger.Info("Connection setup", "duration", time.Since(start).String(), "address", valuecollector.configfile.Accounts[account].Mailaddress)
if err != nil {
valuecollector.logger.Error("Failed to dial server via TLS", "address", valuecollector.configfile.Accounts[account].Mailaddress, "server", valuecollector.configfile.Accounts[account].Serveraddress)
up = 0
Expand All @@ -252,7 +252,7 @@ func (valuecollector *imapStatsCollector) Collect(ch chan<- prometheus.Metric) {
up = 0
return
}
valuecollector.logger.Info("IMAP login", "duration", time.Since(startLogin), "address", valuecollector.configfile.Accounts[account].Mailaddress, "server", valuecollector.configfile.Accounts[account].Serveraddress)
valuecollector.logger.Info("IMAP login", "duration", time.Since(startLogin).String(), "address", valuecollector.configfile.Accounts[account].Mailaddress, "server", valuecollector.configfile.Accounts[account].Serveraddress)

defer c.Logout()

Expand Down Expand Up @@ -357,7 +357,7 @@ func (valuecollector *imapStatsCollector) Collect(ch chan<- prometheus.Metric) {
}
}
ch <- prometheus.MustNewConstMetric(valuecollector.fetchDuration, prometheus.GaugeValue, float64(time.Since(start).Seconds()), strings.ReplaceAll(strings.ReplaceAll(valuecollector.configfile.Accounts[account].Name, ".", "_"), " ", "_"))
valuecollector.logger.Info("Metric fetch", "duration", time.Since(start), "address", valuecollector.configfile.Accounts[account].Mailaddress)
valuecollector.logger.Info("Metric fetch", "duration", time.Since(start).String(), "address", valuecollector.configfile.Accounts[account].Mailaddress)
}(account)
}
wg.Wait()
Expand Down

0 comments on commit 7f67bcb

Please sign in to comment.