Skip to content

Commit d8c866e

Browse files
authored
fix(e2e): improve node-exporter validator diagnostics (#8193)
1 parent 3215165 commit d8c866e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

e2e/validators.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,15 +1526,20 @@ func ValidateNodeExporter(ctx context.Context, s *Scenario) {
15261526
ValidateFileExists(ctx, s, skipFile)
15271527
ValidateFileExists(ctx, s, "/etc/node-exporter.d/web-config.yml")
15281528

1529-
// Validate that node-exporter is listening on port 19100 and serving metrics.
1529+
// Validate that node-exporter is listening on port 19100 and serving metrics on the node ip.
15301530
// TLS is disabled by default (opt-in via NODE_EXPORTER_TLS_ENABLED=true in /etc/default/node-exporter),
15311531
// so we validate by making a plain HTTP request to the metrics endpoint.
1532+
// We avoid curl -sf here so that diagnostic messages (e.g. "Client sent an HTTP request to an HTTPS server")
1533+
// are visible in test logs rather than silently swallowed.
1534+
// We intentionally do not rewrite wildcard ('*' or '0.0.0.0') listen addresses — node-exporter
1535+
// should always bind to the node IP; if it doesn't, the test should fail.
15321536
s.T.Logf("Validating node-exporter is listening on port 19100 and serving metrics")
15331537
command := []string{
15341538
"set -ex",
1535-
// Extract the listen address from ss, replacing wildcard '*' or '0.0.0.0' with localhost.
1536-
"LISTEN_ADDR=$(ss -tlnp | grep ':19100' | awk '{print $4}' | head -1 | sed 's/^\\*/127.0.0.1/; s/^0\\.0\\.0\\.0/127.0.0.1/')",
1537-
"curl -sf http://${LISTEN_ADDR}/metrics | grep -q 'node_'",
1539+
"LISTEN_ADDR=$(ss -tlnp | grep ':19100' | awk '{print $4}' | head -1)",
1540+
"echo \"node-exporter listen address: ${LISTEN_ADDR}\"",
1541+
"curl -s --max-time 10 http://${LISTEN_ADDR}/metrics 2>&1 | head -20",
1542+
"curl -s --max-time 10 http://${LISTEN_ADDR}/metrics 2>&1 | grep -q 'node_'",
15381543
}
15391544
execScriptOnVMForScenarioValidateExitCode(ctx, s, strings.Join(command, "\n"), 0, "node-exporter should be listening on port 19100 and serving metrics over HTTP")
15401545

0 commit comments

Comments
 (0)