Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions test/extended/router/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,29 @@ var _ = g.Describe("[sig-network][Feature:Router]", func() {
times := 10
p := expfmt.NewTextParser(model.LegacyValidation)

// The HAProxy exporter has a scrape interval (typically 5s), so
// per-route backend metrics may lag behind server-level metrics.
// Wait until all route-specific metrics are populated in the same
// scrape before exiting the retry loop.
err = wait.PollImmediate(2*time.Second, 240*time.Second, func() (bool, error) {
results, err = prometheus.GetBearerTokenURLViaPod(oc, execPodName, fmt.Sprintf("http://%s/metrics", net.JoinHostPort(host, strconv.Itoa(int(metricsPort)))), bearerToken)
o.Expect(err).NotTo(o.HaveOccurred())
metrics, err = p.TextToMetricFamilies(bytes.NewBufferString(results))
o.Expect(err).NotTo(o.HaveOccurred())

if len(findNonZeroGaugesWithLabels(metrics["haproxy_server_up"], serverLabels)) == 2 {
if g := findGaugesWithLabels(metrics["haproxy_backend_connections_total"], routeLabels); len(g) > 0 {
// stop retrying if the route got expected number of connections.
if g[0] >= float64(times) {
backendConns := findGaugesWithLabels(metrics["haproxy_backend_connections_total"], routeLabels)
if len(backendConns) > 0 && backendConns[0] >= float64(times) {
// Also verify that the HTTP response metrics have been
// populated for this route before exiting the loop.
// The exporter may not refresh all stats atomically, so
Comment on lines +175 to +179

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we do it step by step and handle whenever necessary? Like this we can say it about every single metric. No?

// backend_connections_total can appear before
// server_http_responses_total is populated.
if len(findNonZeroGaugesWithLabels(metrics["haproxy_server_http_responses_total"], serverLabels.With("code", "2xx"))) == 2 {
return true, nil
}
g.By("retrying metrics until all per-route stats are populated")
return false, nil
}
// send a burst of traffic to the router
g.By("sending traffic to a weighted route")
Expand Down