Skip to content

Commit

Permalink
Revert "add retries to flaky metrics http test"
Browse files Browse the repository at this point in the history
This reverts commit ad8ab82.
  • Loading branch information
jackgopack4 committed Nov 13, 2024
1 parent 2827738 commit cfce728
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions service/telemetry/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"net/http"
"testing"
"time"

io_prometheus_client "github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt"
Expand Down Expand Up @@ -202,31 +201,11 @@ func createTestMetrics(t *testing.T, mp metric.MeterProvider) {
}

func getMetricsFromPrometheus(t *testing.T, endpoint string) map[string]*io_prometheus_client.MetricFamily {
client := &http.Client{
Timeout: 10 * time.Second,
}
var (
req *http.Request
err error
rr *http.Response
)
req, err = http.NewRequest(http.MethodGet, endpoint, nil)
req, err := http.NewRequest(http.MethodGet, endpoint, nil)
require.NoError(t, err)

maxRetries := 5
for i := 0; i < maxRetries; i++ {
rr, err = client.Do(req)
if err == nil && rr.StatusCode == http.StatusOK {
break
}

if i < maxRetries-1 {
time.Sleep(2 * time.Second) // Wait before retrying
}
}
require.NoError(t, err, "failed to get metrics from Prometheus after %d attempts", maxRetries)
require.Equal(t, http.StatusOK, rr.StatusCode, "unexpected status code after %d attempts", maxRetries)
defer rr.Body.Close()
rr, err := http.DefaultClient.Do(req)
require.NoError(t, err)

var parser expfmt.TextParser
parsed, err := parser.TextToMetricFamilies(rr.Body)
Expand Down

0 comments on commit cfce728

Please sign in to comment.