mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #16550 from jmhbnz/backport-redirecting-metrics-to-file
[3.5] Backport redirecting cmux test metrics data into file to reduce output
This commit is contained in:
commit
630401e074
@ -21,6 +21,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@ -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))
|
||||
@ -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
|
||||
|
@ -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
|
||||
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user