From 709c0da81b6a56204181ea69375d15ce5a4a4466 Mon Sep 17 00:00:00 2001 From: bakins Date: Thu, 10 Dec 2020 13:12:42 -0500 Subject: [PATCH] Use a Parser interface to allow alternate implementations Signed-off-by: bakins --- pkg/listener/listener.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/listener/listener.go b/pkg/listener/listener.go index 0607180..0da8072 100644 --- a/pkg/listener/listener.go +++ b/pkg/listener/listener.go @@ -23,15 +23,19 @@ import ( "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/statsd_exporter/pkg/event" - pkgLine "github.com/prometheus/statsd_exporter/pkg/line" ) +type Parser interface { + LineToEvents(line string, sampleErrors prometheus.CounterVec, samplesReceived prometheus.Counter, tagErrors prometheus.Counter, tagsReceived prometheus.Counter, logger log.Logger) event.Events +} + type StatsDUDPListener struct { Conn *net.UDPConn EventHandler event.EventHandler Logger log.Logger - LineParser *pkgLine.Parser + LineParser Parser UDPPackets prometheus.Counter LinesReceived prometheus.Counter EventsFlushed prometheus.Counter @@ -76,7 +80,7 @@ type StatsDTCPListener struct { Conn *net.TCPListener EventHandler event.EventHandler Logger log.Logger - LineParser *pkgLine.Parser + LineParser Parser LinesReceived prometheus.Counter EventsFlushed prometheus.Counter SampleErrors prometheus.CounterVec @@ -138,7 +142,7 @@ type StatsDUnixgramListener struct { Conn *net.UnixConn EventHandler event.EventHandler Logger log.Logger - LineParser *pkgLine.Parser + LineParser Parser UnixgramPackets prometheus.Counter LinesReceived prometheus.Counter EventsFlushed prometheus.Counter