Improve agent update logging and installer warnings (related to #737)

This commit is contained in:
courtmanr@gmail.com 2025-11-23 22:07:37 +00:00
parent 76b4abd9e5
commit 4640633430
3 changed files with 42 additions and 2 deletions

View file

@ -1536,7 +1536,7 @@ func detectHostRemovedError(body []byte) string {
func (a *Agent) checkForUpdates(ctx context.Context) {
// Skip updates if disabled via config
if a.cfg.DisableAutoUpdate {
a.logger.Debug().Msg("Skipping update check - auto-update disabled")
a.logger.Info().Msg("Skipping update check - auto-update disabled")
return
}

View file

@ -0,0 +1,40 @@
package dockeragent
import (
"bytes"
"context"
"strings"
"testing"
"github.com/rs/zerolog"
)
func TestCheckForUpdatesLog(t *testing.T) {
// Create a buffer to capture logs
var buf bytes.Buffer
logger := zerolog.New(&buf)
// Create an agent with DisableAutoUpdate set to true
agent := &Agent{
cfg: Config{
DisableAutoUpdate: true,
},
logger: logger,
}
// Call checkForUpdates
agent.checkForUpdates(context.Background())
// Check logs
output := buf.String()
expected := "Skipping update check - auto-update disabled"
if !strings.Contains(output, expected) {
t.Errorf("expected log message %q not found in output:\n%s", expected, output)
}
// Verify log level is INFO (zerolog default level is debug? no, default global is info, but logger.Info() writes regardless)
// Zerolog JSON output contains "level":"info"
if !strings.Contains(output, `"level":"info"`) {
t.Errorf("expected log level info, got output:\n%s", output)
}
}

View file

@ -1805,7 +1805,7 @@ if command -v curl &> /dev/null || command -v wget &> /dev/null; then
if [[ -n "$SERVER_INFO" ]] && echo "$SERVER_INFO" | grep -q '"isDevelopment"[[:space:]]*:[[:space:]]*true'; then
NO_AUTO_UPDATE_FLAG=" --no-auto-update"
log_info 'Development server detected auto-update disabled'
log_warn "Server is in development mode; disabling agent auto-update"
fi
if [[ -n "$NO_AUTO_UPDATE_FLAG" ]] && ! "$AGENT_PATH" --help 2>&1 | grep -q -- '--no-auto-update'; then