Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sentry to grid deployer #1269

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions grid-cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ require (
github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/ethereum/go-ethereum v1.11.6 // indirect
github.com/getsentry/sentry-go v0.29.1 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/gomodule/redigo v2.0.0+incompatible // indirect
Expand Down Expand Up @@ -53,6 +54,7 @@ require (
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20200609130330-bd2cb7843e1b // indirect
gonum.org/v1/gonum v0.15.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
Expand Down
8 changes: 8 additions & 0 deletions grid-cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnN
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
github.com/ethereum/go-ethereum v1.11.6 h1:2VF8Mf7XiSUfmoNOy3D+ocfl9Qu8baQBrCNbo2CXQ8E=
github.com/ethereum/go-ethereum v1.11.6/go.mod h1:+a8pUj1tOyJ2RinsNQD4326YS+leSoKGiG/uVVb0x6Y=
github.com/getsentry/sentry-go v0.29.1 h1:DyZuChN8Hz3ARxGVV8ePaNXh1dQ7d76AiB117xcREwA=
github.com/getsentry/sentry-go v0.29.1/go.mod h1:x3AtIzN01d6SiWkderzaH28Tm0lgkafpJ5Bm3li39O0=
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/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
Expand Down Expand Up @@ -93,6 +97,8 @@ github.com/mimoo/StrobeGo v0.0.0-20220103164710-9a04d6ca976b h1:QrHweqAtyJ9EwCaG
github.com/mimoo/StrobeGo v0.0.0-20220103164710-9a04d6ca976b/go.mod h1:xxLb2ip6sSUts3g1irPVHyk/DGslwQsNOo9I7smJfNU=
github.com/pierrec/xxHash v0.1.5 h1:n/jBpwTHiER4xYvK3/CdPVnLDPchj8eTJFFLUb4QHBo=
github.com/pierrec/xxHash v0.1.5/go.mod h1:w2waW5Zoa/Wc4Yqe0wgrIYAGKqRMf7czn2HNKXmuL+I=
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/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down Expand Up @@ -161,6 +167,8 @@ golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.zx2c4.com/wireguard v0.0.20200121/go.mod h1:P2HsVp8SKwZEufsnezXZA4GRX/T49/HlU7DGuelXsU4=
Expand Down
30 changes: 15 additions & 15 deletions grid-client/deployer/deployment_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ func NewDeploymentDeployer(tfPluginClient *TFPluginClient) DeploymentDeployer {
// Validate validates a deployment deployer
func (d *DeploymentDeployer) Validate(ctx context.Context, dls []*workloads.Deployment) error {
if err := validateAccountBalanceForExtrinsics(d.tfPluginClient.SubstrateConn, d.tfPluginClient.Identity); err != nil {
return err
return d.tfPluginClient.sentry.error(err)
}

for _, dl := range dls {
if err := dl.Validate(); err != nil {
return err
return d.tfPluginClient.sentry.error(err)
}
}

return nil
}

// GenerateVersionlessDeployments generates a new deployment without a version
func (d *DeploymentDeployer) GenerateVersionlessDeployments(ctx context.Context, dls []*workloads.Deployment) (map[uint32][]zos.Deployment, error) {
func (d *DeploymentDeployer) generateVersionlessDeployments(ctx context.Context, dls []*workloads.Deployment) (map[uint32][]zos.Deployment, error) {
gridDlsPerNodes := make(map[uint32][]zos.Deployment)

var wg sync.WaitGroup
Expand Down Expand Up @@ -109,16 +109,16 @@ func (d *DeploymentDeployer) GenerateVersionlessDeployments(ctx context.Context,
// Deploy deploys a new deployment
func (d *DeploymentDeployer) Deploy(ctx context.Context, dl *workloads.Deployment) error {
if err := d.Validate(ctx, []*workloads.Deployment{dl}); err != nil {
return fmt.Errorf("invalid deployment: %w", err)
return d.tfPluginClient.sentry.error(fmt.Errorf("invalid deployment: %w", err))
}

dlsPerNodes, err := d.GenerateVersionlessDeployments(ctx, []*workloads.Deployment{dl})
dlsPerNodes, err := d.generateVersionlessDeployments(ctx, []*workloads.Deployment{dl})
if err != nil {
return errors.Wrap(err, "could not generate deployments data")
return d.tfPluginClient.sentry.error(errors.Wrap(err, "could not generate deployments data"))
}

if len(dlsPerNodes[dl.NodeID]) == 0 {
return fmt.Errorf("failed to generate the grid deployment")
return d.tfPluginClient.sentry.error(fmt.Errorf("failed to generate the grid deployment"))
}

dl.NodeDeploymentID, err = d.deployer.Deploy(
Expand All @@ -134,7 +134,7 @@ func (d *DeploymentDeployer) Deploy(ctx context.Context, dl *workloads.Deploymen
d.tfPluginClient.State.StoreContractIDs(dl.NodeID, dl.ContractID)
}

return err
return d.tfPluginClient.sentry.error(err)
}

// BatchDeploy deploys multiple deployments using the deployer
Expand All @@ -146,13 +146,13 @@ func (d *DeploymentDeployer) BatchDeploy(ctx context.Context, dls []*workloads.D
multiErr = multierror.Append(multiErr, fmt.Errorf("invalid deployments: %w", err))
}

newDeployments, err := d.GenerateVersionlessDeployments(ctx, dls)
newDeployments, err := d.generateVersionlessDeployments(ctx, dls)
if err != nil {
multiErr = multierror.Append(multiErr, fmt.Errorf("could not generate grid deployments: %w", err))
}

if len(newDeployments) == 0 {
return errors.Wrap(multiErr, "failed to generate the grid deployments")
return d.tfPluginClient.sentry.error(errors.Wrap(multiErr, "failed to generate the grid deployments"))
}

newDls, err := d.deployer.BatchDeploy(ctx, newDeployments, newDeploymentsSolutionProvider)
Expand All @@ -168,18 +168,18 @@ func (d *DeploymentDeployer) BatchDeploy(ctx context.Context, dls []*workloads.D
}
}

return multiErr
return d.tfPluginClient.sentry.error(multiErr)
}

// Cancel cancels deployments
func (d *DeploymentDeployer) Cancel(ctx context.Context, dl *workloads.Deployment) error {
if err := d.Validate(ctx, []*workloads.Deployment{dl}); err != nil {
return err
return d.tfPluginClient.sentry.error(err)
}

err := d.deployer.Cancel(ctx, dl.ContractID)
if err != nil {
return err
return d.tfPluginClient.sentry.error(err)
}

// update state
Expand Down Expand Up @@ -383,11 +383,11 @@ func (d *DeploymentDeployer) syncContract(dl *workloads.Deployment) error {
func (d *DeploymentDeployer) Sync(ctx context.Context, dl *workloads.Deployment) error {
err := d.syncContract(dl)
if err != nil {
return err
return d.tfPluginClient.sentry.error(err)
}
currentDeployments, err := d.deployer.GetDeployments(ctx, dl.NodeDeploymentID)
if err != nil {
return errors.Wrap(err, "failed to get deployments to update local state")
return d.tfPluginClient.sentry.error(errors.Wrap(err, "failed to get deployments to update local state"))
}

deployment := currentDeployments[dl.NodeID]
Expand Down
4 changes: 2 additions & 2 deletions grid-client/deployer/deployment_deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func TestDeploymentDeployerDeploy(t *testing.T) {
return nil
}).AnyTimes()

dls, err := d.GenerateVersionlessDeployments(context.Background(), []*workloads.Deployment{&dl})
dls, err := d.generateVersionlessDeployments(context.Background(), []*workloads.Deployment{&dl})
assert.NoError(t, err)

assert.Equal(t, len(gridDl.Workloads), len(dls[dl.NodeID][0].Workloads))
Expand Down Expand Up @@ -528,7 +528,7 @@ func TestDeploymentDeployerSync(t *testing.T) {
return nil
})

dls, err := d.GenerateVersionlessDeployments(context.Background(), []*workloads.Deployment{&dl})
dls, err := d.generateVersionlessDeployments(context.Background(), []*workloads.Deployment{&dl})
assert.NoError(t, err)

gridDl := dls[dl.NodeID][0]
Expand Down
42 changes: 21 additions & 21 deletions grid-client/deployer/gateway_fqdn_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,32 @@ func NewGatewayFqdnDeployer(tfPluginClient *TFPluginClient) GatewayFQDNDeployer
func (d *GatewayFQDNDeployer) Validate(ctx context.Context, gw *workloads.GatewayFQDNProxy) error {
sub := d.tfPluginClient.SubstrateConn
if err := validateAccountBalanceForExtrinsics(sub, d.tfPluginClient.Identity); err != nil {
return err
return d.tfPluginClient.sentry.error(err)
}

if err := gw.Validate(); err != nil {
return err
return d.tfPluginClient.sentry.error(err)
}

nodeClient, err := d.tfPluginClient.NcPool.GetNodeClient(sub, gw.NodeID)
if err != nil {
return errors.Wrapf(err, "failed to get node client with ID %d", gw.NodeID)
return d.tfPluginClient.sentry.error(errors.Wrapf(err, "failed to get node client with ID %d", gw.NodeID))
}

cfg, err := nodeClient.NetworkGetPublicConfig(ctx)
if err != nil {
return errors.Wrapf(err, "couldn't get node %d public config", gw.NodeID)
return d.tfPluginClient.sentry.error(errors.Wrapf(err, "couldn't get node %d public config", gw.NodeID))
}

if cfg.IPv4.IP == nil {
return errors.Errorf("node %d doesn't contain a public IP in its public config", gw.NodeID)
return d.tfPluginClient.sentry.error(errors.Errorf("node %d doesn't contain a public IP in its public config", gw.NodeID))
}

return client.AreNodesUp(ctx, sub, []uint32{gw.NodeID}, d.tfPluginClient.NcPool)
return d.tfPluginClient.sentry.error(client.AreNodesUp(ctx, sub, []uint32{gw.NodeID}, d.tfPluginClient.NcPool))
}

// GenerateVersionlessDeployments generates deployments for gatewayFqdn deployer without versions
func (d *GatewayFQDNDeployer) GenerateVersionlessDeployments(ctx context.Context, gw *workloads.GatewayFQDNProxy) (map[uint32]zosTypes.Deployment, error) {
func (d *GatewayFQDNDeployer) generateVersionlessDeployments(ctx context.Context, gw *workloads.GatewayFQDNProxy) (map[uint32]zosTypes.Deployment, error) {
deployments := make(map[uint32]zosTypes.Deployment)
var err error

Expand All @@ -74,12 +74,12 @@ func (d *GatewayFQDNDeployer) GenerateVersionlessDeployments(ctx context.Context
// Deploy deploys the GatewayFQDN deployments using the deployer
func (d *GatewayFQDNDeployer) Deploy(ctx context.Context, gw *workloads.GatewayFQDNProxy) error {
if err := d.Validate(ctx, gw); err != nil {
return err
return d.tfPluginClient.sentry.error(err)
}

newDeployments, err := d.GenerateVersionlessDeployments(ctx, gw)
newDeployments, err := d.generateVersionlessDeployments(ctx, gw)
if err != nil {
return errors.Wrap(err, "could not generate deployments data")
return d.tfPluginClient.sentry.error(errors.Wrap(err, "could not generate deployments data"))
}

// TODO: solution providers
Expand All @@ -97,7 +97,7 @@ func (d *GatewayFQDNDeployer) Deploy(ctx context.Context, gw *workloads.GatewayF
}
}

return err
return d.tfPluginClient.sentry.error(err)
}

// BatchDeploy deploys multiple deployments using the deployer
Expand All @@ -107,12 +107,12 @@ func (d *GatewayFQDNDeployer) BatchDeploy(ctx context.Context, gws []*workloads.

for _, gw := range gws {
if err := d.Validate(ctx, gw); err != nil {
return err
return d.tfPluginClient.sentry.error(err)
}

dls, err := d.GenerateVersionlessDeployments(ctx, gw)
dls, err := d.generateVersionlessDeployments(ctx, gw)
if err != nil {
return errors.Wrap(err, "could not generate deployments data")
return d.tfPluginClient.sentry.error(errors.Wrap(err, "could not generate deployments data"))
}

for nodeID, dl := range dls {
Expand All @@ -133,23 +133,23 @@ func (d *GatewayFQDNDeployer) BatchDeploy(ctx context.Context, gws []*workloads.
// error is not returned immediately before updating state because of untracked failed deployments
for _, gw := range gws {
if err := d.updateStateFromDeployments(gw, newDls); err != nil {
return errors.Wrapf(err, "failed to update gateway fqdn '%s' state", gw.Name)
return d.tfPluginClient.sentry.error(errors.Wrapf(err, "failed to update gateway fqdn '%s' state", gw.Name))
}
}

return err
return d.tfPluginClient.sentry.error(err)
}

// Cancel cancels a gateway deployment
func (d *GatewayFQDNDeployer) Cancel(ctx context.Context, gw *workloads.GatewayFQDNProxy) (err error) {
if err := d.Validate(ctx, gw); err != nil {
return err
return d.tfPluginClient.sentry.error(err)
}

contractID := gw.NodeDeploymentID[gw.NodeID]
err = d.deployer.Cancel(ctx, contractID)
if err != nil {
return err
return d.tfPluginClient.sentry.error(err)
}

// update state
Expand Down Expand Up @@ -198,12 +198,12 @@ func (d *GatewayFQDNDeployer) syncContracts(ctx context.Context, gw *workloads.G
// Sync syncs the gateway deployments
func (d *GatewayFQDNDeployer) Sync(ctx context.Context, gw *workloads.GatewayFQDNProxy) error {
if err := d.syncContracts(ctx, gw); err != nil {
return errors.Wrap(err, "could not sync contracts")
return d.tfPluginClient.sentry.error(errors.Wrap(err, "could not sync contracts"))
}

dls, err := d.deployer.GetDeployments(ctx, gw.NodeDeploymentID)
if err != nil {
return errors.Wrap(err, "could not get deployment objects")
return d.tfPluginClient.sentry.error(errors.Wrap(err, "could not get deployment objects"))
}

dl := dls[gw.NodeID]
Expand All @@ -225,7 +225,7 @@ func (d *GatewayFQDNDeployer) Sync(ctx context.Context, gw *workloads.GatewayFQD
gw.Network = gwWorkload.Network

if err != nil {
return err
return d.tfPluginClient.sentry.error(err)
}
}

Expand Down
12 changes: 6 additions & 6 deletions grid-client/deployer/gateway_fqdn_deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func TestFQDNDeployer(t *testing.T) {
})

t.Run("test generate", func(t *testing.T) {
dls, err := d.GenerateVersionlessDeployments(context.Background(), &gw)
dls, err := d.generateVersionlessDeployments(context.Background(), &gw)
assert.NoError(t, err)

testDl := workloads.NewGridDeployment(twinID, 0, []zosTypes.Workload{
Expand All @@ -151,7 +151,7 @@ func TestFQDNDeployer(t *testing.T) {
})

t.Run("test deploy", func(t *testing.T) {
dls, err := d.GenerateVersionlessDeployments(context.Background(), &gw)
dls, err := d.generateVersionlessDeployments(context.Background(), &gw)
assert.NoError(t, err)

mockValidation(d.tfPluginClient.Identity, cl, sub, ncPool, proxyCl)
Expand All @@ -175,7 +175,7 @@ func TestFQDNDeployer(t *testing.T) {

gw.NodeDeploymentID = map[uint32]uint64{nodeID: contractID}

dls, err := d.GenerateVersionlessDeployments(context.Background(), &gw)
dls, err := d.generateVersionlessDeployments(context.Background(), &gw)
assert.NoError(t, err)

mockValidation(d.tfPluginClient.Identity, cl, sub, ncPool, proxyCl)
Expand All @@ -198,7 +198,7 @@ func TestFQDNDeployer(t *testing.T) {

gw.NodeDeploymentID = map[uint32]uint64{nodeID: contractID}

dls, err := d.GenerateVersionlessDeployments(context.Background(), &gw)
dls, err := d.generateVersionlessDeployments(context.Background(), &gw)
assert.NoError(t, err)

mockValidation(d.tfPluginClient.Identity, cl, sub, ncPool, proxyCl)
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestFQDNDeployer(t *testing.T) {
gw.ContractID = contractID
gw.NodeDeploymentID = map[uint32]uint64{nodeID: contractID}

dls, err := d.GenerateVersionlessDeployments(context.Background(), &gw)
dls, err := d.generateVersionlessDeployments(context.Background(), &gw)
assert.NoError(t, err)

dl := dls[nodeID]
Expand Down Expand Up @@ -346,7 +346,7 @@ func TestFQDNDeployer(t *testing.T) {
gw.ContractID = contractID
gw.NodeDeploymentID = map[uint32]uint64{nodeID: contractID}

dls, err := d.GenerateVersionlessDeployments(context.Background(), &gw)
dls, err := d.generateVersionlessDeployments(context.Background(), &gw)
assert.NoError(t, err)

dl := dls[nodeID]
Expand Down
Loading
Loading