From ec999f3bce2ea5e58ce20bb61c1e985c8e742e55 Mon Sep 17 00:00:00 2001 From: Cyril Cressent Date: Fri, 27 Oct 2023 14:08:52 -0700 Subject: [PATCH 01/18] Add upload of installation script logs --- install-script/install.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/install-script/install.sh b/install-script/install.sh index 02eaff61..4968102e 100755 --- a/install-script/install.sh +++ b/install-script/install.sh @@ -127,6 +127,9 @@ CURL_MAX_TIME=1800 # set by check_dependencies therefore cannot be set by set_defaults SYSTEMD_DISABLED=false +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() { @@ -167,6 +170,13 @@ Supported env variables: EOF } +function reporter { + echo "Reporting Sumo OpenTelemetry collector installation..." + echo "SUMOLOGIC_INSTALLATION_TOKEN=${SUMOLOGIC_INSTALLATION_TOKEN}" >> $INSTALLATION_LOGFILE + gzip < "${INSTALLATION_LOGFILE}" | curl --silent --location --post302 --header 'Content-Encoding:gzip' --data-binary @- "${INSTALLATION_LOGFILE_ENDPOINT}" +} +trap reporter EXIT + function set_defaults() { HOME_DIRECTORY="/var/lib/otelcol-sumo" FILE_STORAGE="${HOME_DIRECTORY}/file_storage" @@ -1699,6 +1709,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 From 23f138512be3bd595f3f2389dc547d59b4bafc54 Mon Sep 17 00:00:00 2001 From: Cyril Cressent Date: Fri, 27 Oct 2023 14:49:17 -0700 Subject: [PATCH 02/18] Add support for gziping install log if possible --- install-script/install.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/install-script/install.sh b/install-script/install.sh index 4968102e..440e5276 100755 --- a/install-script/install.sh +++ b/install-script/install.sh @@ -171,9 +171,14 @@ EOF } function reporter { - echo "Reporting Sumo OpenTelemetry collector installation..." - echo "SUMOLOGIC_INSTALLATION_TOKEN=${SUMOLOGIC_INSTALLATION_TOKEN}" >> $INSTALLATION_LOGFILE - gzip < "${INSTALLATION_LOGFILE}" | curl --silent --location --post302 --header 'Content-Encoding:gzip' --data-binary @- "${INSTALLATION_LOGFILE_ENDPOINT}" + echo "Reporting Sumo OpenTelemetry collector installation..." + echo "SUMOLOGIC_INSTALLATION_TOKEN=${SUMOLOGIC_INSTALLATION_TOKEN}" >> $INSTALLATION_LOGFILE + + if command -v "gzip" &> /dev/null; then + gzip < "${INSTALLATION_LOGFILE}" | curl --silent --location --post302 --header 'Content-Encoding:gzip' --data-binary @- "${INSTALLATION_LOGFILE_ENDPOINT}" + else + curl --silent --location --post302 --data-binary @"${INSTALLATION_LOGFILE}" "${INSTALLATION_LOGFILE_ENDPOINT}" + fi } trap reporter EXIT From 6654f7c1542943d4ace6bb113427b0b12c19ba34 Mon Sep 17 00:00:00 2001 From: Cyril Cressent Date: Fri, 27 Oct 2023 14:59:32 -0700 Subject: [PATCH 03/18] Remove message tripping up tests --- install-script/install.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/install-script/install.sh b/install-script/install.sh index 440e5276..8423e8fc 100755 --- a/install-script/install.sh +++ b/install-script/install.sh @@ -171,7 +171,6 @@ EOF } function reporter { - echo "Reporting Sumo OpenTelemetry collector installation..." echo "SUMOLOGIC_INSTALLATION_TOKEN=${SUMOLOGIC_INSTALLATION_TOKEN}" >> $INSTALLATION_LOGFILE if command -v "gzip" &> /dev/null; then From 72f014d8bd3a33d6e4dafedddd05e326f4092f71 Mon Sep 17 00:00:00 2001 From: Cyril Cressent Date: Mon, 4 Dec 2023 10:53:09 -0800 Subject: [PATCH 04/18] Update following backend rework --- install-script/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install-script/install.sh b/install-script/install.sh index 8423e8fc..e51190d5 100755 --- a/install-script/install.sh +++ b/install-script/install.sh @@ -174,9 +174,9 @@ function reporter { echo "SUMOLOGIC_INSTALLATION_TOKEN=${SUMOLOGIC_INSTALLATION_TOKEN}" >> $INSTALLATION_LOGFILE if command -v "gzip" &> /dev/null; then - gzip < "${INSTALLATION_LOGFILE}" | curl --silent --location --post302 --header 'Content-Encoding:gzip' --data-binary @- "${INSTALLATION_LOGFILE_ENDPOINT}" + gzip < "${INSTALLATION_LOGFILE}" | curl --silent --location -X POST --header 'Content-Encoding:gzip' --data-binary @- "${INSTALLATION_LOGFILE_ENDPOINT}" else - curl --silent --location --post302 --data-binary @"${INSTALLATION_LOGFILE}" "${INSTALLATION_LOGFILE_ENDPOINT}" + curl --silent --location -X POST --data-binary @"${INSTALLATION_LOGFILE}" "${INSTALLATION_LOGFILE_ENDPOINT}" fi } trap reporter EXIT From 3b8ef5663e161b31aec7b16a6b59954269ad5b6c Mon Sep 17 00:00:00 2001 From: Cyril Cressent Date: Mon, 4 Dec 2023 10:55:07 -0800 Subject: [PATCH 05/18] Remove support for gzipped logs The backend does not currently handle `Content-Encoding` headers properly anymore. See: https://sumologic.atlassian.net/browse/SUMO-232957 --- install-script/install.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/install-script/install.sh b/install-script/install.sh index e51190d5..5104759e 100755 --- a/install-script/install.sh +++ b/install-script/install.sh @@ -172,12 +172,7 @@ EOF function reporter { echo "SUMOLOGIC_INSTALLATION_TOKEN=${SUMOLOGIC_INSTALLATION_TOKEN}" >> $INSTALLATION_LOGFILE - - if command -v "gzip" &> /dev/null; then - gzip < "${INSTALLATION_LOGFILE}" | curl --silent --location -X POST --header 'Content-Encoding:gzip' --data-binary @- "${INSTALLATION_LOGFILE_ENDPOINT}" - else - curl --silent --location -X POST --data-binary @"${INSTALLATION_LOGFILE}" "${INSTALLATION_LOGFILE_ENDPOINT}" - fi + curl --silent --location -X POST --data-binary @"${INSTALLATION_LOGFILE}" "${INSTALLATION_LOGFILE_ENDPOINT}" } trap reporter EXIT From 1cf268d1cf78d54c6bc699050ba3897d87d1f726 Mon Sep 17 00:00:00 2001 From: Cyril Cressent Date: Fri, 19 Jan 2024 12:36:26 -0800 Subject: [PATCH 06/18] Add upload of installation logs for Windows --- install-script/install.ps1 | 55 ++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/install-script/install.ps1 b/install-script/install.ps1 index f9497932..ac6ee74b 100644 --- a/install-script/install.ps1 +++ b/install-script/install.ps1 @@ -396,19 +396,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 @@ -420,6 +446,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" @@ -527,4 +562,8 @@ try { msiexec.exe /i "$msiPath" /passive $msiProperties } catch [HttpRequestException] { Write-Error $_.Exception.InnerException.Message -} \ No newline at end of file +} finally { + Stop-Transcript | Out-Null + Send-Installation-Logs -Endpoint $InstallationLogFileEndpoint -Path $InstallationLogFile -HttpClient $httpClient + Remove-Item $InstallationLogFile +} From f24bf05d06f3e5465c1a405d37813f0ca41e1767 Mon Sep 17 00:00:00 2001 From: Cyril Cressent Date: Wed, 14 Feb 2024 10:55:39 -0800 Subject: [PATCH 07/18] Add option to disable installation telemetry Add --disable-installation-telemetry for Linux Add -DisableInstallationTelemetry for Windows Signed-off-by: Cyril Cressent --- install-script/install.ps1 | 12 ++++++++++-- install-script/install.sh | 19 +++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/install-script/install.ps1 b/install-script/install.ps1 index ac6ee74b..ef788873 100644 --- a/install-script/install.ps1 +++ b/install-script/install.ps1 @@ -28,7 +28,11 @@ param ( [bool] $Ephemeral, # The API URL used to communicate with the SumoLogic backend - [string] $Api + [string] $Api, + + # DisableInstallationTelemetry is used to disable reporting the installation + # to Sumologic. + [bool] $DisableInstallationTelemetry ) $PackageGithubOrg = "SumoLogic" @@ -564,6 +568,10 @@ try { Write-Error $_.Exception.InnerException.Message } finally { Stop-Transcript | Out-Null - Send-Installation-Logs -Endpoint $InstallationLogFileEndpoint -Path $InstallationLogFile -HttpClient $httpClient + + if ($DisableInstallationTelemetry -eq $false) { + Send-Installation-Logs -Endpoint $InstallationLogFileEndpoint -Path $InstallationLogFile -HttpClient $httpClient + } + Remove-Item $InstallationLogFile } diff --git a/install-script/install.sh b/install-script/install.sh index 5104759e..c3dcfdae 100755 --- a/install-script/install.sh +++ b/install-script/install.sh @@ -50,6 +50,8 @@ ARG_SHORT_EPHEMERAL='E' ARG_LONG_EPHEMERAL='ephemeral' ARG_SHORT_TIMEOUT='m' ARG_LONG_TIMEOUT='download-timeout' +ARG_SHORT_DISABLE_INSTALLATION_TELEMETRY='S' +ARG_LONG_DISABLE_INSTALLATION_TELEMETRY='disable-installation-telemetry' PACKAGE_GITHUB_ORG="SumoLogic" PACKAGE_GITHUB_REPO="sumologic-otel-collector-packaging" @@ -65,6 +67,7 @@ readonly ARG_SHORT_INSTALL_HOSTMETRICS ARG_LONG_INSTALL_HOSTMETRICS readonly ARG_SHORT_REMOTELY_MANAGED ARG_LONG_REMOTELY_MANAGED readonly ARG_SHORT_EPHEMERAL ARG_LONG_EPHEMERAL readonly ARG_SHORT_TIMEOUT ARG_LONG_TIMEOUT +readonly ARG_SHORT_DISABLE_INSTALLATION_TELEMETRY ARG_LONG_DISABLE_INSTALLATION_TELEMETRY readonly DEPRECATED_ARG_LONG_TOKEN DEPRECATED_ENV_TOKEN DEPRECATED_ARG_LONG_SKIP_TOKEN readonly PACKAGE_GITHUB_ORG PACKAGE_GITHUB_REPO @@ -127,6 +130,7 @@ CURL_MAX_TIME=1800 # set by check_dependencies therefore cannot be set by set_defaults SYSTEMD_DISABLED=false +DISABLE_INSTALLATION_TELEMETRY=false INSTALLATION_LOGFILE="/tmp/sumologic-otel-collector_installation.log" INSTALLATION_LOGFILE_ENDPOINT='https://stag-open-events.sumologic.net/api/v1/collector/installation/logs' @@ -162,6 +166,7 @@ Supported arguments: -${ARG_SHORT_EPHEMERAL}, --${ARG_LONG_EPHEMERAL} Delete the collector from Sumo Logic after 12 hours of inactivity. -${ARG_SHORT_TIMEOUT}, --${ARG_LONG_TIMEOUT} Timeout in seconds after which download will fail. Default is ${CURL_MAX_TIME}. -${ARG_SHORT_YES}, --${ARG_LONG_YES} Disable confirmation asks. + -${ARG_SHORT_DISABLE_INSTALLATION_TELEMETRY}, --${ARG_LONG_DISABLE_INSTALLATION_TELEMETRY} Do not report installation logs to Sumologic -${ARG_SHORT_HELP}, --${ARG_LONG_HELP} Prints this help and usage. @@ -171,8 +176,10 @@ EOF } function reporter { - echo "SUMOLOGIC_INSTALLATION_TOKEN=${SUMOLOGIC_INSTALLATION_TOKEN}" >> $INSTALLATION_LOGFILE - curl --silent --location -X POST --data-binary @"${INSTALLATION_LOGFILE}" "${INSTALLATION_LOGFILE_ENDPOINT}" + if ! $DISABLE_INSTALLATION_TELEMETRY; then + echo "SUMOLOGIC_INSTALLATION_TOKEN=${SUMOLOGIC_INSTALLATION_TOKEN}" >> $INSTALLATION_LOGFILE + curl --silent --location -X POST --data-binary @"${INSTALLATION_LOGFILE}" "${INSTALLATION_LOGFILE_ENDPOINT}" + fi } trap reporter EXIT @@ -270,7 +277,7 @@ function parse_options() { "--${ARG_LONG_TIMEOUT}") set -- "$@" "-${ARG_SHORT_TIMEOUT}" ;; - "-${ARG_SHORT_TOKEN}"|"-${ARG_SHORT_HELP}"|"-${ARG_SHORT_API}"|"-${ARG_SHORT_TAG}"|"-${ARG_SHORT_SKIP_CONFIG}"|"-${ARG_SHORT_VERSION}"|"-${ARG_SHORT_FIPS}"|"-${ARG_SHORT_YES}"|"-${ARG_SHORT_SKIP_SYSTEMD}"|"-${ARG_SHORT_UNINSTALL}"|"-${ARG_SHORT_PURGE}"|"-${ARG_SHORT_SKIP_TOKEN}"|"-${ARG_SHORT_DOWNLOAD}"|"-${ARG_SHORT_CONFIG_BRANCH}"|"-${ARG_SHORT_BINARY_BRANCH}"|"-${ARG_SHORT_BRANCH}"|"-${ARG_SHORT_KEEP_DOWNLOADS}"|"-${ARG_SHORT_TIMEOUT}"|"-${ARG_SHORT_INSTALL_HOSTMETRICS}"|"-${ARG_SHORT_REMOTELY_MANAGED}"|"-${ARG_SHORT_EPHEMERAL}") + "-${ARG_SHORT_TOKEN}"|"-${ARG_SHORT_HELP}"|"-${ARG_SHORT_API}"|"-${ARG_SHORT_TAG}"|"-${ARG_SHORT_SKIP_CONFIG}"|"-${ARG_SHORT_VERSION}"|"-${ARG_SHORT_FIPS}"|"-${ARG_SHORT_YES}"|"-${ARG_SHORT_SKIP_SYSTEMD}"|"-${ARG_SHORT_UNINSTALL}"|"-${ARG_SHORT_PURGE}"|"-${ARG_SHORT_SKIP_TOKEN}"|"-${ARG_SHORT_DOWNLOAD}"|"-${ARG_SHORT_CONFIG_BRANCH}"|"-${ARG_SHORT_BINARY_BRANCH}"|"-${ARG_SHORT_BRANCH}"|"-${ARG_SHORT_KEEP_DOWNLOADS}"|"-${ARG_SHORT_TIMEOUT}"|"-${ARG_SHORT_INSTALL_HOSTMETRICS}"|"-${ARG_SHORT_REMOTELY_MANAGED}"|"-${ARG_SHORT_EPHEMERAL}"|"-${ARG_SHORT_DISABLE_INSTALLATION_TELEMETRY}") set -- "$@" "${arg}" ;; "--${ARG_LONG_INSTALL_HOSTMETRICS}") @@ -282,6 +289,9 @@ function parse_options() { "--${ARG_LONG_EPHEMERAL}") set -- "$@" "-${ARG_SHORT_EPHEMERAL}" ;; + "--${ARG_LONG_DISABLE_INSTALLATION_TELEMETRY}") + set -- "$@" "-${ARG_SHORT_DISABLE_INSTALLATION_TELEMETRY}" + ;; -*) echo "Unknown option ${arg}"; usage; exit 1 ;; *) @@ -294,7 +304,7 @@ function parse_options() { while true; do set +e - getopts "${ARG_SHORT_HELP}${ARG_SHORT_TOKEN}:${ARG_SHORT_API}:${ARG_SHORT_TAG}:${ARG_SHORT_VERSION}:${ARG_SHORT_FIPS}${ARG_SHORT_YES}${ARG_SHORT_SKIP_SYSTEMD}${ARG_SHORT_UNINSTALL}${ARG_SHORT_PURGE}${ARG_SHORT_SKIP_TOKEN}${ARG_SHORT_SKIP_CONFIG}${ARG_SHORT_DOWNLOAD}${ARG_SHORT_KEEP_DOWNLOADS}${ARG_SHORT_CONFIG_BRANCH}:${ARG_SHORT_BINARY_BRANCH}:${ARG_SHORT_BRANCH}:${ARG_SHORT_EPHEMERAL}${ARG_SHORT_REMOTELY_MANAGED}${ARG_SHORT_INSTALL_HOSTMETRICS}${ARG_SHORT_TIMEOUT}:" opt + getopts "${ARG_SHORT_HELP}${ARG_SHORT_TOKEN}:${ARG_SHORT_API}:${ARG_SHORT_TAG}:${ARG_SHORT_VERSION}:${ARG_SHORT_FIPS}${ARG_SHORT_YES}${ARG_SHORT_SKIP_SYSTEMD}${ARG_SHORT_UNINSTALL}${ARG_SHORT_PURGE}${ARG_SHORT_SKIP_TOKEN}${ARG_SHORT_SKIP_CONFIG}${ARG_SHORT_DOWNLOAD}${ARG_SHORT_KEEP_DOWNLOADS}${ARG_SHORT_CONFIG_BRANCH}:${ARG_SHORT_BINARY_BRANCH}:${ARG_SHORT_BRANCH}:${ARG_SHORT_EPHEMERAL}${ARG_SHORT_REMOTELY_MANAGED}${ARG_SHORT_INSTALL_HOSTMETRICS}${ARG_SHORT_TIMEOUT}:${ARG_SHORT_DISABLE_INSTALLATION_TELEMETRY}" opt set -e # Invalid argument catched, print and exit @@ -332,6 +342,7 @@ function parse_options() { "${ARG_SHORT_EPHEMERAL}") EPHEMERAL=true ;; "${ARG_SHORT_KEEP_DOWNLOADS}") KEEP_DOWNLOADS=true ;; "${ARG_SHORT_TIMEOUT}") CURL_MAX_TIME="${OPTARG}" ;; + "${ARG_SHORT_DISABLE_INSTALLATION_TELEMETRY}") DISABLE_INSTALLATION_TELEMETRY=true ;; "${ARG_SHORT_TAG}") if [[ "${OPTARG}" != ?*"="* ]]; then echo "Invalid tag: '${OPTARG}'. Should be in 'key=value' format" From 89752fea8dd88a4e4774450ba1b2175f08baca42 Mon Sep 17 00:00:00 2001 From: Cyril Cressent Date: Wed, 14 Feb 2024 11:15:42 -0800 Subject: [PATCH 08/18] Do not send installation telemetry when --help Signed-off-by: Cyril Cressent --- install-script/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-script/install.sh b/install-script/install.sh index c3dcfdae..ea60a3ac 100755 --- a/install-script/install.sh +++ b/install-script/install.sh @@ -316,7 +316,7 @@ function parse_options() { # Validate opt and set arguments case "$opt" in - "${ARG_SHORT_HELP}") usage; exit 0 ;; + "${ARG_SHORT_HELP}") usage; DISABLE_INSTALLATION_TELEMETRY=true exit 0 ;; "${ARG_SHORT_TOKEN}") SUMOLOGIC_INSTALLATION_TOKEN="${OPTARG}" ;; "${ARG_SHORT_API}") API_BASE_URL="${OPTARG}" ;; "${ARG_SHORT_SKIP_CONFIG}") SKIP_CONFIG=true ;; From 2b1c15fea6c0428793ea0649e5d2d77ceb5db6dd Mon Sep 17 00:00:00 2001 From: Cyril Cressent Date: Wed, 14 Feb 2024 11:36:20 -0800 Subject: [PATCH 09/18] Add option to change installation logs endpoint Add --installation-logfile-endpoint on Linux Add -InstallationLogfileEndpoint on Windows Signed-off-by: Cyril Cressent --- install-script/install.ps1 | 11 +++++++++-- install-script/install.sh | 13 ++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/install-script/install.ps1 b/install-script/install.ps1 index ef788873..9c5a99d4 100644 --- a/install-script/install.ps1 +++ b/install-script/install.ps1 @@ -32,7 +32,11 @@ param ( # DisableInstallationTelemetry is used to disable reporting the installation # to Sumologic. - [bool] $DisableInstallationTelemetry + [bool] $DisableInstallationTelemetry, + + # InstallationLogfileEndpoint is used to configure the endpoint where + # installation logs will be sent. + [string] $InstallationLogfileEndpoint ) $PackageGithubOrg = "SumoLogic" @@ -436,7 +440,10 @@ function Send-Installation-Logs { try { $InstallationLogFile = New-TemporaryFile - $InstallationLogFileEndpoint = "https://stag-open-events.sumologic.net/api/v1/collector/installation/logs" + + if ($InstallationLogFileEndpoint -eq "") { + $InstallationLogFileEndpoint = "https://stag-open-events.sumologic.net/api/v1/collector/installation/logs" + } Start-Transcript $InstallationLogFile | Out-Null diff --git a/install-script/install.sh b/install-script/install.sh index ea60a3ac..23d56c66 100755 --- a/install-script/install.sh +++ b/install-script/install.sh @@ -52,6 +52,8 @@ ARG_SHORT_TIMEOUT='m' ARG_LONG_TIMEOUT='download-timeout' ARG_SHORT_DISABLE_INSTALLATION_TELEMETRY='S' ARG_LONG_DISABLE_INSTALLATION_TELEMETRY='disable-installation-telemetry' +ARG_SHORT_INSTALLATION_LOGFILE_ENDPOINT='l' +ARG_LONG_INSTALLATION_LOGFILE_ENDPOINT='installation-logfile-endpoint' PACKAGE_GITHUB_ORG="SumoLogic" PACKAGE_GITHUB_REPO="sumologic-otel-collector-packaging" @@ -68,6 +70,7 @@ readonly ARG_SHORT_REMOTELY_MANAGED ARG_LONG_REMOTELY_MANAGED readonly ARG_SHORT_EPHEMERAL ARG_LONG_EPHEMERAL readonly ARG_SHORT_TIMEOUT ARG_LONG_TIMEOUT readonly ARG_SHORT_DISABLE_INSTALLATION_TELEMETRY ARG_LONG_DISABLE_INSTALLATION_TELEMETRY +readonly ARG_SHORT_INSTALLATION_LOGFILE_ENDPOINT ARG_LONG_INSTALLATION_LOGFILE_ENDPOINT readonly DEPRECATED_ARG_LONG_TOKEN DEPRECATED_ENV_TOKEN DEPRECATED_ARG_LONG_SKIP_TOKEN readonly PACKAGE_GITHUB_ORG PACKAGE_GITHUB_REPO @@ -166,7 +169,7 @@ Supported arguments: -${ARG_SHORT_EPHEMERAL}, --${ARG_LONG_EPHEMERAL} Delete the collector from Sumo Logic after 12 hours of inactivity. -${ARG_SHORT_TIMEOUT}, --${ARG_LONG_TIMEOUT} Timeout in seconds after which download will fail. Default is ${CURL_MAX_TIME}. -${ARG_SHORT_YES}, --${ARG_LONG_YES} Disable confirmation asks. - -${ARG_SHORT_DISABLE_INSTALLATION_TELEMETRY}, --${ARG_LONG_DISABLE_INSTALLATION_TELEMETRY} Do not report installation logs to Sumologic + -${ARG_SHORT_DISABLE_INSTALLATION_TELEMETRY}, --${ARG_LONG_DISABLE_INSTALLATION_TELEMETRY} Do not report installation logs to Sumologic. -${ARG_SHORT_HELP}, --${ARG_LONG_HELP} Prints this help and usage. @@ -277,7 +280,7 @@ function parse_options() { "--${ARG_LONG_TIMEOUT}") set -- "$@" "-${ARG_SHORT_TIMEOUT}" ;; - "-${ARG_SHORT_TOKEN}"|"-${ARG_SHORT_HELP}"|"-${ARG_SHORT_API}"|"-${ARG_SHORT_TAG}"|"-${ARG_SHORT_SKIP_CONFIG}"|"-${ARG_SHORT_VERSION}"|"-${ARG_SHORT_FIPS}"|"-${ARG_SHORT_YES}"|"-${ARG_SHORT_SKIP_SYSTEMD}"|"-${ARG_SHORT_UNINSTALL}"|"-${ARG_SHORT_PURGE}"|"-${ARG_SHORT_SKIP_TOKEN}"|"-${ARG_SHORT_DOWNLOAD}"|"-${ARG_SHORT_CONFIG_BRANCH}"|"-${ARG_SHORT_BINARY_BRANCH}"|"-${ARG_SHORT_BRANCH}"|"-${ARG_SHORT_KEEP_DOWNLOADS}"|"-${ARG_SHORT_TIMEOUT}"|"-${ARG_SHORT_INSTALL_HOSTMETRICS}"|"-${ARG_SHORT_REMOTELY_MANAGED}"|"-${ARG_SHORT_EPHEMERAL}"|"-${ARG_SHORT_DISABLE_INSTALLATION_TELEMETRY}") + "-${ARG_SHORT_TOKEN}"|"-${ARG_SHORT_HELP}"|"-${ARG_SHORT_API}"|"-${ARG_SHORT_TAG}"|"-${ARG_SHORT_SKIP_CONFIG}"|"-${ARG_SHORT_VERSION}"|"-${ARG_SHORT_FIPS}"|"-${ARG_SHORT_YES}"|"-${ARG_SHORT_SKIP_SYSTEMD}"|"-${ARG_SHORT_UNINSTALL}"|"-${ARG_SHORT_PURGE}"|"-${ARG_SHORT_SKIP_TOKEN}"|"-${ARG_SHORT_DOWNLOAD}"|"-${ARG_SHORT_CONFIG_BRANCH}"|"-${ARG_SHORT_BINARY_BRANCH}"|"-${ARG_SHORT_BRANCH}"|"-${ARG_SHORT_KEEP_DOWNLOADS}"|"-${ARG_SHORT_TIMEOUT}"|"-${ARG_SHORT_INSTALL_HOSTMETRICS}"|"-${ARG_SHORT_REMOTELY_MANAGED}"|"-${ARG_SHORT_EPHEMERAL}"|"-${ARG_SHORT_DISABLE_INSTALLATION_TELEMETRY}"|"-${ARG_SHORT_INSTALLATION_LOGFILE_ENDPOINT}") set -- "$@" "${arg}" ;; "--${ARG_LONG_INSTALL_HOSTMETRICS}") @@ -292,6 +295,9 @@ function parse_options() { "--${ARG_LONG_DISABLE_INSTALLATION_TELEMETRY}") set -- "$@" "-${ARG_SHORT_DISABLE_INSTALLATION_TELEMETRY}" ;; + "--${ARG_LONG_INSTALLATION_LOGFILE_ENDPOINT}") + set -- "$@" "-${ARG_SHORT_INSTALLATION_LOGFILE_ENDPOINT}" + ;; -*) echo "Unknown option ${arg}"; usage; exit 1 ;; *) @@ -304,7 +310,7 @@ function parse_options() { while true; do set +e - getopts "${ARG_SHORT_HELP}${ARG_SHORT_TOKEN}:${ARG_SHORT_API}:${ARG_SHORT_TAG}:${ARG_SHORT_VERSION}:${ARG_SHORT_FIPS}${ARG_SHORT_YES}${ARG_SHORT_SKIP_SYSTEMD}${ARG_SHORT_UNINSTALL}${ARG_SHORT_PURGE}${ARG_SHORT_SKIP_TOKEN}${ARG_SHORT_SKIP_CONFIG}${ARG_SHORT_DOWNLOAD}${ARG_SHORT_KEEP_DOWNLOADS}${ARG_SHORT_CONFIG_BRANCH}:${ARG_SHORT_BINARY_BRANCH}:${ARG_SHORT_BRANCH}:${ARG_SHORT_EPHEMERAL}${ARG_SHORT_REMOTELY_MANAGED}${ARG_SHORT_INSTALL_HOSTMETRICS}${ARG_SHORT_TIMEOUT}:${ARG_SHORT_DISABLE_INSTALLATION_TELEMETRY}" opt + getopts "${ARG_SHORT_HELP}${ARG_SHORT_TOKEN}:${ARG_SHORT_API}:${ARG_SHORT_TAG}:${ARG_SHORT_VERSION}:${ARG_SHORT_FIPS}${ARG_SHORT_YES}${ARG_SHORT_SKIP_SYSTEMD}${ARG_SHORT_UNINSTALL}${ARG_SHORT_PURGE}${ARG_SHORT_SKIP_TOKEN}${ARG_SHORT_SKIP_CONFIG}${ARG_SHORT_DOWNLOAD}${ARG_SHORT_KEEP_DOWNLOADS}${ARG_SHORT_CONFIG_BRANCH}:${ARG_SHORT_BINARY_BRANCH}:${ARG_SHORT_BRANCH}:${ARG_SHORT_EPHEMERAL}${ARG_SHORT_REMOTELY_MANAGED}${ARG_SHORT_INSTALL_HOSTMETRICS}${ARG_SHORT_TIMEOUT}:${ARG_SHORT_DISABLE_INSTALLATION_TELEMETRY}${ARG_SHORT_INSTALLATION_LOGFILE_ENDPOINT}:" opt set -e # Invalid argument catched, print and exit @@ -343,6 +349,7 @@ function parse_options() { "${ARG_SHORT_KEEP_DOWNLOADS}") KEEP_DOWNLOADS=true ;; "${ARG_SHORT_TIMEOUT}") CURL_MAX_TIME="${OPTARG}" ;; "${ARG_SHORT_DISABLE_INSTALLATION_TELEMETRY}") DISABLE_INSTALLATION_TELEMETRY=true ;; + "${ARG_SHORT_INSTALLATION_LOGFILE_ENDPOINT}") INSTALLATION_LOGFILE_ENDPOINT="${OPTARG}" ;; "${ARG_SHORT_TAG}") if [[ "${OPTARG}" != ?*"="* ]]; then echo "Invalid tag: '${OPTARG}'. Should be in 'key=value' format" From 111e8ea4861cef77b28ade09950282d8aff8fcd2 Mon Sep 17 00:00:00 2001 From: Cyril Cressent Date: Thu, 11 Apr 2024 16:15:03 -0700 Subject: [PATCH 10/18] Fix ShellCheck warnings --- install-script/install.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/install-script/install.sh b/install-script/install.sh index 23d56c66..656ac453 100755 --- a/install-script/install.sh +++ b/install-script/install.sh @@ -178,9 +178,12 @@ Supported env variables: EOF } +# shellcheck disable=SC2317 # Don't warn about unreachable commands in this function +# ShellCheck may incorrectly believe that code is unreachable if it's invoked in +# a trap, like the reporter function. function reporter { if ! $DISABLE_INSTALLATION_TELEMETRY; then - echo "SUMOLOGIC_INSTALLATION_TOKEN=${SUMOLOGIC_INSTALLATION_TOKEN}" >> $INSTALLATION_LOGFILE + echo "SUMOLOGIC_INSTALLATION_TOKEN=${SUMOLOGIC_INSTALLATION_TOKEN}" >> "$INSTALLATION_LOGFILE" curl --silent --location -X POST --data-binary @"${INSTALLATION_LOGFILE}" "${INSTALLATION_LOGFILE_ENDPOINT}" fi } From 869e73366cb59aa67d8258add78341338b7ecc8c Mon Sep 17 00:00:00 2001 From: Cyril Cressent Date: Mon, 22 Apr 2024 11:30:39 -0700 Subject: [PATCH 11/18] Remove installation log file after upload This is for the shellscript only since the PowerShell script already does that. --- install-script/install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/install-script/install.sh b/install-script/install.sh index 656ac453..8276a8c6 100755 --- a/install-script/install.sh +++ b/install-script/install.sh @@ -185,6 +185,7 @@ function reporter { if ! $DISABLE_INSTALLATION_TELEMETRY; then echo "SUMOLOGIC_INSTALLATION_TOKEN=${SUMOLOGIC_INSTALLATION_TOKEN}" >> "$INSTALLATION_LOGFILE" curl --silent --location -X POST --data-binary @"${INSTALLATION_LOGFILE}" "${INSTALLATION_LOGFILE_ENDPOINT}" + rm -f "${INSTALLATION_LOGFILE}" fi } trap reporter EXIT From 0090d575d7ad978c8c14bd6fb24b0738fddb08c7 Mon Sep 17 00:00:00 2001 From: Cyril Cressent Date: Mon, 22 Apr 2024 12:29:00 -0700 Subject: [PATCH 12/18] Add installOptions for testing telemetry --- install-script/test/command_unix.go | 48 ++++++++++++++++---------- install-script/test/command_windows.go | 28 ++++++++++----- install-script/test/consts_common.go | 2 ++ 3 files changed, 52 insertions(+), 26 deletions(-) diff --git a/install-script/test/command_unix.go b/install-script/test/command_unix.go index 38a3537c..886a03d8 100644 --- a/install-script/test/command_unix.go +++ b/install-script/test/command_unix.go @@ -14,24 +14,26 @@ import ( ) type installOptions struct { - installToken string - autoconfirm bool - skipSystemd bool - tags map[string]string - skipConfig bool - skipInstallToken bool - fips bool - envs map[string]string - uninstall bool - purge bool - apiBaseURL string - configBranch string - downloadOnly bool - dontKeepDownloads bool - installHostmetrics bool - remotelyManaged bool - ephemeral bool - timeout float64 + installToken string + autoconfirm bool + skipSystemd bool + tags map[string]string + skipConfig bool + skipInstallToken bool + fips bool + envs map[string]string + uninstall bool + purge bool + apiBaseURL string + configBranch string + downloadOnly bool + dontKeepDownloads bool + installHostmetrics bool + remotelyManaged bool + ephemeral bool + timeout float64 + disableInstallationTelemetry bool + installationLogfileEndpoint string } func (io *installOptions) string() []string { @@ -105,6 +107,16 @@ func (io *installOptions) string() []string { opts = append(opts, "--download-timeout", fmt.Sprintf("%f", io.timeout)) } + if io.disableInstallationTelemetry { + opts = append(opts, "--disable-installation-telemetry") + } + + if io.installationLogfileEndpoint == "" { + opts = append(opts, "--installation-logfile-endpoint", StagingInstallationLogfileEndpoint) + } else { + opts = append(opts, "--installation-logfile-endpoint", io.installationLogfileEndpoint) + } + return opts } diff --git a/install-script/test/command_windows.go b/install-script/test/command_windows.go index 47ad5b86..63426f83 100644 --- a/install-script/test/command_windows.go +++ b/install-script/test/command_windows.go @@ -12,14 +12,16 @@ import ( ) type installOptions struct { - installToken string - tags map[string]string - fips bool - envs map[string]string - apiBaseURL string - installHostmetrics bool - remotelyManaged bool - ephemeral bool + installToken string + tags map[string]string + fips bool + envs map[string]string + apiBaseURL string + installHostmetrics bool + remotelyManaged bool + ephemeral bool + disableInstallationTelemetry bool + installationLogfileEndpoint string } func (io *installOptions) string() []string { @@ -52,6 +54,16 @@ func (io *installOptions) string() []string { opts = append(opts, "-Api", io.apiBaseURL) } + if io.disableInstallationTelemetry { + opts = append(opts, "-DisableInstallationTelemetry") + } + + if io.installationLogfileEndpoint == "" { + opts = append(opts, "-InstallationLogfileEndpoint", StagingInstallationLogfileEndpoint) + } else { + opts = append(opts, "-InstallationLogfileEndpoint", io.installationTokenEndpoint) + } + return opts } diff --git a/install-script/test/consts_common.go b/install-script/test/consts_common.go index 641997fa..becd7bcc 100644 --- a/install-script/test/consts_common.go +++ b/install-script/test/consts_common.go @@ -12,6 +12,8 @@ const ( GithubOrg = "SumoLogic" GithubAppRepository = "sumologic-otel-collector" GithubApiBaseUrl = "https://api.github.com" + + StagingInstallationLogfileEndpoint string = "https://stag-open-events.sumologic.net/api/v1/collector/installation/logs" ) var ( From 057db21b8f07470bfe15b49f07645df6db828a42 Mon Sep 17 00:00:00 2001 From: Cyril Cressent Date: Mon, 22 Apr 2024 12:31:47 -0700 Subject: [PATCH 13/18] Change default log endpoint to the production one --- install-script/install.ps1 | 2 +- install-script/install.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/install-script/install.ps1 b/install-script/install.ps1 index 9c5a99d4..5af3f172 100644 --- a/install-script/install.ps1 +++ b/install-script/install.ps1 @@ -442,7 +442,7 @@ try { $InstallationLogFile = New-TemporaryFile if ($InstallationLogFileEndpoint -eq "") { - $InstallationLogFileEndpoint = "https://stag-open-events.sumologic.net/api/v1/collector/installation/logs" + $InstallationLogFileEndpoint = "https://open-events.sumologic.net/api/v1/collector/installation/logs" } Start-Transcript $InstallationLogFile | Out-Null diff --git a/install-script/install.sh b/install-script/install.sh index 8276a8c6..661ff0f0 100755 --- a/install-script/install.sh +++ b/install-script/install.sh @@ -135,7 +135,7 @@ SYSTEMD_DISABLED=false DISABLE_INSTALLATION_TELEMETRY=false INSTALLATION_LOGFILE="/tmp/sumologic-otel-collector_installation.log" -INSTALLATION_LOGFILE_ENDPOINT='https://stag-open-events.sumologic.net/api/v1/collector/installation/logs' +INSTALLATION_LOGFILE_ENDPOINT='https://open-events.sumologic.net/api/v1/collector/installation/logs' ############################ Functions From 8f654cb39379e75d59e8e3f11f738ba9d15984d2 Mon Sep 17 00:00:00 2001 From: Cyril Cressent Date: Mon, 22 Apr 2024 12:35:54 -0700 Subject: [PATCH 14/18] Fix InstallOptions on Windows --- install-script/test/command_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-script/test/command_windows.go b/install-script/test/command_windows.go index 63426f83..74d266b5 100644 --- a/install-script/test/command_windows.go +++ b/install-script/test/command_windows.go @@ -61,7 +61,7 @@ func (io *installOptions) string() []string { if io.installationLogfileEndpoint == "" { opts = append(opts, "-InstallationLogfileEndpoint", StagingInstallationLogfileEndpoint) } else { - opts = append(opts, "-InstallationLogfileEndpoint", io.installationTokenEndpoint) + opts = append(opts, "-InstallationLogfileEndpoint", io.installationLogfileEndpoint) } return opts From e4ff3e8fa26460f8ed443e65e83b5f9899bf488c Mon Sep 17 00:00:00 2001 From: Cyril Cressent Date: Wed, 29 May 2024 11:11:55 -0700 Subject: [PATCH 15/18] Add tests for log data uploading Signed-off-by: Cyril Cressent --- install-script/test/check.go | 62 ++++++++++++++++++--- install-script/test/common_unix.go | 7 ++- install-script/test/install_unix_test.go | 20 +++++++ install-script/test/install_windows_test.go | 18 ++++++ 4 files changed, 97 insertions(+), 10 deletions(-) diff --git a/install-script/test/check.go b/install-script/test/check.go index 84f7078c..6aeca28f 100644 --- a/install-script/test/check.go +++ b/install-script/test/check.go @@ -1,7 +1,10 @@ package sumologic_scripts_tests import ( + "context" "io/fs" + "net" + "net/http" "os" "os/exec" "path/filepath" @@ -10,14 +13,20 @@ import ( "github.com/stretchr/testify/require" ) +type mockInstallationLogsEndpoint struct { + server *http.Server + receivedData bool +} + type check struct { - test *testing.T - installOptions installOptions - code int - err error - expectedInstallCode int - output []string - errorOutput []string + test *testing.T + installationLogsEndpoint *mockInstallationLogsEndpoint + installOptions installOptions + code int + err error + expectedInstallCode int + output []string + errorOutput []string } type condCheckFunc func(check) bool @@ -221,3 +230,42 @@ func PathHasUserACL(t *testing.T, path string, ownerName string, perms string) { require.NoError(t, err, "error while checking "+path+" acl") require.Contains(t, string(output), "user:"+ownerName+":"+perms) } + +func preActionStartInstallationLogsMockReceiver(c check) { + c.test.Log("Starting mock installation logs endpoint") + + mux := http.NewServeMux() + mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodPost && r.ContentLength >= 1 { + c.installationLogsEndpoint.receivedData = true + } + }) + + listener, err := net.Listen("tcp", ":4444") + require.NoError(c.test, err) + + c.installationLogsEndpoint.server = &http.Server{ + Handler: mux, + } + + go func() { + err := c.installationLogsEndpoint.server.Serve(listener) + if err != nil && err != http.ErrServerClosed { + require.NoError(c.test, err) + } + }() +} + +func checkInstallationLogsReceived(c check) { + require.Equal(c.test, true, c.installationLogsEndpoint.receivedData, "mock installation logs endpoint should have received data but didn't") + + c.test.Log("Stopping mock installation logs endpoint") + require.NoError(c.test, c.installationLogsEndpoint.server.Shutdown(context.Background())) +} + +func checkInstallationLogsNotReceived(c check) { + require.Equal(c.test, false, c.installationLogsEndpoint.receivedData, "mock installation logs endpoint received data but shouldn't have") + + c.test.Log("Stopping mock installation logs endpoint") + require.NoError(c.test, c.installationLogsEndpoint.server.Shutdown(context.Background())) +} diff --git a/install-script/test/common_unix.go b/install-script/test/common_unix.go index 513aaf0c..b9195b24 100644 --- a/install-script/test/common_unix.go +++ b/install-script/test/common_unix.go @@ -23,9 +23,10 @@ func cleanCache(t *testing.T) { func runTest(t *testing.T, spec *testSpec) { ch := check{ - test: t, - installOptions: spec.options, - expectedInstallCode: spec.installCode, + test: t, + installationLogsEndpoint: new(mockInstallationLogsEndpoint), + installOptions: spec.options, + expectedInstallCode: spec.installCode, } t.Log("Running conditional checks") diff --git a/install-script/test/install_unix_test.go b/install-script/test/install_unix_test.go index 93b1ffc2..eaaa708d 100644 --- a/install-script/test/install_unix_test.go +++ b/install-script/test/install_unix_test.go @@ -601,6 +601,26 @@ func TestInstallScript(t *testing.T) { preChecks: []checkFunc{checkBinaryNotCreated, checkConfigNotCreated, checkUserConfigNotCreated, checkUserNotExists}, postChecks: []checkFunc{checkBinaryCreated, checkBinaryIsRunning, checkConfigCreated, checkUserConfigNotCreated, checkSystemdConfigNotCreated}, }, + { + name: "installation telemetry is uploaded", + options: installOptions{ + disableInstallationTelemetry: false, + installationLogfileEndpoint: "http://localhost:4444/", + }, + preActions: []checkFunc{preActionStartInstallationLogsMockReceiver}, + postChecks: []checkFunc{checkInstallationLogsReceived}, + installCode: 1, + }, + { + name: "installation telemetry can be disabled", + options: installOptions{ + disableInstallationTelemetry: true, + installationLogfileEndpoint: "http://localhost:4444/", + }, + preActions: []checkFunc{preActionStartInstallationLogsMockReceiver}, + postChecks: []checkFunc{checkInstallationLogsNotReceived}, + installCode: 1, + }, } { t.Run(spec.name, func(t *testing.T) { runTest(t, &spec) diff --git a/install-script/test/install_windows_test.go b/install-script/test/install_windows_test.go index 9fcff317..ab12141b 100644 --- a/install-script/test/install_windows_test.go +++ b/install-script/test/install_windows_test.go @@ -146,6 +146,24 @@ func TestInstallScript(t *testing.T) { checkTags, }, }, + { + name: "installation telemetry is uploaded", + options: installOptions{ + disableInstallationTelemetry: false, + installationLogfileEndpoint: "http://localhost:4444/", + }, + preActions: []checkFunc{preActionStartInstallationLogsMockReceiver}, + postChecks: []checkFunc{checkInstallationLogsReceived}, + }, + { + name: "installation telemetry can be disabled", + options: installOptions{ + disableInstallationTelemetry: true, + installationLogfileEndpoint: "http://localhost:4444/", + }, + preActions: []checkFunc{preActionStartInstallationLogsMockReceiver}, + postChecks: []checkFunc{checkInstallationLogsNotReceived}, + }, } { t.Run(spec.name, func(t *testing.T) { runTest(t, &spec) From cbb50ad6122c70096768eb0bfead11fdb1ce84f6 Mon Sep 17 00:00:00 2001 From: Cyril Cressent Date: Wed, 29 May 2024 15:38:45 -0700 Subject: [PATCH 16/18] Fix Windows tests --- install-script/test/common_windows.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/install-script/test/common_windows.go b/install-script/test/common_windows.go index 58a5c585..c30e632d 100644 --- a/install-script/test/common_windows.go +++ b/install-script/test/common_windows.go @@ -19,9 +19,10 @@ var commonPostChecks = []checkFunc{checkNoBakFilesPresent} func runTest(t *testing.T, spec *testSpec) { ch := check{ - test: t, - installOptions: spec.options, - expectedInstallCode: spec.installCode, + test: t, + installationLogsEndpoint: new(mockInstallationLogsEndpoint), + installOptions: spec.options, + expectedInstallCode: spec.installCode, } t.Log("Running conditional checks") From 104990fc03efa7ab59d40689dff27dd290bd5ca4 Mon Sep 17 00:00:00 2001 From: Cyril Cressent Date: Wed, 29 May 2024 19:45:30 -0700 Subject: [PATCH 17/18] Fix Windows tests --- install-script/test/install_windows_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/install-script/test/install_windows_test.go b/install-script/test/install_windows_test.go index ab12141b..85e1b18f 100644 --- a/install-script/test/install_windows_test.go +++ b/install-script/test/install_windows_test.go @@ -154,6 +154,7 @@ func TestInstallScript(t *testing.T) { }, preActions: []checkFunc{preActionStartInstallationLogsMockReceiver}, postChecks: []checkFunc{checkInstallationLogsReceived}, + installCode: 1, }, { name: "installation telemetry can be disabled", @@ -163,6 +164,7 @@ func TestInstallScript(t *testing.T) { }, preActions: []checkFunc{preActionStartInstallationLogsMockReceiver}, postChecks: []checkFunc{checkInstallationLogsNotReceived}, + installCode: 1, }, } { t.Run(spec.name, func(t *testing.T) { From 42cd587594908362faa01e698b03e825d379063a Mon Sep 17 00:00:00 2001 From: Cyril Cressent Date: Mon, 3 Jun 2024 09:32:36 -0700 Subject: [PATCH 18/18] Use $TMPDIR --- install-script/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-script/install.sh b/install-script/install.sh index 854521bb..fe2858e2 100755 --- a/install-script/install.sh +++ b/install-script/install.sh @@ -138,7 +138,7 @@ CURL_MAX_TIME=1800 SYSTEMD_DISABLED=false DISABLE_INSTALLATION_TELEMETRY=false -INSTALLATION_LOGFILE="/tmp/sumologic-otel-collector_installation.log" +INSTALLATION_LOGFILE="${TMPDIR:=/tmp}/sumologic-otel-collector_installation.log" INSTALLATION_LOGFILE_ENDPOINT='https://open-events.sumologic.net/api/v1/collector/installation/logs' ############################ Functions