-
Notifications
You must be signed in to change notification settings - Fork 0
improve logging #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ashraffouda
wants to merge
1
commit into
main
Choose a base branch
from
improve-logging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
improve logging #87
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -551,6 +551,7 @@ func (m *Module) Run(vm pkg.VM) (pkg.MachineInfo, error) { | |
| Disks: disks, | ||
| Devices: vm.Devices, | ||
| NoKeepAlive: vm.NoKeepAlive, | ||
| NetworkInfo: &vm.Network, | ||
| } | ||
|
|
||
| log.Debug().Str("name", vm.Name).Msg("saving machine") | ||
|
|
@@ -569,6 +570,78 @@ func (m *Module) Run(vm pkg.VM) (pkg.MachineInfo, error) { | |
| m.failures.Set(vm.Name, permanent, cache.NoExpiration) | ||
| } | ||
|
|
||
| // Log comprehensive VM configuration before starting | ||
| logEvent := log.Info(). | ||
| Str("vm-id", vm.Name). | ||
| Str("hostname", vm.Hostname). | ||
| Uint8("cpu", uint8(vm.CPU)). | ||
| Uint64("memory-bytes", uint64(vm.Memory)) | ||
|
|
||
| // Log network interfaces with IPs and MACs | ||
| for idx, nic := range nics { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can implement a serializer for the interface, to construct a consistent printable string, instead of duplicating in |
||
| logEvent = logEvent. | ||
| Str(fmt.Sprintf("interface-%d-tap", idx), nic.Tap). | ||
| Str(fmt.Sprintf("interface-%d-mac", idx), nic.Mac) | ||
|
|
||
| // Log console info if available | ||
| if nic.Console != nil { | ||
| logEvent = logEvent. | ||
| Str(fmt.Sprintf("interface-%d-console-ip", idx), nic.Console.ListenAddress.IP.String()). | ||
| Str(fmt.Sprintf("interface-%d-vm-ip", idx), nic.Console.VmAddress.IP.String()). | ||
| Str(fmt.Sprintf("interface-%d-namespace", idx), nic.Console.Namespace) | ||
| } | ||
|
|
||
| // Find corresponding interface config to get IPs | ||
| if idx < len(vm.Network.Ifaces) { | ||
| ifcfg := vm.Network.Ifaces[idx] | ||
| if len(ifcfg.IPs) > 0 { | ||
| ips := make([]string, len(ifcfg.IPs)) | ||
| for i, ip := range ifcfg.IPs { | ||
| ips[i] = ip.String() | ||
| } | ||
| logEvent = logEvent.Strs(fmt.Sprintf("interface-%d-ips", idx), ips) | ||
| } | ||
| // Log gateways if present | ||
| if ifcfg.IP4DefaultGateway != nil { | ||
| logEvent = logEvent.Str(fmt.Sprintf("interface-%d-gw4", idx), ifcfg.IP4DefaultGateway.String()) | ||
| } | ||
| if ifcfg.IP6DefaultGateway != nil { | ||
| logEvent = logEvent.Str(fmt.Sprintf("interface-%d-gw6", idx), ifcfg.IP6DefaultGateway.String()) | ||
| } | ||
| // Log if this is a public interface | ||
| if ifcfg.PublicIPv4 { | ||
| logEvent = logEvent.Bool(fmt.Sprintf("interface-%d-public-ipv4", idx), true) | ||
| } | ||
| if ifcfg.PublicIPv6 { | ||
| logEvent = logEvent.Bool(fmt.Sprintf("interface-%d-public-ipv6", idx), true) | ||
| } | ||
| // Log network ID for private networks | ||
| if ifcfg.NetID != "" { | ||
| logEvent = logEvent.Str(fmt.Sprintf("interface-%d-network-id", idx), string(ifcfg.NetID)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Log mounts | ||
| if len(cfg.Mounts) > 0 { | ||
| mountPaths := make([]string, len(cfg.Mounts)) | ||
| for i, mnt := range cfg.Mounts { | ||
| mountPaths[i] = fmt.Sprintf("%s->%s", mnt.Source, mnt.Target) | ||
| } | ||
| logEvent = logEvent.Strs("mounts", mountPaths) | ||
| } | ||
|
|
||
| // Log disks | ||
| if len(disks) > 0 { | ||
| diskPaths := make([]string, len(disks)) | ||
| for i, disk := range disks { | ||
| diskPaths[i] = disk.Path | ||
| } | ||
| logEvent = logEvent.Strs("disks", diskPaths) | ||
| } | ||
|
|
||
| logEvent.Msg("starting VM with full configuration") | ||
|
|
||
| machineInfo, err := machine.Run(ctx, m.socketPath(vm.Name), m.logsPath(vm.Name)) | ||
| if err != nil { | ||
| return pkg.MachineInfo{}, m.withLogs(m.logsPath(vm.Name), err) | ||
|
|
@@ -615,6 +688,7 @@ func (m *Module) removeConfig(name string) { | |
|
|
||
| // Delete deletes a machine by name (id) | ||
| func (m *Module) Delete(name string) error { | ||
| log.Info().Str("vm-id", name).Msg("deleting VM") | ||
| defer m.failures.Delete(name) | ||
|
|
||
| // before we do anything we set failures to permanent to prevent monitoring from trying | ||
|
|
@@ -649,7 +723,7 @@ func (m *Module) Delete(name string) error { | |
| killAfter = 10 * time.Second | ||
| ) | ||
|
|
||
| log.Debug().Str("name", name).Msg("shutting vm down [client]") | ||
| log.Info().Str("name", name).Msg("shutting vm down [client]") | ||
| if err := client.Shutdown(ctx); err != nil { | ||
| log.Error().Err(err).Str("name", name).Msg("failed to shutdown machine") | ||
| } | ||
|
|
@@ -659,13 +733,13 @@ func (m *Module) Delete(name string) error { | |
| return nil | ||
| } | ||
|
|
||
| log.Debug().Str("name", name).Msg("shutting vm down [sigterm]") | ||
| log.Info().Str("name", name).Msg("shutting vm down [sigterm]") | ||
| if time.Since(now) > termAfter { | ||
| _ = syscall.Kill(ps.Pid, syscall.SIGTERM) | ||
| } | ||
|
|
||
| if time.Since(now) > killAfter { | ||
| log.Debug().Str("name", name).Msg("shutting vm down [sigkill]") | ||
| log.Info().Str("name", name).Msg("shutting vm down [sigkill]") | ||
| _ = syscall.Kill(ps.Pid, syscall.SIGKILL) | ||
| break | ||
| } | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data includes envvars, i don't think we should expose that