mirror of
https://github.com/mjl-/mox.git
synced 2025-07-14 09:34:36 +03:00
expose fewer internals in packages, for easier software reuse
- prometheus is now behind an interface, they aren't dependencies for the reusable components anymore. - some dependencies have been inverted: instead of packages importing a main package to get configuration, the main package now sets configuration in these packages. that means fewer internals are pulled in. - some functions now have new parameters for values that were retrieved from package "mox-".
This commit is contained in:
@ -11,24 +11,15 @@ import (
|
||||
|
||||
"golang.org/x/exp/slog"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
|
||||
"github.com/mjl-/mox/dns"
|
||||
"github.com/mjl-/mox/mlog"
|
||||
"github.com/mjl-/mox/stub"
|
||||
)
|
||||
|
||||
var xlog = mlog.New("iprev", nil)
|
||||
|
||||
var (
|
||||
metricIPRev = promauto.NewHistogramVec(
|
||||
prometheus.HistogramOpts{
|
||||
Name: "mox_iprev_lookup_total",
|
||||
Help: "Number of iprev lookups.",
|
||||
Buckets: []float64{0.001, 0.005, 0.01, 0.05, 0.100, 0.5, 1, 5, 10, 20, 30},
|
||||
},
|
||||
[]string{"status"},
|
||||
)
|
||||
MetricIPRev stub.HistogramVec = stub.HistogramVecIgnore{}
|
||||
)
|
||||
|
||||
// Lookup errors.
|
||||
@ -62,7 +53,7 @@ func Lookup(ctx context.Context, resolver dns.Resolver, ip net.IP) (rstatus Stat
|
||||
log := xlog.WithContext(ctx)
|
||||
start := time.Now()
|
||||
defer func() {
|
||||
metricIPRev.WithLabelValues(string(rstatus)).Observe(float64(time.Since(start)) / float64(time.Second))
|
||||
MetricIPRev.ObserveLabels(float64(time.Since(start))/float64(time.Second), string(rstatus))
|
||||
log.Debugx("iprev lookup result", rerr,
|
||||
slog.Any("ip", ip),
|
||||
slog.Any("status", rstatus),
|
||||
|
Reference in New Issue
Block a user