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(),
LineParser: parser,
UDPPackets: udpPackets,
UDPPacketDrops: udpPacketDrops,
LinesReceived: linesReceived,
EventsFlushed: eventsFlushed,
SampleErrors: *sampleErrors,

View file

@ -71,6 +71,12 @@ var (
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(
prometheus.CounterOpts{
Name: "statsd_exporter_tcp_connections_total",
@ -377,6 +383,7 @@ func main() {
Logger: logger,
LineParser: parser,
UDPPackets: udpPackets,
UDPPacketDrops: udpPacketDrops,
LinesReceived: linesReceived,
EventsFlushed: eventsFlushed,
Relay: relayTarget,

View file

@ -56,6 +56,12 @@ var (
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(
prometheus.CounterOpts{
Name: "statsd_exporter_tcp_connections_total",
@ -683,6 +689,7 @@ func TestInvalidUtf8InDatadogTagValue(t *testing.T) {
Logger: log.NewNopLogger(),
LineParser: parser,
UDPPackets: udpPackets,
UDPPacketDrops: udpPacketDrops,
LinesReceived: linesReceived,
EventsFlushed: eventsFlushed,
SampleErrors: *sampleErrors,

View file

@ -38,6 +38,7 @@ type StatsDUDPListener struct {
Logger log.Logger
LineParser Parser
UDPPackets prometheus.Counter
UDPPacketDrops prometheus.Counter
LinesReceived prometheus.Counter
EventsFlushed prometheus.Counter
Relay *relay.Relay
@ -66,7 +67,7 @@ func (l *StatsDUDPListener) Listen() {
level.Error(l.Logger).Log("error", err)
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)
}
}
@ -75,7 +76,12 @@ func (l *StatsDUDPListener) EnqueueUdpPacket(packet []byte, n int) {
l.UDPPackets.Inc()
packetCopy := make([]byte, n)
copy(packetCopy, packet)
l.UdpPacketQueue <- packetCopy
select {
case l.UdpPacketQueue <- packetCopy:
// do nothing
default:
l.UDPPacketDrops.Inc()
}
}
func (l *StatsDUDPListener) ProcessUdpPacketQueue() {