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

Commit

Permalink
Update HTTP probe to support latency distributions.
Browse files Browse the repository at this point in the history
Following screenshot shows the results in stackdriver:
http://screen/rP1kffdhvbF

ORIGINAL_AUTHOR=Manu Garg <manugarg@gmail.com>
PiperOrigin-RevId: 175875550
  • Loading branch information
manugarg committed Nov 15, 2017
1 parent d5688f6 commit 5397a37
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions probes/http/http.go
Expand Up @@ -58,18 +58,24 @@ type probeRunResult struct {
target string
total metrics.Int
success metrics.Int
latency metrics.Float
latency metrics.Value
timeouts metrics.Int
respCodes *metrics.Map
respBodies *metrics.Map
}

func newProbeRunResult(target string) probeRunResult {
return probeRunResult{
func newProbeRunResult(target string, opts *options.Options) probeRunResult {
prr := probeRunResult{
target: target,
respCodes: metrics.NewMap("code", &metrics.Int{}),
respBodies: metrics.NewMap("resp", &metrics.Int{}),
}
if opts.LatencyDist != nil {
prr.latency = opts.LatencyDist.Clone()
} else {
prr.latency = metrics.NewFloat(0)
}
return prr
}

// Metrics converts probeRunResult into a slice of the metrics that is suitable for
Expand All @@ -79,7 +85,7 @@ func (prr probeRunResult) Metrics() *metrics.EventMetrics {
return metrics.NewEventMetrics(time.Now()).
AddMetric("total", &prr.total).
AddMetric("success", &prr.success).
AddMetric("latency", &prr.latency).
AddMetric("latency", prr.latency).
AddMetric("timeouts", &prr.timeouts).
AddMetric("resp-code", prr.respCodes).
AddMetric("resp-body", prr.respBodies)
Expand Down Expand Up @@ -162,7 +168,7 @@ func (p *Probe) runProbe(resultsChan chan<- probeutils.ProbeResult) {
// Write probe results to the "stats" channel.
go func(target string, resultsChan chan<- probeutils.ProbeResult) {
defer wg.Done()
result := newProbeRunResult(target)
result := newProbeRunResult(target, p.opts)

// Prepare HTTP.Request for Client.Do
host := target
Expand Down

0 comments on commit 5397a37

Please sign in to comment.