Skip to content

Commit

Permalink
chore: reduce unneeded lock
Browse files Browse the repository at this point in the history
  • Loading branch information
wbollock committed Dec 11, 2023
1 parent ae96e91 commit d8c9ed4
Showing 1 changed file with 0 additions and 10 deletions.
10 changes: 0 additions & 10 deletions internal/collector/icmp_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,6 @@ func PingHandler(registry *prometheus.Registry, pingSuccessGauge prometheus.Gaug
p := parseParams(r)
start := time.Now()

// TODO use atomic lock and reduce lock duration, dont think this is needed
mutex.Lock()

// assume failure
pingSuccessGauge.Set(0)
pingTimeoutGauge.Set(1)

mutex.Unlock()

log.Debugf("Request received with parameters: target=%v, count=%v, size=%v, interval=%v, timeout=%v, ttl=%v, packet=%v",
p.target, p.count, p.size, p.interval, p.timeout, p.ttl, p.packet)

Expand Down Expand Up @@ -152,7 +143,6 @@ func PingHandler(registry *prometheus.Registry, pingSuccessGauge prometheus.Gaug
log.Debugf("OnFinish: target=%v, PacketsSent=%d, PacketsRecv=%d, PacketLoss=%f%%, MinRtt=%v, AvgRtt=%v, MaxRtt=%v, StdDevRtt=%v, Duration=%v",
stats.IPAddr, pinger.PacketsSent, pinger.PacketsRecv, stats.PacketLoss, stats.MinRtt, stats.AvgRtt, stats.MaxRtt, stats.StdDevRtt, time.Since(start))

// lock while we attribute values to
mutex.Lock()
if pinger.PacketsRecv > 0 && pinger.Timeout > time.Since(start) {
log.Debugf("Ping successful: target=%v", stats.IPAddr)
Expand Down

0 comments on commit d8c9ed4

Please sign in to comment.