feat(loader): add performance-mode option can skip non critical step when attach failed

This commit is contained in:
hengyoush
2024-11-01 22:38:14 +08:00
parent 7062127f80
commit fbc88bccad
3 changed files with 21 additions and 2 deletions

View File

@@ -47,6 +47,7 @@ type AgentOptions struct {
PerfEventBufferSizeForEvent int
DisableOpensslUprobe bool
WatchOptions watch.WatchOptions
PerformanceMode bool
DockerEndpoint string
ContainerdEndpoint string

View File

@@ -517,7 +517,12 @@ func attachBpfProgs(ifName string, kernelVersion *compatible.KernelVersion, opti
}
}
for _, functions := range kernelVersion.InstrumentFunctions {
nonCriticalSteps := getNonCriticalSteps()
for step, functions := range kernelVersion.InstrumentFunctions {
_, isNonCriticalStep := nonCriticalSteps[step]
if options.PerformanceMode && isNonCriticalStep {
continue
}
for idx, function := range functions {
var err error
var l link.Link
@@ -533,7 +538,11 @@ func attachBpfProgs(ifName string, kernelVersion *compatible.KernelVersion, opti
}
if err != nil {
if idx == len(functions)-1 {
common.AgentLog.Fatalf("Attach failed: %v, functions: %v", err, functions)
if isNonCriticalStep {
common.AgentLog.Debugf("Attach failed: %v, functions: %v skip it because it's a non-criticalstep", err, functions)
} else {
common.AgentLog.Fatalf("Attach failed: %v, functions: %v", err, functions)
}
} else {
common.AgentLog.Debugf("Attach failed but has fallback: %v, functions: %v", err, functions)
}
@@ -647,3 +656,11 @@ func attachNfFunctions(links *list.List) {
links.PushBack(l)
}
}
func getNonCriticalSteps() map[bpf.AgentStepT]bool {
return map[bpf.AgentStepT]bool{
bpf.AgentStepTIP_OUT: true,
bpf.AgentStepTQDISC_OUT: true,
bpf.AgentStepTIP_IN: true,
}
}

View File

@@ -91,6 +91,7 @@ func init() {
strings.Join(getDefaultCriRuntimeEndpoint(), ", ")))
// internal
rootCmd.PersistentFlags().BoolVar(&options.PerformanceMode, "performance-mode", true, "--performance false")
rootCmd.PersistentFlags().IntVar(&BPFVerifyLogSize, "bpf-verify-log-size", 10*1024, "--bpf-verify-log-size 1024")
rootCmd.PersistentFlags().IntVar(&KernEvtPerfEventBufferSize, "kern-perf-event-buffer-size", 1*1024*1024, "--kern-perf-event-buffer-size 1024")
rootCmd.PersistentFlags().IntVar(&KernEvtPerfEventBufferSize, "data-perf-event-buffer-size", 30*1024*1024, "--data-perf-event-buffer-size 1024")