From 74981782a92359799949402d56e5fc1cebd52e10 Mon Sep 17 00:00:00 2001 From: eriknordmark Date: Thu, 14 May 2026 22:24:53 +0200 Subject: [PATCH] server: optional log of served device config Adam logs every inbound API request, but not the response shape. When debugging "what did adam tell EVE on this poll?" the request log alone doesn't say whether adam returned a baseos to install, what content-tree UUID, how many apps/networks/etc. Add a one-line response summary at log.Printf level, gated by an env var (ADAM_LOG_DEVICE_CONFIG=1) so the default log volume is unchanged. Fires before the 304 Not Modified check so no-change polls still surface what would have been returned. Format: config served: uuid= version= baseos.version= baseos.activate= baseos.ct= baseosconfig_list= contentInfo= apps= networks= volumes= datastores= README gets a short subsection in Options describing the variable and an example docker invocation. Signed-off-by: eriknordmark Co-Authored-By: Claude Opus 4.7 --- README.md | 23 +++++++++++++++++++++++ pkg/server/commonHandler.go | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/README.md b/README.md index db0bd5c..03b912a 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,29 @@ Finally, you can embed Adam container into an EVE root filesystem creating an EV net: host ``` +### Debug logging + +Adam logs every API request it receives. For investigations where you +also need to see what was *returned* to the device on each `/config` +poll, set `ADAM_LOG_DEVICE_CONFIG=1` in adam's environment. With this +on, every served device config produces a one-line summary on stderr: + +``` +config served: uuid= version= baseos.version= baseos.activate= \ + baseos.ct= baseosconfig_list= contentInfo= apps= \ + networks= volumes= datastores= +``` + +The variable is off by default; turning it on adds one log line per +`/config` poll per device, which is modest at typical poll intervals +(~30 s) but multiplies across N devices. + +For example, with `docker run`: + +``` +docker run -e ADAM_LOG_DEVICE_CONFIG=1 lfedge/adam server +``` + ## Controlling Adam Adam provides a CLI management interface and Web UI, both of which wrap an open management API. diff --git a/pkg/server/commonHandler.go b/pkg/server/commonHandler.go index 97e0973..55bbcce 100644 --- a/pkg/server/commonHandler.go +++ b/pkg/server/commonHandler.go @@ -17,6 +17,7 @@ import ( "log" "math/rand" "net/http" + "os" "strings" "time" @@ -89,6 +90,28 @@ func configProcess(manager driver.DeviceManager, u uuid.UUID, configRequest *con // also flips ConfigHash and EVE doesn't get 304 Not Modified. msg.ControllercertConfighash = controllerCertConfigHash + // Optional debug trace of what we're about to serve. Off by + // default; set ADAM_LOG_DEVICE_CONFIG=1 to enable when investigating + // "what did adam tell EVE on this poll?" questions. Fires before the + // 304 Not Modified check so it surfaces the response shape even on + // no-change polls. + if os.Getenv("ADAM_LOG_DEVICE_CONFIG") == "1" { + var bosVer, bosCTUUID string + var bosAct bool + if msg.Baseos != nil { + bosVer = msg.Baseos.BaseOsVersion + bosAct = msg.Baseos.Activate + bosCTUUID = msg.Baseos.ContentTreeUuid + } + log.Printf("config served: uuid=%s version=%s baseos.version=%q "+ + "baseos.activate=%v baseos.ct=%q baseosconfig_list=%d "+ + "contentInfo=%d apps=%d networks=%d volumes=%d datastores=%d", + u, msg.GetId().GetVersion(), + bosVer, bosAct, bosCTUUID, + len(msg.Base), len(msg.ContentInfo), len(msg.Apps), + len(msg.Networks), len(msg.Volumes), len(msg.Datastores)) + } + response := &config.ConfigResponse{} hash := sha256.New()