Skip to content

Commit

Permalink
Merge pull request etcd-io#16550 from jmhbnz/backport-redirecting-met…
Browse files Browse the repository at this point in the history
…rics-to-file

[3.5] Backport redirecting cmux test metrics data into file to reduce output
  • Loading branch information
serathius committed Sep 7, 2023
2 parents 182e352 + baa580a commit 630401e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
21 changes: 16 additions & 5 deletions tests/e2e/cmux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
"testing"

Expand Down Expand Up @@ -137,7 +139,7 @@ func testConnectionMultiplexing(ctx context.Context, t *testing.T, member etcdPr
}
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))
Expand Down Expand Up @@ -187,12 +189,21 @@ func validateGrpcgatewayRangeReponse(respData []byte) error {
return json.Unmarshal(respData, &resp)
}

func fetchMetrics(endpoint string, httpVersion string, connType clientConnType) error {
req := 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 clientConnType) error {
tmpDir := t.TempDir()
metricFile := filepath.Join(tmpDir, "metrics")

req := cURLReq{endpoint: "/metrics", timeout: 5, httpVersion: httpVersion, OutputFile: 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
Expand Down
6 changes: 6 additions & 0 deletions tests/e2e/v2_curl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ type cURLReq struct {

ciphers string
httpVersion string

OutputFile string
}

// cURLPrefixArgsCluster builds the beginning of a curl command for a given key
Expand Down Expand Up @@ -185,6 +187,10 @@ func cURLPrefixArgs(clientURL string, connType clientConnType, CN bool, method s
cmdArgs = append(cmdArgs, "--ciphers", req.ciphers)
}

if req.OutputFile != "" {
cmdArgs = append(cmdArgs, "--output", req.OutputFile)
}

switch method {
case "POST", "PUT":
dt := req.value
Expand Down

0 comments on commit 630401e

Please sign in to comment.