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

Commit

Permalink
Rename sent/rcvd/rtt variables to total/success/latency.
Browse files Browse the repository at this point in the history
ORIGINAL_AUTHOR=Manu Garg <[email protected]>
PiperOrigin-RevId: 164995016
  • Loading branch information
manugarg committed Aug 11, 2017
1 parent 0d68b0d commit b28dce8
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 46 deletions.
20 changes: 10 additions & 10 deletions probes/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ type Probe struct {
// types instead of metrics.AtomicInt.
type probeRunResult struct {
target string
sent metrics.Int
rcvd metrics.Int
rtt metrics.Int // microseconds
total metrics.Int
success metrics.Int
latency metrics.Int // microseconds
timeouts metrics.Int
}

Expand All @@ -90,9 +90,9 @@ func newProbeRunResult(target string) probeRunResult {
// Metrics converts probeRunResult into metrics.EventMetrics object
func (prr probeRunResult) Metrics() *metrics.EventMetrics {
return metrics.NewEventMetrics(time.Now()).
AddMetric("sent", &prr.sent).
AddMetric("rcvd", &prr.rcvd).
AddMetric("rtt", &prr.rtt).
AddMetric("total", &prr.total).
AddMetric("success", &prr.success).
AddMetric("latency", &prr.latency).
AddMetric("timeouts", &prr.timeouts)
}

Expand Down Expand Up @@ -161,8 +161,8 @@ func (p *Probe) runProbe(resultsChan chan<- probeutils.ProbeResult) {
// Verified that each request will use different UDP ports.

fullTarget := net.JoinHostPort(target, "53")
result.sent.Inc()
resp, rtt, err := p.client.Exchange(p.msg, fullTarget)
result.total.Inc()
resp, latency, err := p.client.Exchange(p.msg, fullTarget)

if err != nil {
if isClientTimeout(err) {
Expand All @@ -175,8 +175,8 @@ func (p *Probe) runProbe(resultsChan chan<- probeutils.ProbeResult) {
if resp == nil {
p.l.Warningf("Target(%s): Response is nil, but error is also nil", fullTarget)
}
result.rcvd.Inc()
result.rtt.IncBy(metrics.NewInt(rtt.Nanoseconds() / 1000))
result.success.Inc()
result.latency.IncBy(metrics.NewInt(latency.Nanoseconds() / 1000))
}

resultsChan <- result
Expand Down
8 changes: 4 additions & 4 deletions probes/dns/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ func TestRun(t *testing.T) {

// Strings that should be in all targets' output.
reqStrs := map[string]int64{
"sent": 1,
"rcvd": 1,
"total": 1,
"success": 1,
}

// The resultsChan output iterates through p.targets in the same order.
for _, target := range p.targets {
r := <-resultsChan
result := r.(probeRunResult)
if result.sent.Int64() != reqStrs["sent"] || result.rcvd.Int64() != reqStrs["rcvd"] {
t.Errorf("Mismatch got (sent, rcvd) = (%d, %d), want (%d, %d)", result.sent.Int64(), result.rcvd.Int64(), reqStrs["sent"], reqStrs["rcvd"])
if result.total.Int64() != reqStrs["total"] || result.success.Int64() != reqStrs["success"] {
t.Errorf("Mismatch got (total, success) = (%d, %d), want (%d, %d)", result.total.Int64(), result.success.Int64(), reqStrs["total"], reqStrs["success"])
}
if result.Target() != target {
t.Errorf("Unexpected target in probe result. Got: %s, Expected: %s", result.Target(), target)
Expand Down
20 changes: 10 additions & 10 deletions probes/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ type Probe struct {
// probeRunResult implements the probeutils.ProbeResult interface.
type probeRunResult struct {
target string
sent metrics.Int
rcvd metrics.Int
rtt metrics.Int // microseconds
total metrics.Int
success metrics.Int
latency metrics.Int // microseconds
timeouts metrics.Int
respCodes *metrics.Map
respBodies *metrics.Map
Expand All @@ -79,9 +79,9 @@ func newProbeRunResult(target string) probeRunResult {
// interface.
func (prr probeRunResult) Metrics() *metrics.EventMetrics {
return metrics.NewEventMetrics(time.Now()).
AddMetric("sent", &prr.sent).
AddMetric("rcvd", &prr.rcvd).
AddMetric("rtt", &prr.rtt).
AddMetric("total", &prr.total).
AddMetric("success", &prr.success).
AddMetric("latency", &prr.latency).
AddMetric("timeouts", &prr.timeouts).
AddMetric("resp-code", prr.respCodes).
AddMetric("resp-body", prr.respBodies)
Expand Down Expand Up @@ -193,9 +193,9 @@ func (p *Probe) runProbe(resultsChan chan<- probeutils.ProbeResult) {

for i := 0; i < int(p.c.GetRequestsPerProbe()); i++ {
start := time.Now()
result.sent.Inc()
result.total.Inc()
resp, err := p.client.Do(req)
rtt := time.Since(start)
latency := time.Since(start)

if err != nil {
if isClientTimeout(err) {
Expand All @@ -212,8 +212,8 @@ func (p *Probe) runProbe(resultsChan chan<- probeutils.ProbeResult) {
// Calling Body.Close() allows the TCP connection to be reused.
resp.Body.Close()
result.respCodes.IncKey(fmt.Sprintf("%d", resp.StatusCode))
result.rcvd.Inc()
result.rtt.IncBy(metrics.NewInt(rtt.Nanoseconds() / 1000))
result.success.Inc()
result.latency.IncBy(metrics.NewInt(latency.Nanoseconds() / 1000))
if p.c.GetExportResponseAsMetrics() {
if len(respBody) <= maxResponseSizeForMetrics {
result.respBodies.IncKey(string(respBody))
Expand Down
8 changes: 4 additions & 4 deletions probes/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ func TestRun(t *testing.T) {

// Strings that should be in all targets' output.
reqStrs := map[string]int64{
"sent": 1,
"rcvd": 1,
"total": 1,
"success": 1,
}

// The resultsChan output iterates through p.targets in the same order.
for _, target := range p.targets {
r := <-resultsChan
result := r.(probeRunResult)
if result.sent.Int64() != reqStrs["sent"] || result.rcvd.Int64() != reqStrs["rcvd"] {
t.Errorf("Mismatch got (sent, rcvd) = (%d, %d), want (%d, %d)", result.sent.Int64(), result.rcvd.Int64(), reqStrs["sent"], reqStrs["rcvd"])
if result.total.Int64() != reqStrs["total"] || result.success.Int64() != reqStrs["success"] {
t.Errorf("Mismatch got (total, success) = (%d, %d), want (%d, %d)", result.total.Int64(), result.success.Int64(), reqStrs["total"], reqStrs["success"])
}
if result.Target() != target {
t.Errorf("Unexpected target in probe result. Got: %s, Expected: %s", result.Target(), target)
Expand Down
6 changes: 3 additions & 3 deletions probes/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,9 @@ func (p *Probe) Start(ctx context.Context, dataChan chan *metrics.EventMetrics)
}
for _, t := range p.targets {
em := metrics.NewEventMetrics(ts).
AddMetric("sent", metrics.NewInt(p.sent[t])).
AddMetric("rcvd", metrics.NewInt(p.received[t])).
AddMetric("rtt", metrics.NewInt(p.latencyUsec[t])).
AddMetric("total", metrics.NewInt(p.sent[t])).
AddMetric("success", metrics.NewInt(p.received[t])).
AddMetric("latency", metrics.NewInt(p.latencyUsec[t])).
AddLabel("ptype", "ping").
AddLabel("probe", p.name).
AddLabel("dst", t)
Expand Down
30 changes: 15 additions & 15 deletions probes/udp/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ type Probe struct {
// types instead of metrics.AtomicInt.
type probeRunResult struct {
target string
sent metrics.Int
rcvd metrics.Int
rtt metrics.Int // microseconds
total metrics.Int
success metrics.Int
latency metrics.Int // microseconds
timeouts metrics.Int
}

Expand All @@ -75,9 +75,9 @@ func (prr probeRunResult) Target() string {
// Metrics converts probeRunResult into metrics.EventMetrics object
func (prr probeRunResult) Metrics() *metrics.EventMetrics {
return metrics.NewEventMetrics(time.Now()).
AddMetric("sent", &prr.sent).
AddMetric("rcvd", &prr.rcvd).
AddMetric("rtt", &prr.rtt).
AddMetric("total", &prr.total).
AddMetric("success", &prr.success).
AddMetric("latency", &prr.latency).
AddMetric("timeouts", &prr.timeouts)
}

Expand Down Expand Up @@ -110,10 +110,10 @@ func isClientTimeout(err error) bool {

// Ping sends a UDP "ping" to addr. Probe succeeds if the same data is returned within timeout.
// TODO: Hide this once b/32340835 is fixed, that is, once nobody using it anymore.
func Ping(addr string, timeout time.Duration) (success bool, rtt time.Duration, err error) {
func Ping(addr string, timeout time.Duration) (success bool, latency time.Duration, err error) {
conn, err := net.DialTimeout("udp", addr, timeout)
if err != nil {
return false, rtt, err
return false, latency, err
}

defer conn.Close()
Expand All @@ -122,18 +122,18 @@ func Ping(addr string, timeout time.Duration) (success bool, rtt time.Duration,
conn.SetWriteDeadline(t.Add(timeout))
sendData := []byte(t.Format(time.RFC3339Nano))
if _, err = conn.Write(sendData); err != nil {
return false, rtt, err
return false, latency, err
}

conn.SetReadDeadline(time.Now().Add(timeout))

b := make([]byte, 1024)
n, err := conn.Read(b)
rtt = time.Since(t)
latency = time.Since(t)

success = bytes.Equal(b[:n], sendData)

return success, rtt, err
return success, latency, err
}

// runProbe performs a single probe run. The main thread launches one goroutine
Expand Down Expand Up @@ -163,8 +163,8 @@ func (p *Probe) runProbe(stats chan<- probeutils.ProbeResult) {

// Verified that each request will use different UDP ports.
fullTarget := net.JoinHostPort(target, fmt.Sprintf("%d", p.c.GetPort()))
result.sent.Inc()
success, rtt, err := Ping(fullTarget, p.timeout)
result.total.Inc()
success, latency, err := Ping(fullTarget, p.timeout)

if err != nil {
if isClientTimeout(err) {
Expand All @@ -175,8 +175,8 @@ func (p *Probe) runProbe(stats chan<- probeutils.ProbeResult) {
}
} else {
if success {
result.rcvd.Inc()
result.rtt.IncBy(metrics.NewInt(rtt.Nanoseconds() / 1000))
result.success.Inc()
result.latency.IncBy(metrics.NewInt(latency.Nanoseconds() / 1000))
} else {
p.l.Warningf("Target(%s): Response is nil, but error is also nil", fullTarget)
}
Expand Down

0 comments on commit b28dce8

Please sign in to comment.