diff --git a/tests/e2e/cmux_test.go b/tests/e2e/cmux_test.go index 4f97c2bf224e..0b059d59b0eb 100644 --- a/tests/e2e/cmux_test.go +++ b/tests/e2e/cmux_test.go @@ -21,6 +21,8 @@ import ( "context" "encoding/json" "fmt" + "os" + "path/filepath" "strings" "testing" @@ -126,7 +128,7 @@ func testConnectionMultiplexing(t *testing.T, ctx context.Context, member e2e.Et } t.Run(tname, func(t *testing.T) { assert.NoError(t, fetchGrpcGateway(httpEndpoint, httpVersion, connType)) - assert.NoError(t, fetchMetrics(httpEndpoint, httpVersion, connType)) + assert.NoError(t, fetchMetrics(t, httpEndpoint, httpVersion, connType)) assert.NoError(t, fetchVersion(httpEndpoint, httpVersion, connType)) assert.NoError(t, fetchHealth(httpEndpoint, httpVersion, connType)) assert.NoError(t, fetchDebugVars(httpEndpoint, httpVersion, connType)) @@ -168,12 +170,21 @@ func validateGrpcgatewayRangeReponse(respData []byte) error { return json.Unmarshal(respData, &resp) } -func fetchMetrics(endpoint string, httpVersion string, connType e2e.ClientConnType) error { - req := e2e.CURLReq{Endpoint: "/metrics", Timeout: 5, HttpVersion: httpVersion} - respData, err := curl(endpoint, "GET", req, connType) - if err != nil { +func fetchMetrics(t *testing.T, endpoint string, httpVersion string, connType e2e.ClientConnType) error { + tmpDir := t.TempDir() + metricFile := filepath.Join(tmpDir, "metrics") + + req := e2e.CURLReq{Endpoint: "/metrics", Timeout: 5, HttpVersion: httpVersion, Output: metricFile} + if _, err := curl(endpoint, "GET", req, connType); err != nil { return err } + + rawData, err := os.ReadFile(metricFile) + if err != nil { + return fmt.Errorf("failed to read the metric: %w", err) + } + respData := string(rawData) + var parser expfmt.TextParser _, err = parser.TextToMetricFamilies(strings.NewReader(strings.ReplaceAll(respData, "\r\n", "\n"))) return err diff --git a/tests/framework/e2e/curl.go b/tests/framework/e2e/curl.go index 88a37db151af..e7118003ffc6 100644 --- a/tests/framework/e2e/curl.go +++ b/tests/framework/e2e/curl.go @@ -37,6 +37,8 @@ type CURLReq struct { Ciphers string HttpVersion string + + Output string } func (r CURLReq) timeoutDuration() time.Duration { @@ -93,6 +95,10 @@ func CURLPrefixArgs(clientURL string, cfg ClientConfig, CN bool, method string, cmdArgs = append(cmdArgs, "--ciphers", req.Ciphers) } + if req.Output != "" { + cmdArgs = append(cmdArgs, "--output", req.Output) + } + switch method { case "POST", "PUT": dt := req.Value