From 731467742d0a5dc9b522886f675b57b0bc3956a6 Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Wed, 17 Jan 2024 17:48:35 +0100 Subject: [PATCH 1/3] gvproxy: Add more context to errors Some errors are currently not logged, or without much context. This commit adds prefixes to some of these, to make it easier to understand the codepaths which caused gvproxy to exit. Signed-off-by: Christophe Fergeau --- cmd/gvproxy/main.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/cmd/gvproxy/main.go b/cmd/gvproxy/main.go index 8e534a25f..a2efaa428 100644 --- a/cmd/gvproxy/main.go +++ b/cmd/gvproxy/main.go @@ -274,7 +274,7 @@ func main() { }) // Wait for all of the go funcs to finish up if err := groupErrs.Wait(); err != nil { - log.Error(err) + log.Errorf("gvproxy exiting: %v", err) exitCode = 1 } } @@ -341,7 +341,7 @@ func run(ctx context.Context, g *errgroup.Group, configuration *types.Configurat if vpnkitSocket != "" { vpnkitListener, err := transport.Listen(vpnkitSocket) if err != nil { - return err + return errors.Wrap(err, "vpnkit listen error") } g.Go(func() error { vpnloop: @@ -368,7 +368,7 @@ func run(ctx context.Context, g *errgroup.Group, configuration *types.Configurat if qemuSocket != "" { qemuListener, err := transport.Listen(qemuSocket) if err != nil { - return err + return errors.Wrap(err, "qemu listen error") } g.Go(func() error { @@ -383,7 +383,6 @@ func run(ctx context.Context, g *errgroup.Group, configuration *types.Configurat conn, err := qemuListener.Accept() if err != nil { return errors.Wrap(err, "qemu accept error") - } return vn.AcceptQemu(ctx, conn) }) @@ -392,7 +391,7 @@ func run(ctx context.Context, g *errgroup.Group, configuration *types.Configurat if bessSocket != "" { bessListener, err := transport.Listen(bessSocket) if err != nil { - return err + return errors.Wrap(err, "bess listen error") } g.Go(func() error { @@ -416,7 +415,7 @@ func run(ctx context.Context, g *errgroup.Group, configuration *types.Configurat if vfkitSocket != "" { conn, err := transport.ListenUnixgram(vfkitSocket) if err != nil { - return err + return errors.Wrap(err, "vfkit listen error") } g.Go(func() error { @@ -430,7 +429,7 @@ func run(ctx context.Context, g *errgroup.Group, configuration *types.Configurat g.Go(func() error { vfkitConn, err := transport.AcceptVfkit(conn) if err != nil { - return err + return errors.Wrap(err, "vfkit accept error") } return vn.AcceptVfkit(ctx, vfkitConn) }) From 6ded4a2960d2af71026717803ece1e78c6fa1a76 Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Thu, 18 Jan 2024 12:28:17 +0100 Subject: [PATCH 2/3] Improve versioning from shallow git clones if an annotated tag is found, the git describe string will be similar to: v0.7.2-15-g2c897d90 When using shallow clones, the commit being built may not have an annotated tag in its history, `git describe` will only be the abbreviated commit hash in this case: 2c897d90 This commit tries to detect these situations, and adds a 'git' prefix to the hash in these cases to make the version info look a bit better: $ gvproxy --version: gvproxy version git2c897d90 Signed-off-by: Christophe Fergeau --- pkg/types/version.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/types/version.go b/pkg/types/version.go index 845ba439b..c371601c5 100644 --- a/pkg/types/version.go +++ b/pkg/types/version.go @@ -45,6 +45,16 @@ func moduleVersion() string { return gitArchiveVersion // This will be set when building from git using make case gitVersion != "": + if !strings.HasPrefix(gitVersion, "v") { + // if an annotated tag is found, the git describe string will be similar to: + // v0.7.2-15-g2c897d90 + // When using shallow clones, the commit being built + // may not have an annotated tag in its history, + // `git describe` will only be the abbreviated commit hash in this case: + // 2c897d90 + return fmt.Sprintf("git%s", gitVersion) + + } return gitVersion // moduleVersionFromBuildInfo() will be set when using `go install` default: From 2d837fd505c3bf76f6b583344f8cb55ebc6c5be9 Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Mon, 22 Jan 2024 14:59:35 +0100 Subject: [PATCH 3/3] ghactions: Fix version generation for ghactions builds gvproxy --version uses the `git describe` to automatically generate the version. actions/checkout by default creates a 1 commit checkout with no history/no tags, which will prevent git describe from generating a useful version. This commit instructs actions/checkout to use full checkouts with all tags. Signed-off-by: Christophe Fergeau --- .github/workflows/go.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index f45b41833..2de018cea 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -17,6 +17,9 @@ jobs: go-version: ["1.20.x", "1.21.x", "1.22.0-rc.1"] steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 # history/tags are needed for automatic version generation + fetch-tags: true - name: Set up Go uses: actions/setup-go@v3