Skip to content

Commit

Permalink
fix(runtime): Handle panic and log stack trace during resource provis…
Browse files Browse the repository at this point in the history
…ioning, identity store sync, data source sync, tag sync, data usage sync and data access sync. (#356)

* fix(runtime): Handle panic and log stack trace during resource provisioning, identity store sync, data source sync, tag sync, data usage sync and data access sync.

* Improve error handling
  • Loading branch information
rmennes authored Jul 22, 2024
1 parent dbacfbc commit f69a70a
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 3 deletions.
13 changes: 13 additions & 0 deletions base/wrappers/data_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package wrappers
import (
"context"
"fmt"
"runtime/debug"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -68,6 +69,12 @@ func (s *DataAccessSyncFunction) SyncFromTarget(ctx context.Context, config *acc
if err != nil {
logger.Error(fmt.Sprintf("Failure during access provider sync from target: %v", err))
}

if r := recover(); r != nil {
err = fmt.Errorf("panic during access provider sync from target: %v", r)

logger.Error(fmt.Sprintf("Panic during access provider sync from target: %v\n\n%s", r, string(debug.Stack())))
}
}()

logger.Info("Starting data access synchronisation from target")
Expand Down Expand Up @@ -104,6 +111,12 @@ func (s *DataAccessSyncFunction) SyncToTarget(ctx context.Context, config *acces
if err != nil {
logger.Error(fmt.Sprintf("Failure during access provider sync to target: %v", err))
}

if r := recover(); r != nil {
err = fmt.Errorf("panic during access provider sync to target: %v", r)

logger.Error(fmt.Sprintf("Panic during access provider sync to target: %v\n\n%s", r, string(debug.Stack())))
}
}()

logger.Info("Starting data access synchronisation to target")
Expand Down
15 changes: 14 additions & 1 deletion base/wrappers/data_object_enricher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"runtime/debug"

"github.com/raito-io/cli/base/data_object_enricher"
"github.com/raito-io/cli/base/data_source"
Expand Down Expand Up @@ -43,9 +44,21 @@ type dataObjectEnricherFunction struct {
enricher SyncFactory[config.ConfigMap, DataObjectEnricherI]
}

func (f *dataObjectEnricherFunction) Enrich(ctx context.Context, config *data_object_enricher.DataObjectEnricherConfig) (*data_object_enricher.DataObjectEnricherResult, error) {
func (f *dataObjectEnricherFunction) Enrich(ctx context.Context, config *data_object_enricher.DataObjectEnricherConfig) (_ *data_object_enricher.DataObjectEnricherResult, err error) {
logger.Info("Enriching data objects...")

defer func() {
if err != nil {
logger.Error(fmt.Sprintf("Failure during data object enrich: %v", err))
}

if r := recover(); r != nil {
err = fmt.Errorf("panic during data object enrich: %v", r)

logger.Error(fmt.Sprintf("Panic during data object enrich: %v\n\n%s", r, string(debug.Stack())))
}
}()

fileCreator, err := data_source.NewDataSourceFileCreator(&data_source.DataSourceSyncConfig{
TargetFile: config.OutputFile,
DataSourceId: "",
Expand Down
7 changes: 7 additions & 0 deletions base/wrappers/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package wrappers
import (
"context"
"fmt"
"runtime/debug"
"time"

"github.com/raito-io/cli/base/data_source"
Expand Down Expand Up @@ -48,6 +49,12 @@ func (s *dataSourceSyncFunction) SyncDataSource(ctx context.Context, config *dat
if err != nil {
logger.Error(fmt.Sprintf("Failure during data source sync: %v", err))
}

if r := recover(); r != nil {
err = fmt.Errorf("panic during data source sync: %v", r)

logger.Error(fmt.Sprintf("Panic during data source sync: %v\n\n%s", r, string(debug.Stack())))
}
}()

logger.Info("Starting data source synchronisation")
Expand Down
7 changes: 7 additions & 0 deletions base/wrappers/data_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package wrappers
import (
"context"
"fmt"
"runtime/debug"

"github.com/raito-io/cli/base/data_usage"
"github.com/raito-io/cli/base/util/config"
Expand Down Expand Up @@ -44,6 +45,12 @@ func (s *dataUsageSyncFunction) SyncDataUsage(ctx context.Context, config *data_
if err != nil {
logger.Error(fmt.Sprintf("Failure during data usage sync: %v", err))
}

if r := recover(); r != nil {
err = fmt.Errorf("panic during data usage sync: %v", r)

logger.Error(fmt.Sprintf("Panic during data usage sync: %v\n\n%s", r, string(debug.Stack())))
}
}()

logger.Info("Starting data usage synchronisation")
Expand Down
7 changes: 7 additions & 0 deletions base/wrappers/identity_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package wrappers
import (
"context"
"fmt"
"runtime/debug"

"github.com/raito-io/cli/base/identity_store"
"github.com/raito-io/cli/base/util/config"
Expand Down Expand Up @@ -45,6 +46,12 @@ func (s *identityStoreSyncFunction) SyncIdentityStore(ctx context.Context, confi
if err != nil {
logger.Error(fmt.Sprintf("Failure during identity store sync: %v", err))
}

if r := recover(); r != nil {
err = fmt.Errorf("panic during identity store sync: %v", r)

logger.Error(fmt.Sprintf("Panic during identity store sync: %v\n\n%s", r, string(debug.Stack())))
}
}()

logger.Info("Starting identity store synchronisation")
Expand Down
13 changes: 11 additions & 2 deletions base/wrappers/resource_provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package wrappers
import (
"context"
"fmt"
"runtime/debug"
"time"

"github.com/raito-io/cli/base/resource_provider"
Expand Down Expand Up @@ -30,13 +31,21 @@ func ResourceProviderSync(syncer ResourceProviderSyncer) resource_provider.Resou
return ResourceProviderSyncFactory(NewDummySyncFactoryFn[resource_provider.UpdateResourceInput](syncer))
}

func (r *ResourceProvisionSyncFunction) UpdateResources(ctx context.Context, config *resource_provider.UpdateResourceInput) (*resource_provider.UpdateResourceResult, error) {
func (r *ResourceProvisionSyncFunction) UpdateResources(ctx context.Context, config *resource_provider.UpdateResourceInput) (_ *resource_provider.UpdateResourceResult, err error) {
logger.Info("Starting resource provisioning")

start := time.Now()

defer func() {
logger.Info(fmt.Sprintf("Finished resource provisioning in %s", time.Since(start)))
if err != nil {
logger.Error(fmt.Sprintf("Failure during resource provisioning: %v", err))
} else if r := recover(); r != nil {
err = fmt.Errorf("panic during resource provisioning: %v", r)

logger.Error(fmt.Sprintf("Panic during resource provisioning: %v\n\n%s", r, string(debug.Stack())))
} else {
logger.Info(fmt.Sprintf("Finished resource provisioning in %s", time.Since(start)))
}
}()

syncer, err := r.syncer.Create(ctx, config)
Expand Down
7 changes: 7 additions & 0 deletions base/wrappers/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package wrappers
import (
"context"
"fmt"
"runtime/debug"
"time"

"github.com/raito-io/cli/base/tag"
Expand Down Expand Up @@ -38,6 +39,12 @@ func (t *tagSyncFunction) SyncTags(ctx context.Context, config *tag.TagSyncConfi
if err != nil {
logger.Error(fmt.Sprintf("Failure during tag sync: %v", err))
}

if r := recover(); r != nil {
err = fmt.Errorf("panic during tag sync: %v", r)

logger.Error(fmt.Sprintf("Panic during tag sync: %v\n\n%s", r, string(debug.Stack())))
}
}()

logger.Info("Starting tag synchronisation")
Expand Down

0 comments on commit f69a70a

Please sign in to comment.