Skip to content

Commit 451f195

Browse files
committed
Trace HTTP requests to Firecracker in debug mode
1 parent 2cb0a5f commit 451f195

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

cmd/firectl/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,15 @@ func main() {
204204
CPUTemplate: firecracker.CPUTemplate(opts.FcCPUTemplate),
205205
HtEnabled: !opts.FcDisableHt,
206206
MemInMiB: opts.FcMemSz,
207+
Debug: opts.Debug,
207208
}
208209

209210
err = checkConfig(fcCfg)
210211
if err != nil {
211212
log.Fatalf("Configuration error: %s", err)
212213
}
213214

214-
m := firecracker.NewMachine(fcCfg, firecracker.WithLogger(logger))
215+
m := firecracker.NewMachine(fcCfg, firecracker.WithLogger(log.NewEntry(logger)))
215216

216217
ctx := context.Background()
217218
vmmCtx, vmmCancel := context.WithCancel(ctx)

firecracker.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"net/http"
2020
"time"
2121

22+
"github.com/sirupsen/logrus"
2223
"github.com/go-openapi/strfmt"
2324

2425
"github.com/firecracker-microvm/firecracker-go-sdk/client"
@@ -33,7 +34,7 @@ type FirecrackerClient struct {
3334
client *client.Firecracker
3435
}
3536

36-
func NewFirecrackerClient(socketPath string) *FirecrackerClient {
37+
func NewFirecrackerClient(socketPath string, logger *logrus.Entry, debug bool) *FirecrackerClient {
3738
httpClient := client.NewHTTPClient(strfmt.NewFormats())
3839

3940
socketTransport := &http.Transport{
@@ -49,6 +50,15 @@ func NewFirecrackerClient(socketPath string) *FirecrackerClient {
4950

5051
transport := httptransport.New(client.DefaultHost, client.DefaultBasePath, client.DefaultSchemes)
5152
transport.Transport = socketTransport
53+
54+
if debug {
55+
transport.SetDebug(debug)
56+
}
57+
58+
if logger != nil {
59+
transport.SetLogger(logger)
60+
}
61+
5262
httpClient.SetTransport(transport)
5363

5464
return &FirecrackerClient{client: httpClient}

machine.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ type Config struct {
8080
NetworkInterfaces []NetworkInterface
8181
VsockDevices []VsockDevice
8282
Console string
83+
Debug bool
8384
machineCfg models.MachineConfiguration
8485
}
8586

@@ -143,11 +144,17 @@ func NewMachine(cfg Config, opts ...Opt) *Machine {
143144
}
144145

145146
if m.logger == nil {
146-
m.logger = log.NewEntry(log.New())
147+
logger := log.New()
148+
149+
if cfg.Debug {
150+
logger.SetLevel(log.DebugLevel)
151+
}
152+
153+
m.logger = log.NewEntry(logger)
147154
}
148155

149156
if m.client == nil {
150-
m.client = NewFirecrackerClient(cfg.SocketPath)
157+
m.client = NewFirecrackerClient(cfg.SocketPath, m.logger, cfg.Debug)
151158
}
152159

153160
m.logger.Debug("Called NewMachine()")

machine_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func init() {
3939

4040
// Ensure that we can create a new machine
4141
func TestNewMachine(t *testing.T) {
42-
m := NewMachine(Config{})
42+
m := NewMachine(Config{Debug: true})
4343
if m == nil {
4444
t.Errorf("NewMachine did not create a Machine")
4545
}
@@ -62,6 +62,7 @@ func TestMicroVMExecution(t *testing.T) {
6262
CPUCount: nCpus,
6363
CPUTemplate: cpuTemplate,
6464
MemInMiB: memSz,
65+
Debug: true,
6566
}
6667
m := NewMachine(cfg)
6768
ctx := context.Background()

0 commit comments

Comments
 (0)