Add structured daemon lifecycle logs
VM start, image build, and network/setup failures were hard to diagnose because bangerd emitted almost no lifecycle logs and the Firecracker SDK logger was discarded. This adds a daemon-wide JSON logger with configurable log level so failures leave breadcrumbs instead of only side effects. Log the main daemon and VM lifecycle stages, preserve raw Firecracker and image-build helper output in dedicated files, and include those log paths in daemon status and returned errors. Bridge SDK logrus output into the daemon logger at debug level so low-level Firecracker diagnostics are available without making normal info logs unreadable. Validation: go test ./... and make build. Left unrelated worktree changes out of this commit, including internal/api/types.go, the deleted shell scripts, and my-rootfs.ext4.
This commit is contained in:
parent
5018bc6170
commit
644e60d739
13 changed files with 746 additions and 31 deletions
|
|
@ -16,6 +16,7 @@ import (
|
|||
type fileConfig struct {
|
||||
RuntimeDir string `toml:"runtime_dir"`
|
||||
RepoRoot string `toml:"repo_root"`
|
||||
LogLevel string `toml:"log_level"`
|
||||
FirecrackerBin string `toml:"firecracker_bin"`
|
||||
MapDNSBin string `toml:"mapdns_bin"`
|
||||
MapDNSDataFile string `toml:"mapdns_data_file"`
|
||||
|
|
@ -40,6 +41,7 @@ type fileConfig struct {
|
|||
|
||||
func Load(layout paths.Layout) (model.DaemonConfig, error) {
|
||||
cfg := model.DaemonConfig{
|
||||
LogLevel: "info",
|
||||
AutoStopStaleAfter: 0,
|
||||
StatsPollInterval: model.DefaultStatsPollInterval,
|
||||
MetricsPollInterval: model.DefaultMetricsPollInterval,
|
||||
|
|
@ -75,6 +77,9 @@ func Load(layout paths.Layout) (model.DaemonConfig, error) {
|
|||
if file.FirecrackerBin != "" {
|
||||
cfg.FirecrackerBin = file.FirecrackerBin
|
||||
}
|
||||
if file.LogLevel != "" {
|
||||
cfg.LogLevel = file.LogLevel
|
||||
}
|
||||
if file.MapDNSBin != "" {
|
||||
cfg.MapDNSBin = file.MapDNSBin
|
||||
}
|
||||
|
|
@ -150,6 +155,9 @@ func Load(layout paths.Layout) (model.DaemonConfig, error) {
|
|||
if value := os.Getenv("BANGER_MAPDNS_DATA_FILE"); value != "" {
|
||||
cfg.MapDNSDataFile = value
|
||||
}
|
||||
if value := os.Getenv("BANGER_LOG_LEVEL"); value != "" {
|
||||
cfg.LogLevel = value
|
||||
}
|
||||
if cfg.MapDNSBin == "" {
|
||||
cfg.MapDNSBin = "mapdns"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -130,6 +130,7 @@ func TestLoadFallsBackToLegacyRuntimeLayoutWithoutBundleMetadata(t *testing.T) {
|
|||
func TestLoadAppliesMapDNSEnvOverrides(t *testing.T) {
|
||||
t.Setenv("BANGER_MAPDNS_BIN", "/opt/bin/mapdns")
|
||||
t.Setenv("BANGER_MAPDNS_DATA_FILE", "/tmp/mapdns-records.json")
|
||||
t.Setenv("BANGER_LOG_LEVEL", "debug")
|
||||
|
||||
cfg, err := Load(paths.Layout{ConfigDir: t.TempDir()})
|
||||
if err != nil {
|
||||
|
|
@ -142,4 +143,17 @@ func TestLoadAppliesMapDNSEnvOverrides(t *testing.T) {
|
|||
if cfg.MapDNSDataFile != "/tmp/mapdns-records.json" {
|
||||
t.Fatalf("MapDNSDataFile = %q", cfg.MapDNSDataFile)
|
||||
}
|
||||
if cfg.LogLevel != "debug" {
|
||||
t.Fatalf("LogLevel = %q", cfg.LogLevel)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadDefaultsLogLevelToInfo(t *testing.T) {
|
||||
cfg, err := Load(paths.Layout{ConfigDir: t.TempDir()})
|
||||
if err != nil {
|
||||
t.Fatalf("Load: %v", err)
|
||||
}
|
||||
if cfg.LogLevel != "info" {
|
||||
t.Fatalf("LogLevel = %q, want info", cfg.LogLevel)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue