windows_exporter/tools/end-to-end-test.ps1

69 lines
2.7 KiB
PowerShell
Raw Normal View History

$ErrorActionPreference = 'Stop'
Set-StrictMode -Version 3
if (-not (Test-Path -Path '.\windows_exporter.exe')) {
Write-Output ".\windows_exporter.exe not found. Consider running \`go build\` first"
}
# cd to location of script
$script_path = $MyInvocation.MyCommand.Path
$working_dir = Split-Path $script_path
Push-Location $working_dir
$temp_dir = Join-Path $env:TEMP $(New-Guid) | ForEach-Object { mkdir $_ }
# Create temporary directory for textfile collector
$textfile_dir = "$($temp_dir)/textfile"
mkdir $textfile_dir | Out-Null
Copy-Item 'e2e-textfile.prom' -Destination "$($textfile_dir)/e2e-textfile.prom"
# Omit dynamic collector information that will change after each run
First implementation of physical_disk collector (#803) * Added physical_disk collector. Signed-off-by: Rob Scheepens <rob.scheepens@nutanix.com> Signed-off-by: Brantley West <brantley@nutanix.com> * exporter.go: Added physical_disk to defaultCollectors Signed-off-by: Rob Scheepens <rob.scheepens@nutanix.com> Signed-off-by: Brantley West <brantley@nutanix.com> * Fix test cases for physicaldisk metrics Signed-off-by: Rob Scheepens <rob.scheepens@nutanix.com> Signed-off-by: Brantley West <brantley@nutanix.com> * physical_disk.go: cleanup gofmt error Signed-off-by: Brantley West <brantley@nutanix.com> * physical_disk.go: populate physical disk 'number' label Signed-off-by: Brantley West <brantley@nutanix.com> * Added docs/collector.physical_disk.md. Signed-off-by: Rob Scheepens <rob.scheepens@nutanix.com> * physical_disk.go: change 'number' label to 'disk' to match node_exporter label Signed-off-by: Brantley West <brantley@nutanix.com> * physical_disk.go: adopt github.com/go-kit/log Signed-off-by: Brantley West <brantley@nutanix.com> * physical_disk.go: adopt include/exclude disk list Signed-off-by: Brantley West <brantley@nutanix.com> * fix: Add init config for physical_disk collector Signed-off-by: Ben Reedy <breed808@breed808.com> * chore: gofmt physical_disk collector Signed-off-by: Ben Reedy <breed808@breed808.com> --------- Signed-off-by: Rob Scheepens <rob.scheepens@nutanix.com> Signed-off-by: Brantley West <brantley@nutanix.com> Signed-off-by: Ben Reedy <breed808@breed808.com> Co-authored-by: Brantley West <brantley@nutanix.com> Co-authored-by: Ben Reedy <breed808@breed808.com>
2023-09-22 06:45:22 +00:00
$skip_re = "^(go_|windows_exporter_build_info|windows_exporter_collector_duration_seconds|windows_exporter_perflib_snapshot_duration_seconds|process_|windows_textfile_mtime_seconds|windows_cpu|windows_cs|windows_logical_disk|windows_physical_disk|windows_net|windows_os|windows_service|windows_system|windows_textfile_mtime_seconds)"
# Start process in background, awaiting HTTP requests.
# Use default collectors, port and address: http://localhost:9182/metrics
$exporter_proc = Start-Process `
-PassThru `
-FilePath ..\windows_exporter.exe `
-ArgumentList "--log.level=debug --web.disable-exporter-metrics --collectors.enabled=[defaults],textfile --collector.textfile.directories=$($textfile_dir)" `
-WindowStyle Hidden `
-RedirectStandardOutput "$($temp_dir)/windows_exporter.log" `
-RedirectStandardError "$($temp_dir)/windows_exporter_error.log"
# 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"
}
2024-08-05 13:50:41 +00:00
try {
$response = Invoke-WebRequest -UseBasicParsing -URI http://127.0.0.1:9182/metrics
} catch {
Write-Host "STDOUT"
Get-Content "$($temp_dir)/windows_exporter.log"
Write-Host "STDERR"
Get-Content "$($temp_dir)/windows_exporter_error.log"
throw $_
}
# Response output must be split and saved as UTF-8.
$response.content -split "[`r`n]"| Select-String -NotMatch $skip_re | Set-Content -Encoding utf8 "$($temp_dir)/e2e-output.txt"
Stop-Process -Id $exporter_proc.Id
$output_diff = Compare-Object (Get-Content 'e2e-output.txt') (Get-Content "$($temp_dir)/e2e-output.txt")
# Fail if differences in output are detected
if (-not ($null -eq $output_diff)) {
$output_diff | Format-Table
Write-Host "STDOUT"
Get-Content "$($temp_dir)/windows_exporter.log"
Write-Host "STDERR"
Get-Content "$($temp_dir)/windows_exporter_error.log"
exit 1
}