Skip to content

Commit

Permalink
Adds a GH integration test for the .NET Deployer TA
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanotti committed Mar 8, 2025
1 parent 773d789 commit f560f1a
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/dotnet-instr-deployer-add-on.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,19 @@ jobs:
with:
name: splunk_otel_dotnet_deployer
path: ./packaging/dotnet-instr-deployer-add-on/out/distribution/splunk_otel_dotnet_deployer.tgz

# Run the .NET Instrumentation Deployer Add-On integration tests

- name: Download the Splunk UF MSI
shell: bash
run: curl https://download.splunk.com/products/universalforwarder/releases/9.4.0/windows/splunkforwarder-9.4.0-6b4ebe426ca6-windows-x64.msi -o splunkforwarder.msi

- name: Install then Splunk UF
run: msiexec.exe /i "$PWD\splunkforwarder.msi" /qn /l*v install-log.txt AGREETOLICENSE=Yes

- name: Run the integration test script
run: |
./.github/workflows/scripts/win-test-dotnet-deployer-ta.ps1 `
-tgzFilePath ./packaging/dotnet-instr-deployer-add-on/out/distribution/splunk_otel_dotnet_deployer.tgz `
-splunkInstallPath $(Join-Path "${Env:ProgramFiles}" "SplunkUniversalForwarder")
108 changes: 108 additions & 0 deletions .github/workflows/scripts/win-test-dotnet-deployer-ta.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<#
.SYNOPSIS
The script validates if the Splunk OpenTelemetry .NET Deployer TA can be
installed and uninstalled successfully by Splunk.
.DESCRIPTION
The script extracts the Splunk OpenTelemetry .NET Deployer TA from a .tgz file
and installs it. It then validates the installation by checking if the expected
files and directories are present. The script also uninstalls the Splunk OpenTelemetry
.NET instrumentation, by changing the local configuration of the Deployer TA
and validates the uninstallation by once again checking if the instrumentation
files and folders were removed.
.PARAMETER tgzFilePath
Path to the .tgz file containing the Splunk OpenTelemetry .NET Deployer TA.
.PARAMETER splunkInstallPath
Path to the Splunk installation directory.
.PARAMETER splunkAppName
Actual name on the disk of the folder with the Splunk OpenTelemetry .NET
Deployer TA app.
#>
param (
[string]$tgzFilePath,
[string]$splunkInstallPath,
[string]$splunkAppName = "splunk_otel_dotnet_deployer"
)

# Function to extract .tgz file into the given destination path
function Expand-Tgz {
param (
[string]$tgzFilePath,
[string]$destinationPath
)

Write-Host "Expanding '$tgzFilePath' into '$destinationPath'"
tar -xzf $tgzFilePath -C $destinationPath
}

# Validate parameters
if (-not (Test-Path $tgzFilePath)) {
Write-Error "The specified .tgz file does not exist: $tgzFilePath"
exit 1
}
if (-not (Test-Path $splunkInstallPath)) {
Write-Error "The specified Splunk installation path does not exist: $splunkInstallPath"
exit 1
}

$splunkAppsPath = Join-Path $splunkInstallPath "etc/apps"
Expand-Tgz -tgzFilePath $tgzFilePath -destinationPath $splunkAppsPath

# Check if the TA is installed
$taPath = Join-Path $splunkAppsPath $splunkAppName
if (Test-Path $taPath) {
Write-Host "Splunk TA $splunkAppName is installed at $taPath"
} else {
Write-Error "Splunk TA $splunkAppName is not installed"
exit 1
}

# Restart Splunk
Write-Host "Restarting Splunk"
& "$splunkInstallPath/bin/splunk.exe" restart

# Check if the Splunk OpenTelemetry .NET instrumentation is installed
$splunkOtelDotNetPath = Join-Path ${env:ProgramFiles} "Splunk OpenTelemetry .NET"
if (Test-Path $splunkOtelDotNetPath) {
Write-Host "Splunk OpenTelemetry .NET instrumentation is installed at $splunkOtelDotNetPath"
} else {
Write-Error "Splunk OpenTelemetry .NET instrumentation is not installed"
exit 1
}

# Create a local inputs.conf for the TA and configure it to uninstall the Splunk OpenTelemety .NET instrumentation
$localInputsConfPath = Join-Path $taPath "local/inputs.conf"
# Ensure the local directory exists
$localDir = Join-Path $taPath "local"
if (-not (Test-Path $localDir)) {
New-Item -ItemType Directory -Path $localDir | Out-Null
}

# Copy the default inputs.conf to the local directory
$defaultInputsConfPath = Join-Path $taPath "default/inputs.conf"
if (Test-Path $defaultInputsConfPath) {
Copy-Item -Path $defaultInputsConfPath -Destination $inputsConfPath
Write-Host "Copied default inputs.conf to local directory"
} else {
Write-Error "Default inputs.conf does not exist at $defaultInputsConfPath"
exit 1
}

# Modify the local inputs.conf to uninstall the Splunk OpenTelemetry .NET instrumentation
$localInputsConfContent = (Get-Content $localInputsConfPath).Replace("uninstall = false", "uninstall = true")
Set-Content -Path $localInputsConfPath -Value $localInputsConfContent

# Restart Splunk
Write-Host "Restarting Splunk"
& "$splunkInstallPath/bin/splunk.exe" restart

# Check if the Splunk OpenTelemetry .NET instrumentation is uninstalled
if (-not (Test-Path $splunkOtelDotNetPath)) {
Write-Host "Splunk OpenTelemetry .NET instrumentation is uninstalled"
} else {
Write-Error "Splunk OpenTelemetry .NET instrumentation is not uninstalled"
exit 1
}

0 comments on commit f560f1a

Please sign in to comment.