Skip to content

Commit

Permalink
Merge pull request etcd-io#16439 from fuweid/fix-16422
Browse files Browse the repository at this point in the history
tests/*: redirect metrics into file
  • Loading branch information
serathius authored Aug 18, 2023
2 parents 699861a + e4e05c5 commit 6ef9c53
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 @@ -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))
Expand Down Expand Up @@ -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, 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/framework/e2e/curl.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type CURLReq struct {

Ciphers string
HttpVersion string

OutputFile string
}

func (r CURLReq) timeoutDuration() time.Duration {
Expand Down Expand Up @@ -93,6 +95,10 @@ func CURLPrefixArgs(clientURL string, cfg ClientConfig, CN bool, method string,
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 6ef9c53

Please sign in to comment.