Skip to content

Commit

Permalink
feat: print debug runtime information
Browse files Browse the repository at this point in the history
  • Loading branch information
joshiste committed Aug 21, 2023
1 parent 1e9dcf5 commit 210eb3e
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 1.8.6

- add LogRuntimeInformation

## 1.8.5

- log tls errors on debug

## 1.8.4

- Support loading client certificates from directories
Expand Down
19 changes: 19 additions & 0 deletions extruntime/extruntime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package extruntime

import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"os"
"runtime"
)

func LogRuntimeInformation(level zerolog.Level) {
if !log.WithLevel(level).Enabled() {
return
}

log.WithLevel(level).Msgf("Go Runtime information: os=%s; arch=%s", runtime.GOOS, runtime.GOARCH)
log.WithLevel(level).Msgf("Process information: pid=%d; uid=%d; gid=%d", os.Getpid(), os.Getuid(), os.Getgid())
logCapsInformation(level)
logSeccompInformation(level)
}
13 changes: 13 additions & 0 deletions extruntime/extruntime_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build darwin

package extruntime

import (
"github.com/rs/zerolog"
)

func logCapsInformation(_ zerolog.Level) {
}

func logSeccompInformation(_ zerolog.Level) {
}
42 changes: 42 additions & 0 deletions extruntime/extruntime_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//go:build linux

package extruntime

import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/seccomp/libseccomp-golang"
"os"
"os/exec"
"strconv"
)

func logCapsInformation(level zerolog.Level) {
caps, err := exec.Command("getpcaps", strconv.Itoa(os.Getpid())).CombinedOutput()
if err != nil {
log.WithLevel(level).Msgf("Process capabilities: %s", string(caps))
} else {
log.WithLevel(level).Msgf("Process capabilities: %s", err)
}
}
func logSeccompInformation(level zerolog.Level) {
ctx, err := seccomp.NewContext(seccomp.ActLog)
if err != nil {
log.WithLevel(level).Msgf("Seccomp: %s", err)
return
}
defer ctx.Release()

if err := ctx.Load(); err != nil {
log.WithLevel(level).Msgf("Seccomp: %s", err)
return
}

mode, err := ctx.GetMode()
if err != nil {
log.WithLevel(level).Msgf("Seccomp: %s", err)
return
}

log.WithLevel(level).Msgf("Seccomp: mode=%s", err)
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/madflojo/testcerts v1.1.0
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5
github.com/rs/zerolog v1.27.0
github.com/seccomp/libseccomp-golang v0.10.0
github.com/stretchr/testify v1.8.0
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.27.0 h1:1T7qCieN22GVc8S4Q2yuexzBb1EqjbgjSH9RohbMjKs=
github.com/rs/zerolog v1.27.0/go.mod h1:7frBqO0oezxmnO7GF86FY++uy8I0Tk/If5ni1G9Qc0U=
github.com/seccomp/libseccomp-golang v0.10.0 h1:aA4bp+/Zzi0BnWZ2F1wgNBs5gTpm+na2rWM6M9YjLpY=
github.com/seccomp/libseccomp-golang v0.10.0/go.mod h1:JA8cRccbGaA1s33RQf7Y1+q9gHmZX1yB/z9WDN1C6fg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down

0 comments on commit 210eb3e

Please sign in to comment.