Skip to content

Commit

Permalink
Sentry integration (#40)
Browse files Browse the repository at this point in the history
* No need for the github.com/pierrec/lz4/v4 work-around anymore

The fix was was merged[1] and released upstream.

[1]: pierrec/lz4#212

* Sentry integration

* Fix linter error
  • Loading branch information
edigaryev committed Jan 8, 2024
1 parent cf3af9c commit af0a42c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 12 deletions.
9 changes: 9 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,17 @@ task:
GITHUB_TOKEN: ENCRYPTED[!98ace8259c6024da912c14d5a3c5c6aac186890a8d4819fad78f3e0c41a4e0cd3a2537dd6e91493952fb056fa434be7c!]
FURY_TOKEN: ENCRYPTED[!97fe4497d9aca60a3d64904883b81e21f19706c6aedda625c97f62f67ec46b8efa74c55699956158bbf0a23726e7d9f6!]
GORELEASER_KEY: ENCRYPTED[!9b80b6ef684ceaf40edd4c7af93014ee156c8aba7e6e5795f41c482729887b5c31f36b651491d790f1f668670888d9fd!]
SENTRY_ORG: cirrus-labs
SENTRY_PROJECT: persistent-workers
SENTRY_AUTH_TOKEN: ENCRYPTED[!c16a5cf7da5f856b4bc2f21fe8cb7aa2a6c981f851c094ed4d3025fd02ea59a58a86cee8b193a69a1fc20fa217e56ac3!]
install_script:
- curl -sL https://sentry.io/get-cli/ | bash
- echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | tee /etc/apt/sources.list.d/goreleaser.list
- apt-get update
- apt-get -y install goreleaser-pro
release_script: goreleaser
create_sentry_release_script:
- export SENTRY_RELEASE="vetu@$CIRRUS_TAG"
- sentry-cli releases new $SENTRY_RELEASE
- sentry-cli releases set-commits $SENTRY_RELEASE --auto
- sentry-cli releases finalize $SENTRY_RELEASE
44 changes: 44 additions & 0 deletions cmd/vetu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,49 @@ package main

import (
"context"
"fmt"
"github.com/cirruslabs/vetu/internal/command"
"github.com/cirruslabs/vetu/internal/version"
"github.com/getsentry/sentry-go"
"log"
"os"
"os/signal"
"strings"
"time"
)

func main() {
// Initialize Sentry
var release string

if version.Version != "unknown" {
release = fmt.Sprintf("vetu@%s", version.Version)
}

err := sentry.Init(sentry.ClientOptions{
Release: release,
AttachStacktrace: true,
})
if err != nil {
log.Fatalf("failed to initialize Sentry: %v", err)
}
defer sentry.Flush(2 * time.Second)
defer sentry.Recover()

// Enrich future events with Cirrus CI-specific tags
if tags, ok := os.LookupEnv("CIRRUS_SENTRY_TAGS"); ok {
sentry.ConfigureScope(func(scope *sentry.Scope) {
for _, tag := range strings.Split(tags, ",") {
splits := strings.SplitN(tag, "=", 2)
if len(splits) != 2 {
continue
}

scope.SetTag(splits[0], splits[1])
}
})
}

// Set up a signal-interruptible context
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)

Expand All @@ -17,7 +53,15 @@ func main() {

// Run the command
if err := command.NewRootCmd().ExecuteContext(ctx); err != nil {
// Capture the error into Sentry
sentry.CaptureException(err)
sentry.Flush(2 * time.Second)

// Capture the error into stderr and terminate
cancel()

//nolint:gocritic // "log.Fatal will exit, and `defer sentry.Recover()` will not run" — it's OK,
// since we're already capturing the error above
log.Fatal(err)
}

Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ require (
github.com/distribution/reference v0.5.0
github.com/docker/cli v24.0.6+incompatible
github.com/dustin/go-humanize v1.0.1
github.com/getsentry/sentry-go v0.25.0
github.com/google/uuid v1.4.0
github.com/gosuri/uitable v0.0.4
github.com/hashicorp/go-version v1.6.0
github.com/insomniacslk/dhcp v0.0.0-20230908212754-65c27093e38a
github.com/klauspost/oui v0.0.0-20150225163751-35b4deb627f8
github.com/opencontainers/go-digest v1.0.0
github.com/otiai10/copy v1.12.0
github.com/pierrec/lz4/v4 v4.1.18
github.com/pierrec/lz4/v4 v4.1.21
github.com/projectcalico/libcalico-go v1.7.3
github.com/regclient/regclient v0.5.4
github.com/samber/lo v1.38.1
Expand All @@ -25,7 +26,7 @@ require (
github.com/testcontainers/testcontainers-go v0.26.0
github.com/vishvananda/netlink v1.2.1-beta.2
golang.org/x/crypto v0.17.0
golang.org/x/sys v0.15.0
golang.org/x/sys v0.16.0
golang.org/x/term v0.15.0
gvisor.dev/gvisor v0.0.0-20230926030033-4af66e670562
inet.af/tcpproxy v0.0.0-20221017015627-91f861402626
Expand Down Expand Up @@ -90,6 +91,7 @@ require (
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.13.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
Expand Down
14 changes: 10 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+m
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k=
github.com/getsentry/sentry-go v0.25.0 h1:q6Eo+hS+yoJlTO3uu/azhQadsD8V+jQn2D8VvX1eOyI=
github.com/getsentry/sentry-go v0.25.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
Expand Down Expand Up @@ -141,8 +145,10 @@ github.com/otiai10/copy v1.12.0/go.mod h1:rSaLseMUsZFFbsFGc7wCJnnkTAvdc5L6VWxPE4
github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks=
github.com/otiai10/mint v1.5.1/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM=
github.com/pierrec/lz4/v4 v4.1.14/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
github.com/pierrec/lz4/v4 v4.1.18 h1:xaKrnTkyoqfh1YItXl56+6KJNVYWlEEPuAQW9xsplYQ=
github.com/pierrec/lz4/v4 v4.1.18/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=
github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down Expand Up @@ -266,8 +272,8 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
Expand Down
7 changes: 1 addition & 6 deletions internal/oci/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,7 @@ func pushDisk(
}

chunker, err := chunkerpkg.NewChunker(targetDiskLayerSizeBytes, func(w io.Writer) (io.WriteCloser, error) {
lz4Writer := lz4.NewWriter(w)

// Work around https://github.com/pierrec/lz4/pull/212
_, _ = lz4Writer.Write([]byte{})

return lz4Writer, nil
return lz4.NewWriter(w), nil
})
if err != nil {
return []types.Descriptor{}, err
Expand Down

0 comments on commit af0a42c

Please sign in to comment.