Skip to content

Commit

Permalink
error reporting for dump
Browse files Browse the repository at this point in the history
  • Loading branch information
jt-dd committed Nov 20, 2024
1 parent 83cd922 commit bc31a94
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pkg/kubehound/core/core_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ func DumpCore(ctx context.Context, khCfg *config.KubehoundConfig, upload bool) (
l := log.Logger(ctx)

clusterName, err := config.GetClusterName(ctx)
defer func() {
if err != nil {
errMsg := fmt.Errorf("fatal error: %w", err)
l.Error("Error occurred", log.ErrorField(errMsg))
_ = events.PushEvent(ctx, events.DumpFailed, fmt.Sprintf("%s", errMsg))
}
}()
if err != nil {
return "", fmt.Errorf("collector cluster info: %w", err)
}
Expand All @@ -36,6 +43,7 @@ func DumpCore(ctx context.Context, khCfg *config.KubehoundConfig, upload bool) (

span, ctx := span.SpanRunFromContext(ctx, span.DumperLaunch)
span.SetTag(ext.ManualKeep, true)
l = log.Logger(ctx)
defer func() {
span.Finish(tracer.WithError(err))
}()
Expand All @@ -53,12 +61,15 @@ func DumpCore(ctx context.Context, khCfg *config.KubehoundConfig, upload bool) (
if upload {
// Clean up the temporary directory when done
defer func() {
err = os.RemoveAll(khCfg.Collector.File.Directory)
err := os.RemoveAll(khCfg.Collector.File.Directory)
if err != nil {
errMsg := fmt.Errorf("Failed to remove temporary directory: %w", err)
l.Error("Failed to remove temporary directory", log.ErrorField(err))
_ = events.PushEvent(ctx, events.DumpFailed, fmt.Sprintf("%s", errMsg))
}
}()
puller, err := blob.NewBlobStorage(khCfg, khCfg.Ingestor.Blob)
var puller *blob.BlobStore
puller, err = blob.NewBlobStorage(khCfg, khCfg.Ingestor.Blob)
if err != nil {
return "", err
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/telemetry/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
IngestorFailed
DumpStarted
DumpFinished
DumpFailed
)

const (
Expand Down Expand Up @@ -47,6 +48,7 @@ var map2msg = map[EventAction]EventActionDetails{

DumpStarted: {Title: "Dump started", Level: statsd.Info, Action: EventActionStart},
DumpFinished: {Title: "Dump finished", Level: statsd.Info, Action: EventActionFinish},
DumpFailed: {Title: "Dump failed", Level: statsd.Error, Action: EventActionFail},
}

func (ea EventAction) Tags(ctx context.Context) []string {
Expand Down

0 comments on commit bc31a94

Please sign in to comment.