Skip to content
This repository has been archived by the owner on Nov 5, 2021. It is now read-only.

Commit

Permalink
Ping probe: Update results map even for the targets that don't resolve.
Browse files Browse the repository at this point in the history
Earlier we were skipping updating any target specific data structure if target fails to resolve. We should update the results map regardless of wether target resolves or not.

See #264 for more details.

PiperOrigin-RevId: 259473838
  • Loading branch information
manugarg committed Jul 23, 2019
1 parent ab329ec commit d60aac9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
45 changes: 27 additions & 18 deletions probes/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ func (p *Probe) initInternal() error {
p.ipVer = p.opts.IPVersion
}

p.targets = p.opts.Targets.List()
p.results = make(map[string]*result)
p.ip2target = make(map[[16]byte]string)
p.target2addr = make(map[string]net.Addr)
Expand All @@ -154,6 +153,9 @@ func (p *Probe) initInternal() error {
p.source = p.opts.SourceIP.String()
}

// Update targets run peiodically as well.
p.updateTargets()

return nil
}

Expand Down Expand Up @@ -197,8 +199,13 @@ func (p *Probe) listen() error {
return err
}

func (p *Probe) resolveTargets() {
func (p *Probe) updateTargets() {
p.targets = p.opts.Targets.List()

for _, t := range p.targets {
// Update results map:
p.updateResultForTarget(t)

ip, err := p.opts.Targets.Resolve(t, p.ipVer)
if err != nil {
p.l.Warning("Bad target: ", t, ". Err: ", err.Error())
Expand All @@ -213,21 +220,24 @@ func (p *Probe) resolveTargets() {
}
p.target2addr[t] = a
p.ip2target[ipToKey(ip)] = t
}
}

// Update results map:
if _, ok := p.results[t]; ok {
continue
}
var latencyValue metrics.Value
if p.opts.LatencyDist != nil {
latencyValue = p.opts.LatencyDist.Clone()
} else {
latencyValue = metrics.NewFloat(0)
}
p.results[t] = &result{
latency: latencyValue,
validationFailure: validators.ValidationFailureMap(p.opts.Validators),
}
func (p *Probe) updateResultForTarget(t string) {
if _, ok := p.results[t]; ok {
return
}

var latencyValue metrics.Value
if p.opts.LatencyDist != nil {
latencyValue = p.opts.LatencyDist.Clone()
} else {
latencyValue = metrics.NewFloat(0)
}

p.results[t] = &result{
latency: latencyValue,
validationFailure: validators.ValidationFailureMap(p.opts.Validators),
}
}

Expand Down Expand Up @@ -420,8 +430,7 @@ func (p *Probe) newRunID() uint16 {
func (p *Probe) runProbe() {
// Resolve targets if target resolve interval has elapsed.
if (p.runCnt % uint64(p.c.GetResolveTargetsInterval())) == 0 {
p.targets = p.opts.Targets.List()
p.resolveTargets()
p.updateTargets()
}
p.runCnt++
runID := p.newRunID()
Expand Down
2 changes: 0 additions & 2 deletions probes/ping/ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ func sendAndCheckPackets(p *Probe, t *testing.T) {
tic := newTestICMPConn(p.c, p.targets)
p.conn = tic
trackerChan := make(chan bool, int(p.c.GetPacketsPerProbe())*len(p.targets))
p.resolveTargets()
runID := p.newRunID()
p.sendPackets(runID, trackerChan)

Expand Down Expand Up @@ -247,7 +246,6 @@ func TestSendPacketsIPv6ToIPv4Hosts(t *testing.T) {
tic := newTestICMPConn(c, p.targets)
p.conn = tic
trackerChan := make(chan bool, int(c.GetPacketsPerProbe())*len(p.targets))
p.resolveTargets()
p.sendPackets(p.newRunID(), trackerChan)
for _, target := range p.targets {
if len(tic.sentPackets[target]) != 0 {
Expand Down

0 comments on commit d60aac9

Please sign in to comment.