Skip to content

Commit 14e5b84

Browse files
authored
Adding error reporting on failure on client cmd (#292)
* adding error reporting on failure on client cmd * roll back * error reporting for dump * revert * adding comment
1 parent e5ae1af commit 14e5b84

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pkg/kubehound/core/core_dump.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ func DumpCore(ctx context.Context, khCfg *config.KubehoundConfig, upload bool) (
2525
l := log.Logger(ctx)
2626

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

3744
span, ctx := span.SpanRunFromContext(ctx, span.DumperLaunch)
3845
span.SetTag(ext.ManualKeep, true)
46+
l = log.Logger(ctx)
3947
defer func() {
4048
span.Finish(tracer.WithError(err))
4149
}()
@@ -53,12 +61,16 @@ func DumpCore(ctx context.Context, khCfg *config.KubehoundConfig, upload bool) (
5361
if upload {
5462
// Clean up the temporary directory when done
5563
defer func() {
56-
err = os.RemoveAll(khCfg.Collector.File.Directory)
64+
// This error is scope to the defer and not be handled by the other defer function
65+
err := os.RemoveAll(khCfg.Collector.File.Directory)
5766
if err != nil {
67+
errMsg := fmt.Errorf("Failed to remove temporary directory: %w", err)
5868
l.Error("Failed to remove temporary directory", log.ErrorField(err))
69+
_ = events.PushEvent(ctx, events.DumpFailed, fmt.Sprintf("%s", errMsg))
5970
}
6071
}()
61-
puller, err := blob.NewBlobStorage(khCfg, khCfg.Ingestor.Blob)
72+
var puller *blob.BlobStore
73+
puller, err = blob.NewBlobStorage(khCfg, khCfg.Ingestor.Blob)
6274
if err != nil {
6375
return "", err
6476
}

pkg/telemetry/events/events.go

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const (
1818
IngestorFailed
1919
DumpStarted
2020
DumpFinished
21+
DumpFailed
2122
)
2223

2324
const (
@@ -47,6 +48,7 @@ var map2msg = map[EventAction]EventActionDetails{
4748

4849
DumpStarted: {Title: "Dump started", Level: statsd.Info, Action: EventActionStart},
4950
DumpFinished: {Title: "Dump finished", Level: statsd.Info, Action: EventActionFinish},
51+
DumpFailed: {Title: "Dump failed", Level: statsd.Error, Action: EventActionFail},
5052
}
5153

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

0 commit comments

Comments
 (0)