Skip to content

Commit

Permalink
fix(install): fail install if Otelcol is not running on darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
swiatekm committed Dec 7, 2023
1 parent d8677a5 commit e32ef7a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
15 changes: 15 additions & 0 deletions pkg/scripts_test/install_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func TestInstallScriptDarwin(t *testing.T) {
checkLaunchdConfigCreated,
checkHomeDirectoryCreated,
},
installCode: 1, // because of invalid installation token
},
{
name: "installation token only",
Expand All @@ -102,6 +103,7 @@ func TestInstallScriptDarwin(t *testing.T) {
checkHostmetricsConfigNotCreated,
checkHomeDirectoryCreated,
},
installCode: 1, // because of invalid installation token
},
{
name: "installation token and ephemeral",
Expand All @@ -124,6 +126,7 @@ func TestInstallScriptDarwin(t *testing.T) {
checkHostmetricsConfigNotCreated,
checkHomeDirectoryCreated,
},
installCode: 1, // because of invalid installation token
},
{
name: "override default config",
Expand All @@ -146,6 +149,7 @@ func TestInstallScriptDarwin(t *testing.T) {
checkUserConfigCreated,
checkLaunchdConfigCreated,
},
installCode: 1, // because of invalid installation token
},
{
name: "installation token and hostmetrics",
Expand All @@ -168,6 +172,7 @@ func TestInstallScriptDarwin(t *testing.T) {
checkHostmetricsOwnershipAndPermissions(systemUser, systemGroup),
checkHomeDirectoryCreated,
},
installCode: 1, // because of invalid installation token
},
{
name: "installation token and remotely-managed",
Expand All @@ -190,6 +195,7 @@ func TestInstallScriptDarwin(t *testing.T) {
checkGroupExists,
checkHomeDirectoryCreated,
},
installCode: 1, // because of invalid installation token
},
{
name: "installation token, remotely-managed, and ephemeral",
Expand All @@ -213,6 +219,7 @@ func TestInstallScriptDarwin(t *testing.T) {
checkGroupExists,
checkHomeDirectoryCreated,
},
installCode: 1, // because of invalid installation token
},
{
name: "installation token only, binary not in PATH",
Expand All @@ -235,6 +242,7 @@ func TestInstallScriptDarwin(t *testing.T) {
checkGroupExists,
checkHomeDirectoryCreated,
},
installCode: 1, // because of invalid installation token
},
{
name: "same installation token in launchd config",
Expand All @@ -259,6 +267,7 @@ func TestInstallScriptDarwin(t *testing.T) {
checkTokenInLaunchdConfig,
checkHomeDirectoryCreated,
},
installCode: 1, // because of invalid installation token
},
{
name: "different installation token in launchd config",
Expand Down Expand Up @@ -311,6 +320,7 @@ func TestInstallScriptDarwin(t *testing.T) {
checkUserConfigCreated,
checkAPIBaseURLInConfig,
},
installCode: 1, // because of invalid installation token
},
{
name: "different api base url",
Expand Down Expand Up @@ -355,6 +365,7 @@ func TestInstallScriptDarwin(t *testing.T) {
checkUserConfigCreated,
checkAPIBaseURLInConfig,
},
installCode: 1, // because of invalid installation token
},
{
name: "editing api base url",
Expand All @@ -377,6 +388,7 @@ func TestInstallScriptDarwin(t *testing.T) {
checkUserConfigCreated,
checkAPIBaseURLInConfig,
},
installCode: 1, // because of invalid installation token
},
{
name: "configuration with tags",
Expand All @@ -399,6 +411,7 @@ func TestInstallScriptDarwin(t *testing.T) {
checkTags,
checkLaunchdConfigCreated,
},
installCode: 1, // because of invalid installation token
},
{
name: "same tags",
Expand Down Expand Up @@ -429,6 +442,7 @@ func TestInstallScriptDarwin(t *testing.T) {
checkTags,
checkLaunchdConfigCreated,
},
installCode: 1, // because of invalid installation token
},
{
name: "different tags",
Expand Down Expand Up @@ -489,6 +503,7 @@ func TestInstallScriptDarwin(t *testing.T) {
checkTags,
checkLaunchdConfigCreated,
},
installCode: 1, // because of invalid installation token
},
} {
t.Run(spec.name, func(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions pkg/scripts_test/install_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ func TestInstallScript(t *testing.T) {
checkVarLogACL,
},
conditionalChecks: []condCheckFunc{checkSystemdAvailability},
installCode: 3, // because of invalid installation token
installCode: 1, // because of invalid installation token
},
{
name: "systemd installation token with existing user directory",
Expand Down Expand Up @@ -444,7 +444,7 @@ func TestInstallScript(t *testing.T) {
checkOutputUserAddWarnings,
},
conditionalChecks: []condCheckFunc{checkSystemdAvailability},
installCode: 3, // because of invalid install token
installCode: 1, // because of invalid install token
},
{
name: "systemd existing installation different token env",
Expand Down Expand Up @@ -474,7 +474,7 @@ func TestInstallScript(t *testing.T) {
checkOutputUserAddWarnings,
},
conditionalChecks: []condCheckFunc{checkSystemdAvailability},
installCode: 3, // because of invalid install token
installCode: 1, // because of invalid install token
},
{
name: "installation of hostmetrics in systemd during upgrade",
Expand Down Expand Up @@ -522,7 +522,7 @@ func TestInstallScript(t *testing.T) {
checkVarLogACL,
},
conditionalChecks: []condCheckFunc{checkSystemdAvailability},
installCode: 3, // because of invalid installation token
installCode: 1, // because of invalid installation token
},
{
name: "uninstallation without autoconfirm fails",
Expand Down Expand Up @@ -586,7 +586,7 @@ func TestInstallScript(t *testing.T) {
postChecks: []checkFunc{checkBinaryCreated, checkBinaryIsRunning, checkConfigCreated, checkDifferentTokenInConfig, checkSystemdConfigCreated,
checkUserExists, checkTokenEnvFileNotCreated},
conditionalChecks: []condCheckFunc{checkSystemdAvailability},
installCode: 3, // because of invalid installation token
installCode: 1, // because of invalid installation token
},
{
name: "systemd installation if token in file",
Expand Down
14 changes: 13 additions & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,13 @@ if [[ "${OS_TYPE}" == "darwin" ]]; then
launchctl unload "${LAUNCHD_CONFIG}"
launchctl load -w "${LAUNCHD_CONFIG}"

echo 'Waiting 10s before checking status'
sleep 10
if launchctl print system/otelcol-sumo | grep "last exit code = 1"; then
echo "Failed to launch otelcol"
tail /var/log/otelcol-sumo/otelcol-sumo.log
exit 1
fi
exit 0
fi

Expand Down Expand Up @@ -2127,4 +2134,9 @@ systemctl restart otelcol-sumo

echo 'Waiting 10s before checking status'
sleep 10
systemctl status otelcol-sumo --no-pager
if ! systemctl status otelcol-sumo --no-pager; then
echo "Failed to launch otelcol"
exit 1
fi

exit 0

0 comments on commit e32ef7a

Please sign in to comment.