Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add upload of installation script logs #1312

Closed
wants to merge 13 commits into from
53 changes: 46 additions & 7 deletions scripts/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -377,19 +377,45 @@ function Get-BinaryFromUri {
Write-Host "Downloaded ${Path}"
}

function Send-Installation-Logs {
param (
[Parameter(Mandatory, Position=0)]
[HttpClient] $HttpClient,

[Parameter(Mandatory, Position=1)]
[string] $Endpoint,

[Parameter(Mandatory, Position=2)]
[string] $Path
)

$Content = Get-Content -Path $Path
$StringContent = [System.Net.Http.StringContent]::new($Content)

$response = $HttpClient.PostAsync($Endpoint, $StringContent).GetAwaiter().GetResult()
if (!($response.IsSuccessStatusCode)) {
$statusCode = [int]$response.StatusCode
$reasonPhrase = $response.StatusCode.ToString()
$errMsg = "${statusCode} ${reasonPhrase}"

if ($response.Content -ne $null) {
$content = $response.Content.ReadAsStringAsync().GetAwaiter().GetResult()
$errMsg += ": ${content}"
}

Write-Error $errMsg -ErrorAction Stop
}
}

##
# Main code
##

try {
if ($InstallationToken -eq $null -or $InstallationToken -eq "") {
Write-Error "Installation token has not been provided. Please set the SUMOLOGIC_INSTALLATION_TOKEN environment variable." -ErrorAction Stop
}
$InstallationLogFile = New-TemporaryFile
$InstallationLogFileEndpoint = "https://stag-open-events.sumologic.net/api/v1/collector/installation/logs"

$osName = Get-OSName
$archName = Get-ArchName
Write-Host "Detected OS type:`t${osName}"
Write-Host "Detected architecture:`t${archName}"
Start-Transcript $InstallationLogFile | Out-Null

$handler = New-Object HttpClientHandler
$handler.AllowAutoRedirect = $true
Expand All @@ -401,6 +427,15 @@ try {
# set http client timeout to 30 seconds
$httpClient.Timeout = New-Object System.TimeSpan(0, 0, 30)

if ($InstallationToken -eq $null -or $InstallationToken -eq "") {
Write-Error "Installation token has not been provided. Please set the SUMOLOGIC_INSTALLATION_TOKEN environment variable." -ErrorAction Stop
}

$osName = Get-OSName
$archName = Get-ArchName
Write-Host "Detected OS type:`t${osName}"
Write-Host "Detected architecture:`t${archName}"

if ($Fips -eq $true) {
if ($osName -ne "Win32NT" -or $archName -ne "x64") {
Write-Error "Error: The FIPS-approved binary is only available for windows/amd64"
Expand Down Expand Up @@ -498,4 +533,8 @@ try {
msiexec.exe /i "$msiPath" /passive $msiProperties
} catch [HttpRequestException] {
Write-Error $_.Exception.InnerException.Message
} finally {
Stop-Transcript | Out-Null
Send-Installation-Logs -Endpoint $InstallationLogFileEndpoint -Path $InstallationLogFile -HttpClient $httpClient
Remove-Item $InstallationLogFile
}
12 changes: 12 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ SYSTEMD_DISABLED=false
# alternative commands
TAC="tac"

INSTALLATION_LOGFILE="/tmp/sumologic-otel-collector_installation.log"
INSTALLATION_LOGFILE_ENDPOINT='https://stag-open-events.sumologic.net/api/v1/collector/installation/logs'

############################ Functions

function usage() {
Expand Down Expand Up @@ -170,6 +173,12 @@ Supported env variables:
EOF
}

function reporter {
echo "SUMOLOGIC_INSTALLATION_TOKEN=${SUMOLOGIC_INSTALLATION_TOKEN}" >> $INSTALLATION_LOGFILE
curl --silent --location -X POST --data-binary @"${INSTALLATION_LOGFILE}" "${INSTALLATION_LOGFILE_ENDPOINT}"
ccressent marked this conversation as resolved.
Show resolved Hide resolved
}
trap reporter EXIT

function set_defaults() {
HOME_DIRECTORY="/var/lib/otelcol-sumo"
FILE_STORAGE="${HOME_DIRECTORY}/file_storage"
Expand Down Expand Up @@ -1736,6 +1745,9 @@ function plutil_replace_key() {

############################ Main code

# Redirect a copy of stdout and stderr into $INSTALLATION_LOGFILE
exec > >(tee "${INSTALLATION_LOGFILE}") 2>&1

OS_TYPE="$(get_os_type)"
ARCH_TYPE="$(get_arch_type)"
readonly OS_TYPE ARCH_TYPE
Expand Down
Loading