Skip to content

Commit

Permalink
Delay init of http phase values (#865)
Browse files Browse the repository at this point in the history
Don't init http probe phase labels until we're ready to send the
request.

Avoids exposing 0 value samples for things we haven't started to
measure.

Fix http resolve timing to report lookup time even if it's an error
(ie not found).

Fixes: #579

Signed-off-by: SuperQ <superq@gmail.com>
  • Loading branch information
SuperQ authored Feb 17, 2022
1 parent 4240a3a commit 1b883bf
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions prober/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,6 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
})
)

for _, lv := range []string{"resolve", "connect", "tls", "processing", "transfer"} {
durationGaugeVec.WithLabelValues(lv)
}

registry.MustRegister(durationGaugeVec)
registry.MustRegister(contentLengthGauge)
registry.MustRegister(bodyUncompressedLengthGauge)
Expand All @@ -336,11 +332,11 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
targetPort := targetURL.Port()

ip, lookupTime, err := chooseProtocol(ctx, module.HTTP.IPProtocol, module.HTTP.IPProtocolFallback, targetHost, registry, logger)
durationGaugeVec.WithLabelValues("resolve").Add(lookupTime)
if err != nil {
level.Error(logger).Log("msg", "Error resolving address", "err", err)
return false
}
durationGaugeVec.WithLabelValues("resolve").Add(lookupTime)

httpClientConfig := module.HTTP.HTTPClientConfig
if len(httpClientConfig.TLSConfig.ServerName) == 0 {
Expand Down Expand Up @@ -450,6 +446,10 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
}
request = request.WithContext(httptrace.WithClientTrace(request.Context(), trace))

for _, lv := range []string{"connect", "tls", "processing", "transfer"} {
durationGaugeVec.WithLabelValues(lv)
}

resp, err := client.Do(request)
// This is different from the usual err != nil you'd expect here because err won't be nil if redirects were
// turned off. See https://github.com/golang/go/issues/3795
Expand Down

0 comments on commit 1b883bf

Please sign in to comment.