Skip to content

Commit

Permalink
feat: add extra context to errors (#959)
Browse files Browse the repository at this point in the history
Enhance error handling by wrapping errors with additional context during
plugin operations and eBPF compilation.
  • Loading branch information
ritwikranjan authored Nov 6, 2024
1 parent 1ecfb43 commit 397ca20
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pkg/managers/pluginmanager/pluginmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,18 @@ func (p *PluginManager) Reconcile(ctx context.Context, plugin api.Plugin) error
// Regenerate eBPF code and bpf object.
// This maybe no-op for plugins that don't use eBPF.
if err := plugin.Generate(ctx); err != nil {
return err
return errors.Wrap(err, "failed to generate plugin")
}
if err := plugin.Compile(ctx); err != nil {
return err
return errors.Wrap(err, "failed to compile plugin")
}

// Re-start plugin.
if err := plugin.Stop(); err != nil {
return err
return errors.Wrap(err, "failed to stop plugin")
}
if err := plugin.Init(); err != nil {
return err
return errors.Wrap(err, "failed to init plugin")
}

p.l.Info("Reconciled plugin", zap.String("name", plugin.Name()))
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugin/dropreason/dropreason_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bytes"
"context"
"encoding/binary"
"errors"
"fmt"
"os"
"path"
Expand All @@ -30,6 +29,7 @@ import (
plugincommon "github.com/microsoft/retina/pkg/plugin/common"
_ "github.com/microsoft/retina/pkg/plugin/dropreason/_cprog" // nolint
"github.com/microsoft/retina/pkg/utils"
"github.com/pkg/errors"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -109,7 +109,7 @@ func (dr *dropReason) Compile(ctx context.Context) error {
// Keep target as bpf, otherwise clang compilation yields bpf object that elf reader cannot load.
err = loader.CompileEbpf(ctx, "-target", "bpf", "-Wall", targetArch, "-g", "-O2", "-c", bpfSourceFile, "-o", bpfOutputFile, includeDir, libbpfDir, filterDir)
if err != nil {
return err
return errors.Wrap(err, "unable to compile eBPF code")
}
dr.l.Info("DropReason metric compiled")
return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugin/packetforward/packetforward_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ package packetforward

import (
"context"
"errors"
"fmt"
"path"
"runtime"
"syscall"
"time"

kcfg "github.com/microsoft/retina/pkg/config"
"github.com/pkg/errors"

hubblev1 "github.com/cilium/cilium/pkg/hubble/api/v1"
"github.com/cilium/ebpf"
Expand Down Expand Up @@ -124,7 +124,7 @@ func (p *packetForward) Compile(ctx context.Context) error {
// Keep target as bpf, otherwise clang compilation yields bpf object that elf reader cannot load.
err = loader.CompileEbpf(ctx, "-target", "bpf", "-Wall", targetArch, "-g", "-O2", "-c", bpfSourceFile, "-o", bpfOutputFile, includeDir, libbpfDir)
if err != nil {
return err
return errors.Wrap(err, "error compiling ebpf code")
}
p.l.Info("Packet forwarding metric compiled")
return nil
Expand Down

0 comments on commit 397ca20

Please sign in to comment.