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

Adding error reporting on failure on client cmd #292

Merged
merged 5 commits into from
Nov 20, 2024
Merged
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
16 changes: 14 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,16 @@ 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)
// This error is scope to the defer and not be handled by the other defer function
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
Loading