Skip to content

Commit a10f431

Browse files
authored
Merge pull request #424 from xibz/debug
Adds debug helper
2 parents b876684 + ec30080 commit a10f431

File tree

12 files changed

+712
-54
lines changed

12 files changed

+712
-54
lines changed

config/config.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/pkg/errors"
2222

23+
"github.com/firecracker-microvm/firecracker-containerd/internal/debug"
2324
"github.com/firecracker-microvm/firecracker-containerd/proto"
2425
models "github.com/firecracker-microvm/firecracker-go-sdk/client/models"
2526
)
@@ -40,14 +41,13 @@ const (
4041

4142
// Config represents runtime configuration parameters
4243
type Config struct {
43-
FirecrackerBinaryPath string `json:"firecracker_binary_path"`
44-
KernelImagePath string `json:"kernel_image_path"`
45-
KernelArgs string `json:"kernel_args"`
46-
RootDrive string `json:"root_drive"`
47-
CPUTemplate string `json:"cpu_template"`
48-
LogLevel string `json:"log_level"`
49-
HtEnabled bool `json:"ht_enabled"`
50-
Debug bool `json:"debug"`
44+
FirecrackerBinaryPath string `json:"firecracker_binary_path"`
45+
KernelImagePath string `json:"kernel_image_path"`
46+
KernelArgs string `json:"kernel_args"`
47+
RootDrive string `json:"root_drive"`
48+
CPUTemplate string `json:"cpu_template"`
49+
LogLevels []string `json:"log_levels"`
50+
HtEnabled bool `json:"ht_enabled"`
5151
// If a CreateVM call specifies no network interfaces and DefaultNetworkInterfaces is non-empty,
5252
// the VM will default to using the network interfaces as specified here. This is especially
5353
// useful when a CNI-based network interface is provided in DefaultNetworkInterfaces.
@@ -57,6 +57,8 @@ type Config struct {
5757
// directory.
5858
ShimBaseDir string `json:"shim_base_dir"`
5959
JailerConfig JailerConfig `json:"jailer"`
60+
61+
DebugHelper *debug.Helper `json:"-"`
6062
}
6163

6264
// JailerConfig houses a set of configurable values for jailing
@@ -92,6 +94,11 @@ func LoadConfig(path string) (*Config, error) {
9294
},
9395
}
9496

97+
cfg.DebugHelper, err = debug.New(cfg.LogLevels...)
98+
if err != nil {
99+
return nil, err
100+
}
101+
95102
if err := json.Unmarshal(data, cfg); err != nil {
96103
return nil, errors.Wrapf(err, "failed to unmarshal config from %q", path)
97104
}

config/config.json.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"kernel_args": "console=ttyS0 noapic reboot=k panic=1 pci=off nomodules rw",
55
"root_drive": "./vsock.img",
66
"cpu_template": "T2",
7-
"log_level": "Debug",
7+
"log_levels": ["debug"],
88
"ht_enabled": false
9-
}
9+
}

docs/logging.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
## Logging Congiguration
2+
--
3+
4+
firecracker-containerd allows for users to specify per application/library
5+
logging. We do this by setting the `log_levels` field in the
6+
firecracker-runtime.json file.
7+
8+
```json
9+
{
10+
"firecracker_binary_path": "/usr/local/bin/firecracker",
11+
"kernel_image_path": "/var/lib/firecracker-containerd/runtime/default-vmlinux.bin",
12+
"kernel_args": "ro console=ttyS0 noapic reboot=k panic=1 pci=off nomodules systemd.journald.forward_to_console systemd.unit=firecracker.target init=/sbin/overlay-init",
13+
"root_drive": "/var/lib/firecracker-containerd/runtime/default-rootfs.img",
14+
"cpu_count": 1,
15+
"cpu_template": "T2",
16+
"log_levels": ["debug"],
17+
"jailer": {
18+
"runc_binary_path": "/usr/local/bin/runc"
19+
}
20+
}
21+
```
22+
23+
| log levels | description |
24+
| :---------------------------: | :-----------------------------------------------------------------------------: |
25+
| error | This will set all log levels to error |
26+
| warning | This will set all log levels to warning |
27+
| info | This will set all log levels to info |
28+
| debug | This will set all log levels to debug |
29+
| firecracker:error | Logs any error information in Firecracker's lifecycle |
30+
| firecracker:warning | Logs any error and warning information in Firecracker's lifecycle |
31+
| firecracker:info | Logs any error, warning, info information in Firecracker's lifecycle |
32+
| firecracker:debug | Most verbose log level for firecracker |
33+
| firecracker:output | Logs Firecracker's stdout and stderr. Can be used with other firecracker levels |
34+
| firecracker-go-sdk:error | Logs any errors information in firecracker-go-sdk |
35+
| firecracker-go-sdk:warning | Logs any errors or warnings in firracker-go-sdk |
36+
| firecracker-go-sdk:info | Logs any errors, warnings, or infos in firecracker-go-sdk |
37+
| firecracker-go-sdk:debug | Most verbose logging for firecracker-go-sdk |
38+
| firecracker-containerd:error | Logs any error information during the container/vm lifecycle |
39+
| firecracker-containerd:warning | Logs any error level logs along with any warn level logs |
40+
| firecracker-containerd:info | Logs any error, warn, and info level logs |
41+
| firecracker-containerd:debug | Most verbose logging for firecracker-containerd |
42+
43+
The firecracker:XX are mutually exclusive with other firecracker-YY meaning only one of the log levels can be set at a time.
44+
However, firecracker:output may be set with other firecracker:YY settings.
45+
The firecracker-containerd:XX are also mutually exclusive with other firecracker-containerd-YY levels
46+
info, error, warning, and debug are mutually exclusive and only one can be set at a time.
47+
48+
```json
49+
{
50+
"firecracker_binary_path": "/usr/local/bin/firecracker",
51+
"kernel_image_path": "/var/lib/firecracker-containerd/runtime/default-vmlinux.bin",
52+
"kernel_args": "ro console=ttyS0 noapic reboot=k panic=1 pci=off nomodules systemd.journald.forward_to_console systemd.unit=firecracker.target init=/sbin/overlay-init",
53+
"root_drive": "/var/lib/firecracker-containerd/runtime/default-rootfs.img",
54+
"cpu_count": 1,
55+
"cpu_template": "T2",
56+
"log:levels": ["info","firecracker:debug","firecracker-containerd:error"],
57+
"jailer": {
58+
"runc_binary_path": "/usr/local/bin/runc"
59+
}
60+
}
61+
```
62+
63+
The example above shows that setting the log levels to info, but specifies that
64+
firecracker to be on a debug level and firecracker-containerd to be logging at
65+
the error level

examples/etc/containerd/firecracker-runtime.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"root_drive": "/var/lib/firecracker-containerd/runtime/default-rootfs.img",
66
"cpu_count": 1,
77
"cpu_template": "T2",
8-
"log_level": "Debug",
9-
"debug": true,
8+
"log_levels": ["debug"],
109
"jailer": {
1110
"runc_binary_path": "/usr/local/bin/runc"
1211
}

0 commit comments

Comments
 (0)