add counter for dropped UDP packets. Remove unnecessary and misleading comment

Signed-off-by: kullanici0606 <yakup.turgut@btk.gov.tr>
This commit is contained in:
kullanici0606 2023-10-23 10:00:25 +03:00
parent aaaf26c074
commit c246633aec
4 changed files with 23 additions and 2 deletions

View file

@ -543,6 +543,7 @@ func TestHandlePacket(t *testing.T) {
Logger: log.NewNopLogger(), Logger: log.NewNopLogger(),
LineParser: parser, LineParser: parser,
UDPPackets: udpPackets, UDPPackets: udpPackets,
UDPPacketDrops: udpPacketDrops,
LinesReceived: linesReceived, LinesReceived: linesReceived,
EventsFlushed: eventsFlushed, EventsFlushed: eventsFlushed,
SampleErrors: *sampleErrors, SampleErrors: *sampleErrors,

View file

@ -71,6 +71,12 @@ var (
Help: "The total number of StatsD packets received over UDP.", Help: "The total number of StatsD packets received over UDP.",
}, },
) )
udpPacketDrops = promauto.NewCounter(
prometheus.CounterOpts{
Name: "statsd_exporter_udp_packet_drops_total",
Help: "The total number of dropped StatsD packets which received over UDP.",
},
)
tcpConnections = promauto.NewCounter( tcpConnections = promauto.NewCounter(
prometheus.CounterOpts{ prometheus.CounterOpts{
Name: "statsd_exporter_tcp_connections_total", Name: "statsd_exporter_tcp_connections_total",
@ -377,6 +383,7 @@ func main() {
Logger: logger, Logger: logger,
LineParser: parser, LineParser: parser,
UDPPackets: udpPackets, UDPPackets: udpPackets,
UDPPacketDrops: udpPacketDrops,
LinesReceived: linesReceived, LinesReceived: linesReceived,
EventsFlushed: eventsFlushed, EventsFlushed: eventsFlushed,
Relay: relayTarget, Relay: relayTarget,

View file

@ -56,6 +56,12 @@ var (
Help: "The total number of StatsD packets received over UDP.", Help: "The total number of StatsD packets received over UDP.",
}, },
) )
udpPacketDrops = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "statsd_exporter_udp_packet_drops_total",
Help: "The total number of dropped StatsD packets which received over UDP.",
},
)
tcpConnections = prometheus.NewCounter( tcpConnections = prometheus.NewCounter(
prometheus.CounterOpts{ prometheus.CounterOpts{
Name: "statsd_exporter_tcp_connections_total", Name: "statsd_exporter_tcp_connections_total",
@ -683,6 +689,7 @@ func TestInvalidUtf8InDatadogTagValue(t *testing.T) {
Logger: log.NewNopLogger(), Logger: log.NewNopLogger(),
LineParser: parser, LineParser: parser,
UDPPackets: udpPackets, UDPPackets: udpPackets,
UDPPacketDrops: udpPacketDrops,
LinesReceived: linesReceived, LinesReceived: linesReceived,
EventsFlushed: eventsFlushed, EventsFlushed: eventsFlushed,
SampleErrors: *sampleErrors, SampleErrors: *sampleErrors,

View file

@ -38,6 +38,7 @@ type StatsDUDPListener struct {
Logger log.Logger Logger log.Logger
LineParser Parser LineParser Parser
UDPPackets prometheus.Counter UDPPackets prometheus.Counter
UDPPacketDrops prometheus.Counter
LinesReceived prometheus.Counter LinesReceived prometheus.Counter
EventsFlushed prometheus.Counter EventsFlushed prometheus.Counter
Relay *relay.Relay Relay *relay.Relay
@ -66,7 +67,7 @@ func (l *StatsDUDPListener) Listen() {
level.Error(l.Logger).Log("error", err) level.Error(l.Logger).Log("error", err)
return return
} }
// avoid making copies of slices since we need to minimize the time spent here in order not to drop packets
l.EnqueueUdpPacket(buf, n) l.EnqueueUdpPacket(buf, n)
} }
} }
@ -75,7 +76,12 @@ func (l *StatsDUDPListener) EnqueueUdpPacket(packet []byte, n int) {
l.UDPPackets.Inc() l.UDPPackets.Inc()
packetCopy := make([]byte, n) packetCopy := make([]byte, n)
copy(packetCopy, packet) copy(packetCopy, packet)
l.UdpPacketQueue <- packetCopy select {
case l.UdpPacketQueue <- packetCopy:
// do nothing
default:
l.UDPPacketDrops.Inc()
}
} }
func (l *StatsDUDPListener) ProcessUdpPacketQueue() { func (l *StatsDUDPListener) ProcessUdpPacketQueue() {