Skip to content

Commit

Permalink
Add AfterStop
Browse files Browse the repository at this point in the history
  • Loading branch information
gjulianm committed Dec 20, 2024
1 parent 2f11888 commit 837eed0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/ebpf/helper_call_patcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@ func (h *helperCallRemover) String() string {
func (h *helperCallRemover) BeforeStop(*manager.Manager, names.ModuleName) error {
return nil
}

func (h *helperCallRemover) AfterStop(*manager.Manager, names.ModuleName) error {
return nil
}
13 changes: 12 additions & 1 deletion pkg/ebpf/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ type Modifier interface {
// BeforeStop is called after the ebpf.Manager.Stop call. Errors on these modifiers
// will not prevent the manager from stopping, but they will be reported.
BeforeStop(*manager.Manager, names.ModuleName) error

// AfterStop is called after the ebpf.Manager.Stop call. If the manager returns
// an error on stop, this function will still be called.
AfterStop(*manager.Manager, names.ModuleName) error
}

// InitWithOptions is a wrapper around ebpf-manager.Manager.InitWithOptions
Expand Down Expand Up @@ -111,7 +115,7 @@ func (m *Manager) Stop(clean manager.MapCleanupType) error {
var errs error

for _, mod := range m.EnabledModifiers {
log.Warnf("Running %s manager modifier BeforeStop", mod)
log.Tracef("Running %s manager modifier BeforeStop", mod)
if err := mod.BeforeStop(m.Manager, m.Name); err != nil {
errs = errors.Join(errs, fmt.Errorf("error running %s manager modifier BeforeStop(): %s", mod, err))
}
Expand All @@ -121,5 +125,12 @@ func (m *Manager) Stop(clean manager.MapCleanupType) error {
errs = errors.Join(errs, fmt.Errorf("failed to stop manager %w", err))
}

for _, mod := range m.EnabledModifiers {
log.Tracef("Running %s manager modifier AfterStop", mod)
if err := mod.AfterStop(m.Manager, m.Name); err != nil {
errs = errors.Join(errs, fmt.Errorf("error running %s manager modifier AfterStop(): %s", mod, err))
}
}

return errs
}
4 changes: 4 additions & 0 deletions pkg/ebpf/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func (t *dummyModifier) BeforeStop(_ *manager.Manager, _ names.ModuleName) error
return nil
}

func (t *dummyModifier) AfterStop(_ *manager.Manager, _ names.ModuleName) error {
return nil
}

func TestNewManagerWithDefault(t *testing.T) {
type args struct {
mgr *manager.Manager
Expand Down
5 changes: 5 additions & 0 deletions pkg/ebpf/printk_patcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,8 @@ func (t *PrintkPatcherModifier) AfterInit(_ *manager.Manager, _ names.ModuleName
func (t *PrintkPatcherModifier) BeforeStop(_ *manager.Manager, _ names.ModuleName) error {
return nil
}

// AfterStop is a no-op for this modifier
func (t *PrintkPatcherModifier) AfterStop(_ *manager.Manager, _ names.ModuleName) error {
return nil
}
5 changes: 5 additions & 0 deletions pkg/ebpf/telemetry/modifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,8 @@ func (t *ErrorsTelemetryModifier) AfterInit(m *manager.Manager, module names.Mod
func (t *ErrorsTelemetryModifier) BeforeStop(_ *manager.Manager, _ names.ModuleName) error {
return nil
}

// AfterStop is a no-op
func (t *ErrorsTelemetryModifier) AfterStop(_ *manager.Manager, _ names.ModuleName) error {
return nil
}

0 comments on commit 837eed0

Please sign in to comment.