From da9cf0338d5c3bf72b6d1c159495408e8d03f75a Mon Sep 17 00:00:00 2001 From: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> Date: Mon, 11 Dec 2023 16:42:23 -0500 Subject: [PATCH 1/5] first crack at adding a new configurable option to the windows installer for static mode Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> --- .../grafana-agent/windows/install_script.nsis | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packaging/grafana-agent/windows/install_script.nsis b/packaging/grafana-agent/windows/install_script.nsis index 07f8986026da..485b72179b06 100644 --- a/packaging/grafana-agent/windows/install_script.nsis +++ b/packaging/grafana-agent/windows/install_script.nsis @@ -27,6 +27,8 @@ LicenseData LICENSE Var EnableExporterCheck Var EnableExporterValue Var EnableExporterDialog +Var ExpandEnvCheck +Var ExpandEnvValue Var PassedInParameters Var Url Var Username @@ -58,6 +60,7 @@ Section "install" ThisIsSilent: ${GetParameters} $PassedInParameters ${GetOptions} $PassedInParameters "/EnableExporter" $EnableExporterValue + ${GetOptions} $PassedInParameters "/ExpandEnv" $ExpandEnvValue ${GetOptions} $PassedInParameters "/Url" $Url ${GetOptions} $PassedInParameters "/Username" $Username ${GetOptions} $PassedInParameters "/Password" $Password @@ -81,6 +84,12 @@ Function enableWindowsExporter ${NSD_CreateCheckBox} 0 13u 100% 12u "" Pop $EnableExporterCheck + ${NSD_CreateLabel} 0 0 100% 12u "Expand Environment Variables" + Pop $0 + + ${NSD_CreateCheckBox} 0 13u 100% 12u "" + Pop $ExpandEnvCheck + nsDialogs::Show FunctionEnd @@ -91,6 +100,13 @@ Function enableWindowsExporterLeave ${Else} StrCpy $EnableExporterValue "false" ${EndIf} + + ${NSD_GetState} $ExpandEnvCheck $ExpandEnvValue + ${If} $ExpandEnvValue == ${BST_CHECKED} + StrCpy $ExpandEnvValue "true" + ${Else} + StrCpy $ExpandEnvValue "false" + ${EndIf} FunctionEnd Function Install @@ -128,7 +144,11 @@ Function Install nsExec::ExecToLog 'sc create "Grafana Agent" binpath= "\"$INSTDIR\grafana-agent-windows-amd64.exe\""' Pop $0 # These separate create and config commands are needed, on the config the binpath is required - nsExec::ExecToLog 'sc config "Grafana Agent" start= auto binpath= "\"$INSTDIR\grafana-agent-windows-amd64.exe\" -config.file=\"$INSTDIR\agent-config.yaml\""' + ${If} $ExpandEnvValue == "true" + nsExec::ExecToLog 'sc config "Grafana Agent" start= auto binpath= "\"$INSTDIR\grafana-agent-windows-amd64.exe\" -config.expand-env -config.file=\"$INSTDIR\agent-config.yaml\""' + ${Else} + nsExec::ExecToLog 'sc config "Grafana Agent" start= auto binpath= "\"$INSTDIR\grafana-agent-windows-amd64.exe\" -config.file=\"$INSTDIR\agent-config.yaml\""' + ${EndIf} Pop $0 nsExec::ExecToLog `sc start "Grafana Agent"` Pop $0 From 80700ba00c9f3c2ccb300178d51f87228d86a064 Mon Sep 17 00:00:00 2001 From: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> Date: Thu, 4 Jan 2024 14:56:58 -0500 Subject: [PATCH 2/5] fix alignment so checkboxes don't overlap Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> --- packaging/grafana-agent/windows/install_script.nsis | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/grafana-agent/windows/install_script.nsis b/packaging/grafana-agent/windows/install_script.nsis index 485b72179b06..d813e4ff7238 100644 --- a/packaging/grafana-agent/windows/install_script.nsis +++ b/packaging/grafana-agent/windows/install_script.nsis @@ -84,10 +84,10 @@ Function enableWindowsExporter ${NSD_CreateCheckBox} 0 13u 100% 12u "" Pop $EnableExporterCheck - ${NSD_CreateLabel} 0 0 100% 12u "Expand Environment Variables" + ${NSD_CreateLabel} 0 26u 100% 12u "Expand Environment Variables" Pop $0 - ${NSD_CreateCheckBox} 0 13u 100% 12u "" + ${NSD_CreateCheckBox} 0 39u 100% 12u "" Pop $ExpandEnvCheck nsDialogs::Show From b39c3658d24bf8bea56e71d74e92cffbdc2de231 Mon Sep 17 00:00:00 2001 From: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> Date: Thu, 4 Jan 2024 14:58:11 -0500 Subject: [PATCH 3/5] changelog Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34d2e8367c64..f1579899e285 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,8 @@ Main (unreleased) - Added support for `loki.write` to flush WAL on agent shutdown. (@thepalbi) +- Add an option to the windows static mode installer for expanding environment vars in the yaml config. (@erikbaranowski) + ### Bugfixes - Update `pyroscope.ebpf` to fix a logical bug causing to profile to many kthreads instead of regular processes https://github.com/grafana/pyroscope/pull/2778 (@korniltsev) From d8ccc081bede812c0d1dc55339a80cd429728bb1 Mon Sep 17 00:00:00 2001 From: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> Date: Fri, 5 Jan 2024 15:44:01 -0500 Subject: [PATCH 4/5] Add docs for new windows static install option Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> --- .../install/install-agent-on-windows.md | 26 ++++++++++++++++++- .../grafana-agent/windows/install_script.nsis | 20 +++++++------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/docs/sources/static/set-up/install/install-agent-on-windows.md b/docs/sources/static/set-up/install/install-agent-on-windows.md index 1ff2a05e61a4..bf27459f1cb4 100644 --- a/docs/sources/static/set-up/install/install-agent-on-windows.md +++ b/docs/sources/static/set-up/install/install-agent-on-windows.md @@ -30,7 +30,11 @@ To do a standard graphical install of Grafana Agent on Windows, perform the foll 1. Double-click on `grafana-agent-installer.exe` to install Grafana Agent. Grafana Agent is installed into the default directory `C:\Program Files\Grafana Agent`. - The [windows_exporter integration](/docs/agent/latest/static/configuration/integrations/windows-exporter-config) can be enabled with all default windows_exporter options. + + The following options are available: + + - The [windows_exporter integration][windows_exporter_config] can be enabled with all default windows_exporter options. + - The [-config.expand-env][flags] command line flag can be enabled. ## Silent install @@ -78,6 +82,24 @@ If you are using `remote_write` you must enable Windows Exporter and set the glo If you are using Powershell, make sure you use triple quotes `"""http://example.com"""` around the URL parameter. +## Silent install with `-config.expand_env` + +It is possible to enable [-config.expand-env][flags] during a silent install. + +1. Navigate to the [latest release](https://github.com/grafana/agent/releases) on GitHub. + +1. Scroll down to the **Assets** section. + +1. Download the file called `grafana-agent-installer.exe.zip`. + +1. Unzip the downloaded file. + +1. Run the following command in PowerShell or Command Prompt: + + ```shell + PATH_TO_INSTALLER/grafana-agent-installer.exe /S /ExpandEnv true + ``` + ## Verify the installation 1. Make sure you can access `http://localhost:12345/-/healthy` and `http://localhost:12345/agent/api/v1/metrics/targets`. @@ -146,6 +168,8 @@ Refer to [windows_events](/docs/loki/latest/clients/promtail/configuration/#wind - [Configure Grafana Agent][configure] {{% docs/reference %}} +[flags]: "/docs/agent/ -> /docs/agent//static/configuration/flags" +[windows_exporter_config]: "/docs/agent/ -> /docs/agent//static/configuration/integrations/windows-exporter-config" [start]: "/docs/agent/ -> /docs/agent//static/set-up/start-agent" [start]: "/docs/grafana-cloud/ -> ../start-agent" [configure]: "/docs/agent/ -> /docs/agent//static/configuration/create-config-file" diff --git a/packaging/grafana-agent/windows/install_script.nsis b/packaging/grafana-agent/windows/install_script.nsis index d813e4ff7238..b08a8216c691 100644 --- a/packaging/grafana-agent/windows/install_script.nsis +++ b/packaging/grafana-agent/windows/install_script.nsis @@ -24,19 +24,19 @@ outFile "${OUT}" LicenseData LICENSE # Everything must be global Vars +Var EnableOptionsDialog +Var PassedInParameters Var EnableExporterCheck Var EnableExporterValue -Var EnableExporterDialog -Var ExpandEnvCheck -Var ExpandEnvValue -Var PassedInParameters Var Url Var Username Var Password +Var ExpandEnvCheck +Var ExpandEnvValue Page license Page directory -Page custom enableWindowsExporter enableWindowsExporterLeave +Page custom enableOptions enableOptionsLeave Page instfiles # Annoyingly macros need to be defined before use @@ -60,21 +60,21 @@ Section "install" ThisIsSilent: ${GetParameters} $PassedInParameters ${GetOptions} $PassedInParameters "/EnableExporter" $EnableExporterValue - ${GetOptions} $PassedInParameters "/ExpandEnv" $ExpandEnvValue ${GetOptions} $PassedInParameters "/Url" $Url ${GetOptions} $PassedInParameters "/Username" $Username ${GetOptions} $PassedInParameters "/Password" $Password + ${GetOptions} $PassedInParameters "/ExpandEnv" $ExpandEnvValue Call Install Return RunInstaller: Call Install SectionEnd -Function enableWindowsExporter +Function enableOptions nsDialogs::Create 1018 - Pop $EnableExporterDialog + Pop $EnableOptionsDialog - ${If} $EnableExporterDialog == error + ${If} $EnableOptionsDialog == error Abort ${EndIf} @@ -93,7 +93,7 @@ Function enableWindowsExporter nsDialogs::Show FunctionEnd -Function enableWindowsExporterLeave +Function enableOptionsLeave ${NSD_GetState} $EnableExporterCheck $EnableExporterValue ${If} $EnableExporterValue == ${BST_CHECKED} StrCpy $EnableExporterValue "true" From c008dda20773442ec3b38609dca7e10cdd52fd90 Mon Sep 17 00:00:00 2001 From: Erik Baranowski <39704712+erikbaranowski@users.noreply.github.com> Date: Wed, 10 Jan 2024 14:55:54 -0500 Subject: [PATCH 5/5] Update docs/sources/static/set-up/install/install-agent-on-windows.md Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com> --- docs/sources/static/set-up/install/install-agent-on-windows.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sources/static/set-up/install/install-agent-on-windows.md b/docs/sources/static/set-up/install/install-agent-on-windows.md index bf27459f1cb4..ddda581a5355 100644 --- a/docs/sources/static/set-up/install/install-agent-on-windows.md +++ b/docs/sources/static/set-up/install/install-agent-on-windows.md @@ -84,7 +84,7 @@ If you are using `remote_write` you must enable Windows Exporter and set the glo ## Silent install with `-config.expand_env` -It is possible to enable [-config.expand-env][flags] during a silent install. +You can enable [-config.expand-env][flags] during a silent install. 1. Navigate to the [latest release](https://github.com/grafana/agent/releases) on GitHub.