From 79ecaf6a99beaca560868b5e79d965ab5ea63817 Mon Sep 17 00:00:00 2001 From: Ben Reedy Date: Sun, 27 Feb 2022 07:34:50 +1000 Subject: [PATCH] Check for listening exporter before querying CI runs have exposed timing issues where promtool/e2e scripts query the exporter, before exporter has begun listening. Signed-off-by: Ben Reedy --- tools/end-to-end-test.ps1 | 12 ++++++++++-- tools/promtool.ps1 | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/tools/end-to-end-test.ps1 b/tools/end-to-end-test.ps1 index 1d370749..3af46a82 100644 --- a/tools/end-to-end-test.ps1 +++ b/tools/end-to-end-test.ps1 @@ -30,8 +30,16 @@ $exporter_proc = Start-Process ` -RedirectStandardOutput "$($temp_dir)/windows_exporter.log" ` -RedirectStandardError "$($temp_dir)/windows_exporter_error.log" -# Give exporter some time to start -Start-Sleep 15 +# Exporter can take some time to start +for ($i=1; $i -le 5; $i++) { + Start-Sleep 10 + + $netstat_output = netstat -anp tcp | Select-String 'listening' + if ($netstat_output -like '*:9182*') { + break + } + Write-Host "Waiting for exporter to start" +} $response = Invoke-WebRequest -UseBasicParsing -URI http://127.0.0.1:9182/metrics # Response output must be split and saved as UTF-8. diff --git a/tools/promtool.ps1 b/tools/promtool.ps1 index 16fe32c6..46d3941a 100644 --- a/tools/promtool.ps1 +++ b/tools/promtool.ps1 @@ -98,8 +98,16 @@ $exporter_proc = Start-Process ` -RedirectStandardOutput "$($temp_dir)/windows_exporter.log" ` -RedirectStandardError "$($temp_dir)/windows_exporter_error.log" -# Give exporter some time to start -Start-Sleep 15 +# Exporter can take some time to start +for ($i=1; $i -le 5; $i++) { + Start-Sleep 10 + + $netstat_output = netstat -anp tcp | Select-String 'listening' + if ($netstat_output -like '*:9183*') { + break + } + Write-Host "Waiting for exporter to start" +} # Omit metrics from client_golang library; we're not responsible for these $skip_re = "^[#]?\s*(HELP|TYPE)?\s*go_"