diff --git a/pkg/dynamicinstrumentation/codegen/codegen.go b/pkg/dynamicinstrumentation/codegen/codegen.go index 5c0e3e8e85e41..b02269f1b0ebc 100644 --- a/pkg/dynamicinstrumentation/codegen/codegen.go +++ b/pkg/dynamicinstrumentation/codegen/codegen.go @@ -76,18 +76,17 @@ func generateHeaderText(param *ditypes.Parameter, out io.Writer) error { return generateSliceHeader(param, out) } else if reflect.Kind(param.Kind) == reflect.String { return generateStringHeader(param, out) - } else { //nolint:revive // TODO - tmplt, err := resolveHeaderTemplate(param) - if err != nil { - return err - } - err = tmplt.Execute(out, param) - if err != nil { - return err - } - if len(param.ParameterPieces) != 0 { - return generateHeadersText(param.ParameterPieces, out) - } + } + template, err := resolveHeaderTemplate(param) + if err != nil { + return err + } + err = template.Execute(out, param) + if err != nil { + return err + } + if len(param.ParameterPieces) != 0 { + return generateHeadersText(param.ParameterPieces, out) } return nil } diff --git a/pkg/dynamicinstrumentation/di.go b/pkg/dynamicinstrumentation/di.go index ffaeebbaea572..57babad4e61a6 100644 --- a/pkg/dynamicinstrumentation/di.go +++ b/pkg/dynamicinstrumentation/di.go @@ -10,7 +10,6 @@ package dynamicinstrumentation import ( - "encoding/json" "fmt" "io" @@ -51,14 +50,16 @@ func newGoDIStats() GoDIStats { } } -type OfflineOptions struct { //nolint:revive // TODO +// OfflineOptions configures the Offline options for the running Dynamic Instrumentation process +type OfflineOptions struct { Offline bool ProbesFilePath string SnapshotOutput string DiagnosticOutput string } -type ReaderWriterOptions struct { //nolint:revive // TODO +// ReaderWriterOptions configures the ReaderWriter options for the running Dynamic Instrumentation process +type ReaderWriterOptions struct { CustomReaderWriters bool SnapshotWriter io.Writer DiagnosticWriter io.Writer @@ -153,28 +154,6 @@ func RunDynamicInstrumentation(opts *DIOptions) (*GoDI, error) { return goDI, nil } -func (goDI *GoDI) printSnapshot(event *ditypes.DIEvent) { //nolint:unused // TODO - if event == nil { - return - } - procInfo := goDI.ConfigManager.GetProcInfos()[event.PID] - diLog := uploader.NewDILog(procInfo, event) - - var bs []byte - var err error - - if diLog != nil { - bs, err = json.MarshalIndent(diLog, "", " ") - } else { - bs, err = json.MarshalIndent(event, "", " ") - } - - if err != nil { - log.Info(err) - } - log.Debug(string(bs)) -} - func (goDI *GoDI) uploadSnapshot(event *ditypes.DIEvent) { // goDI.printSnapshot(event) procInfo := goDI.ConfigManager.GetProcInfos()[event.PID] diff --git a/pkg/dynamicinstrumentation/diagnostics/diagnostics.go b/pkg/dynamicinstrumentation/diagnostics/diagnostics.go index 8355f33783efa..fae84ff61aa77 100644 --- a/pkg/dynamicinstrumentation/diagnostics/diagnostics.go +++ b/pkg/dynamicinstrumentation/diagnostics/diagnostics.go @@ -78,7 +78,8 @@ func (m *DiagnosticManager) update(id probeInstanceID, d *ditypes.DiagnosticUplo } } -func StopGlobalDiagnostics() { //nolint:revive // TODO +// StopGlobalDiagnostics stops diagnostics from running and closes the updates channel +func StopGlobalDiagnostics() { close(Diagnostics.Updates) } diff --git a/pkg/dynamicinstrumentation/diconfig/config_manager.go b/pkg/dynamicinstrumentation/diconfig/config_manager.go index c24369dcb1145..df74ba82b77c1 100644 --- a/pkg/dynamicinstrumentation/diconfig/config_manager.go +++ b/pkg/dynamicinstrumentation/diconfig/config_manager.go @@ -138,7 +138,7 @@ func (cm *RCConfigManager) installConfigProbe(procInfo *ditypes.ProcessInfo) err return fmt.Errorf("could not generate bpf code for config probe: %w", err) } - err = ebpf.CompileBPFProgram(procInfo, configProbe) + err = ebpf.CompileBPFProgram(configProbe) if err != nil { return fmt.Errorf("could not compile bpf code for config probe: %w", err) } @@ -262,7 +262,7 @@ generateCompileAttach: return } - err = ebpf.CompileBPFProgram(procInfo, probe) + err = ebpf.CompileBPFProgram(probe) if err != nil { // TODO: Emit diagnostic? log.Info("Couldn't compile BPF object", err) diff --git a/pkg/dynamicinstrumentation/diconfig/file_config_manager.go b/pkg/dynamicinstrumentation/diconfig/file_config_manager.go index f39537adbbd80..67e8a93de9a50 100644 --- a/pkg/dynamicinstrumentation/diconfig/file_config_manager.go +++ b/pkg/dynamicinstrumentation/diconfig/file_config_manager.go @@ -14,7 +14,8 @@ import ( "github.com/DataDog/datadog-agent/pkg/util/log" ) -func NewFileConfigManager(configFile string) (*ReaderConfigManager, func(), error) { //nolint:revive // TODO +// NewFileConfigManager creates a new FileConfigManager +func NewFileConfigManager(configFile string) (*ReaderConfigManager, func(), error) { stopChan := make(chan bool) stop := func() { stopChan <- true @@ -35,7 +36,10 @@ func NewFileConfigManager(configFile string) (*ReaderConfigManager, func(), erro for { select { case rawBytes := <-updateChan: - cm.ConfigWriter.Write(rawBytes) //nolint:errcheck // TODO + _, err := cm.ConfigWriter.Write(rawBytes) + if err != nil { + log.Errorf("Error writing config file %s: %s", configFile, err) + } case <-stopChan: log.Info("stopping file config manager") fw.Stop() diff --git a/pkg/dynamicinstrumentation/diconfig/mem_config_manager.go b/pkg/dynamicinstrumentation/diconfig/mem_config_manager.go index 7e7ca74f9a933..381080eab517f 100644 --- a/pkg/dynamicinstrumentation/diconfig/mem_config_manager.go +++ b/pkg/dynamicinstrumentation/diconfig/mem_config_manager.go @@ -31,10 +31,10 @@ type ReaderConfigManager struct { state ditypes.DIProcs } -type readerConfigCallback func(configsByService) //nolint:unused // TODO type configsByService = map[ditypes.ServiceName]map[ditypes.ProbeID]rcConfig -func NewReaderConfigManager() (*ReaderConfigManager, error) { //nolint:revive // TODO +// NewReaderConfigManager creates a new ReaderConfigManager +func NewReaderConfigManager() (*ReaderConfigManager, error) { cm := &ReaderConfigManager{ callback: applyConfigUpdate, state: ditypes.NewDIProcs(), @@ -55,11 +55,13 @@ func NewReaderConfigManager() (*ReaderConfigManager, error) { //nolint:revive // return cm, nil } -func (cm *ReaderConfigManager) GetProcInfos() ditypes.DIProcs { //nolint:revive // TODO +// GetProcInfos returns the process info state +func (cm *ReaderConfigManager) GetProcInfos() ditypes.DIProcs { return cm.state } -func (cm *ReaderConfigManager) Stop() { //nolint:revive // TODO +// Stop causes the ReaderConfigManager to stop processing data +func (cm *ReaderConfigManager) Stop() { cm.ConfigWriter.Stop() cm.procTracker.Stop() } @@ -131,7 +133,8 @@ func (cm *ReaderConfigManager) updateServiceConfigs(configs configsByService) { } } -type ConfigWriter struct { //nolint:revive // TODO +// ConfigWriter handles writing configuration data +type ConfigWriter struct { io.Writer updateChannel chan ([]byte) Processes map[ditypes.PID]*ditypes.ProcessInfo @@ -139,9 +142,11 @@ type ConfigWriter struct { //nolint:revive // TODO stopChannel chan (bool) } -type ConfigWriterCallback func(configsByService) //nolint:revive // TODO +// ConfigWriterCallback provides a callback interface for ConfigWriter +type ConfigWriterCallback func(configsByService) -func NewConfigWriter(onConfigUpdate ConfigWriterCallback) *ConfigWriter { //nolint:revive // TODO +// NewConfigWriter creates a new ConfigWriter +func NewConfigWriter(onConfigUpdate ConfigWriterCallback) *ConfigWriter { return &ConfigWriter{ updateChannel: make(chan []byte, 1), configCallback: onConfigUpdate, @@ -154,7 +159,8 @@ func (r *ConfigWriter) Write(p []byte) (n int, e error) { return 0, nil } -func (r *ConfigWriter) Start() error { //nolint:revive // TODO +// Start initiates the ConfigWriter to start processing data +func (r *ConfigWriter) Start() error { go func() { configUpdateLoop: for { @@ -175,18 +181,19 @@ func (r *ConfigWriter) Start() error { //nolint:revive // TODO return nil } -func (cu *ConfigWriter) Stop() { //nolint:revive // TODO - cu.stopChannel <- true +// Stop causes the ConfigWriter to stop processing data +func (r *ConfigWriter) Stop() { + r.stopChannel <- true } // UpdateProcesses is the callback interface that ConfigWriter uses to consume the map of ProcessInfo's // such that it's used whenever there's an update to the state of known service processes on the machine. // It simply overwrites the previous state of known service processes with the new one -func (cu *ConfigWriter) UpdateProcesses(procs ditypes.DIProcs) { //nolint:revive // TODO +func (r *ConfigWriter) UpdateProcesses(procs ditypes.DIProcs) { current := procs - old := cu.Processes + old := r.Processes if !reflect.DeepEqual(current, old) { - cu.Processes = current + r.Processes = current } } diff --git a/pkg/dynamicinstrumentation/ebpf/ebpf.go b/pkg/dynamicinstrumentation/ebpf/ebpf.go index ed2c7578f685b..8703634ad69cc 100644 --- a/pkg/dynamicinstrumentation/ebpf/ebpf.go +++ b/pkg/dynamicinstrumentation/ebpf/ebpf.go @@ -14,7 +14,6 @@ import ( "fmt" "io" "text/template" - "time" "github.com/cilium/ebpf" "github.com/cilium/ebpf/link" @@ -126,8 +125,8 @@ func AttachBPFUprobe(procInfo *ditypes.ProcessInfo, probe *ditypes.Probe) error return nil } -// CompileBPFProgram compiles the code for a single probe associated with the process given by procInfo -func CompileBPFProgram(procInfo *ditypes.ProcessInfo, probe *ditypes.Probe) error { //nolint:revive // TODO +// CompileBPFProgram compiles the code for a single probe +func CompileBPFProgram(probe *ditypes.Probe) error { f := func(in io.Reader, out io.Writer) error { fileContents, err := io.ReadAll(in) if err != nil { @@ -169,7 +168,3 @@ func getCFlags(config *ddebpf.Config) []string { } return cflags } - -const ( - compilationStepTimeout = 60 * time.Second //nolint:unused // TODO -) diff --git a/pkg/dynamicinstrumentation/module/module.go b/pkg/dynamicinstrumentation/module/module.go index 7352b8def49e6..0b8ce1e4636b2 100644 --- a/pkg/dynamicinstrumentation/module/module.go +++ b/pkg/dynamicinstrumentation/module/module.go @@ -24,7 +24,7 @@ type Module struct { } // NewModule creates a new dynamic instrumentation system probe module -func NewModule(config *Config) (*Module, error) { //nolint:revive // TODO +func NewModule(_ *Config) (*Module, error) { godi, err := di.RunDynamicInstrumentation(&di.DIOptions{ RateLimitPerProbePerSecond: 1.0, OfflineOptions: di.OfflineOptions{ @@ -66,7 +66,7 @@ func (m *Module) GetStats() map[string]interface{} { // Register creates a health check endpoint for the dynamic instrumentation module func (m *Module) Register(httpMux *module.Router) error { httpMux.HandleFunc("/check", utils.WithConcurrencyLimit(utils.DefaultMaxConcurrentRequests, - func(w http.ResponseWriter, req *http.Request) { //nolint:revive // TODO + func(w http.ResponseWriter, _ *http.Request) { stats := []string{} utils.WriteAsJSON(w, stats) })) diff --git a/pkg/dynamicinstrumentation/testutil/fixtures.go b/pkg/dynamicinstrumentation/testutil/fixtures.go index ae12846d40309..d25e558b0da9f 100644 --- a/pkg/dynamicinstrumentation/testutil/fixtures.go +++ b/pkg/dynamicinstrumentation/testutil/fixtures.go @@ -40,54 +40,6 @@ var basicCaptures = fixtures{ // "github.com/DataDog/datadog-agent/pkg/dynamicinstrumentation/testutil/sample.test_single_float64": {"x": capturedValue("float", "-1.646464")}, } -var multiParamCaptures = fixtures{ //nolint:unused // TODO - "github.com/DataDog/datadog-agent/pkg/dynamicinstrumentation/testutil/sample.test_multiple_simple_params": { - "a": capturedValue("bool", "false"), - "b": capturedValue("uint8", "42"), - "c": capturedValue("int32", "122"), - "d": capturedValue("uint", "1337"), - "e": capturedValue("string", "xyz"), - }, - "github.com/DataDog/datadog-agent/pkg/dynamicinstrumentation/testutil/sample.test_multiple_composite_params": { - "a": {Type: "array", Fields: fieldMap{ - "a_0": capturedValue("string", "one"), - "a_1": capturedValue("string", "two"), - "a_2": capturedValue("string", "three"), - }}, - "b": {Type: "struct", Fields: fieldMap{ - "aBool": capturedValue("bool", "false"), - "aString": capturedValue("string", ""), - "aNumber": capturedValue("int", "0"), - "nested": {Type: "struct", Fields: fieldMap{ - "anotherInt": capturedValue("int", "0"), - "anotherString": capturedValue("string", ""), - }}, - }}, - "c": {Type: "slice", Fields: fieldMap{ - "c_0": capturedValue("uint", "24"), - "c_1": capturedValue("uint", "42"), - }}, - "d": {Type: "map", Fields: fieldMap{ - "foo": capturedValue("string", "bar"), - }}, - "e": {Type: "slice", Fields: fieldMap{ - "e_0": {Type: "struct", Fields: fieldMap{ - "anotherInt": capturedValue("int", "42"), - "anotherString": capturedValue("string", "ftwo"), - }}, - "e_1": {Type: "struct", Fields: fieldMap{ - "anotherInt": capturedValue("int", "24"), - "anotherString": capturedValue("string", "tfour"), - }}, - }}, - }, - "github.com/DataDog/datadog-agent/pkg/dynamicinstrumentation/testutil/sample.test_combined_byte": { - "w": capturedValue("uint8", "2"), - "x": capturedValue("uint8", "3"), - "y": capturedValue("uint8", "3.0"), - }, -} - var stringCaptures = fixtures{ "github.com/DataDog/datadog-agent/pkg/dynamicinstrumentation/testutil/sample.test_single_string": {"x": capturedValue("string", "abc")}, } @@ -239,32 +191,6 @@ var structCaptures = fixtures{ }}}, } -// TODO: this doesn't work yet: -// could not determine locations of variables from debug information could not inspect param "x" on function: no location field in parameter entry -var genericCaptures = fixtures{ //nolint:unused // TODO - "github.com/DataDog/datadog-agent/pkg/dynamicinstrumentation/testutil/sample.typeWithGenerics[go.shape.string].Guess": {"value": capturedValue("string", "generics work")}, -} - -// TODO: check how map entries should be represented, likely that entries have key / value pair fields -// instead of having the keys hardcoded as string field names -// maps are no supported at the moment so this fails anyway -var mapCaptures = fixtures{ //nolint:unused // TODO - "github.com/DataDog/datadog-agent/pkg/dynamicinstrumentation/testutil/sample.test_map_string_to_int": {"m": {Type: "map", Fields: fieldMap{ - "foo": capturedValue("int", "1"), - "bar": capturedValue("int", "2"), - }}}, - "github.com/DataDog/datadog-agent/pkg/dynamicinstrumentation/testutil/sample.test_map_string_to_struct": {"m": {Type: "map", Fields: fieldMap{ - "foo": {Type: "struct", Fields: fieldMap{ - "anotherInt": capturedValue("int", "3"), - "anotherString": capturedValue("string", "four"), - }}, - "bar": {Type: "struct", Fields: fieldMap{ - "anotherInt": capturedValue("int", "3"), - "anotherString": capturedValue("string", "four"), - }}, - }}}, -} - // mergeMaps combines multiple fixture maps into a single map func mergeMaps(maps ...fixtures) fixtures { result := make(fixtures) diff --git a/pkg/dynamicinstrumentation/uploader/writer.go b/pkg/dynamicinstrumentation/uploader/writer.go index 3f31e4e2a6f75..3ebab2a281961 100644 --- a/pkg/dynamicinstrumentation/uploader/writer.go +++ b/pkg/dynamicinstrumentation/uploader/writer.go @@ -20,19 +20,22 @@ import ( "github.com/kr/pretty" ) -type WriterSerializer[T any] struct { //nolint:revive // TODO +// WriterSerializer is an interface to serialize output guarded by a mutex +type WriterSerializer[T any] struct { output io.Writer mu sync.Mutex } -func NewWriterLogSerializer(writer io.Writer) (*WriterSerializer[ditypes.SnapshotUpload], error) { //nolint:revive // TODO +// NewWriterLogSerializer creates a new WriterSerializer for snapshot uploads +func NewWriterLogSerializer(writer io.Writer) (*WriterSerializer[ditypes.SnapshotUpload], error) { if writer == nil { return nil, errors.New("nil writer for creating log serializer") } return NewWriterSerializer[ditypes.SnapshotUpload](writer) } -func NewWriterDiagnosticSerializer(dm *diagnostics.DiagnosticManager, writer io.Writer) (*WriterSerializer[ditypes.DiagnosticUpload], error) { //nolint:revive // TODO +// NewWriterDiagnosticSerializer creates a new WriterSerializer for diagnostics uploads +func NewWriterDiagnosticSerializer(dm *diagnostics.DiagnosticManager, writer io.Writer) (*WriterSerializer[ditypes.DiagnosticUpload], error) { if writer == nil { return nil, errors.New("nil writer for creating diagnostic serializer") } @@ -51,7 +54,8 @@ func NewWriterDiagnosticSerializer(dm *diagnostics.DiagnosticManager, writer io. return ds, nil } -func NewWriterSerializer[T any](writer io.Writer) (*WriterSerializer[T], error) { //nolint:revive // TODO +// NewWriterSerializer creates a new WriterLogSerializer for generic types +func NewWriterSerializer[T any](writer io.Writer) (*WriterSerializer[T], error) { if writer == nil { return nil, errors.New("nil writer for creating serializer") } @@ -60,7 +64,8 @@ func NewWriterSerializer[T any](writer io.Writer) (*WriterSerializer[T], error) }, nil } -func (s *WriterSerializer[T]) Enqueue(item *T) error { //nolint:revive // TODO +// Enqueue writes an item to the output +func (s *WriterSerializer[T]) Enqueue(item *T) error { s.mu.Lock() defer s.mu.Unlock() bs, err := json.Marshal(item) diff --git a/pkg/dynamicinstrumentation/util/file_watcher.go b/pkg/dynamicinstrumentation/util/file_watcher.go index 944d8e3b35020..2b2aa862fbbd5 100644 --- a/pkg/dynamicinstrumentation/util/file_watcher.go +++ b/pkg/dynamicinstrumentation/util/file_watcher.go @@ -5,7 +5,8 @@ //go:build linux_bpf -package util //nolint:revive // TODO +// Package util providers utility file functions to dynamic instrumentation +package util import ( "os" @@ -70,6 +71,7 @@ func (fw *FileWatcher) Watch() (<-chan []byte, error) { return updateChan, nil } -func (fw *FileWatcher) Stop() { //nolint:revive // TODO +// Stop causes the FileWatcher to stop watching the file +func (fw *FileWatcher) Stop() { fw.stop <- true } diff --git a/pkg/ebpf/btf.go b/pkg/ebpf/btf.go index 3721e0d66054b..45ad7bec22893 100644 --- a/pkg/ebpf/btf.go +++ b/pkg/ebpf/btf.go @@ -90,7 +90,8 @@ type returnBTF struct { vmlinux *btf.Spec } -type BTFResultMetadata struct { //nolint:revive // TODO +// BTFResultMetadata holds metadata about BTF results +type BTFResultMetadata struct { // numLoadAttempts is how many times the loader has been invoked (doesn't include cached requests) numLoadAttempts int // loaderUsed the name of the loader that was used to get the BTF data diff --git a/pkg/ebpf/maps/generic_map.go b/pkg/ebpf/maps/generic_map.go index 02036ce8a7605..15dba2ed118b4 100644 --- a/pkg/ebpf/maps/generic_map.go +++ b/pkg/ebpf/maps/generic_map.go @@ -25,7 +25,8 @@ import ( const defaultBatchSize = 100 -var ErrBatchAPINotSupported = errors.New("batch API not supported for this map: check whether key is fixed-size, kernel supports batch API and if this map is not per-cpu") //nolint:revive // TODO +// ErrBatchAPINotSupported is the error when batch API is not supported for a given map +var ErrBatchAPINotSupported = errors.New("batch API not supported for this map: check whether key is fixed-size, kernel supports batch API and if this map is not per-cpu") // BatchAPISupported returns true if the kernel supports the batch API for maps var BatchAPISupported = funcs.MemoizeNoError(func() bool { diff --git a/pkg/ebpf/telemetry/errors_telemetry.go b/pkg/ebpf/telemetry/errors_telemetry.go index 08688ef51f2df..8546c40ae3390 100644 --- a/pkg/ebpf/telemetry/errors_telemetry.go +++ b/pkg/ebpf/telemetry/errors_telemetry.go @@ -103,15 +103,13 @@ func (e *ebpfTelemetry) fill(maps []names.MapName, mn names.ModuleName, mapErrMa if _, ok := e.mapErrMapsByModule[mn]; ok { return fmt.Errorf("eBPF map for map-operation errors for module %s already exists", mn.Name()) - } else { //nolint:revive // TODO - e.mapErrMapsByModule[mn] = mapErrMap } + e.mapErrMapsByModule[mn] = mapErrMap if _, ok := e.helperErrMapsByModule[mn]; ok { return fmt.Errorf("eBPF map for helper-operation errors for module %s already exists", mn.Name()) - } else { //nolint:revive // TODO - e.helperErrMapsByModule[mn] = helperErrMap } + e.helperErrMapsByModule[mn] = helperErrMap e.initialized = true diff --git a/pkg/ebpf/uprobes/attacher.go b/pkg/ebpf/uprobes/attacher.go index f413462bea633..36781ff80bdc2 100644 --- a/pkg/ebpf/uprobes/attacher.go +++ b/pkg/ebpf/uprobes/attacher.go @@ -303,7 +303,8 @@ type FileRegistry interface { // AttachCallback is a callback that is called whenever a probe is attached successfully type AttachCallback func(*manager.Probe, *utils.FilePath) -var NopOnAttachCallback AttachCallback = nil //nolint:revive // TODO +// NopOnAttachCallback is a callback that indicates that no action should be taken for the callback +var NopOnAttachCallback AttachCallback // UprobeAttacher is a struct that handles the attachment of uprobes to processes and libraries type UprobeAttacher struct { diff --git a/pkg/ebpf/uprobes/testutil.go b/pkg/ebpf/uprobes/testutil.go index 2d4e8b85d4b25..cd4b2891d72ef 100644 --- a/pkg/ebpf/uprobes/testutil.go +++ b/pkg/ebpf/uprobes/testutil.go @@ -58,7 +58,7 @@ type MockFileRegistry struct { } // Register is a mock implementation of the FileRegistry.Register method. -func (m *MockFileRegistry) Register(namespacedPath string, pid uint32, activationCB, deactivationCB, alreadyRegistered utils.Callback) error { //nolint:revive // TODO +func (m *MockFileRegistry) Register(namespacedPath string, pid uint32, activationCB, deactivationCB, _ utils.Callback) error { args := m.Called(namespacedPath, pid, activationCB, deactivationCB) return args.Error(0) } diff --git a/pkg/gpu/probe.go b/pkg/gpu/probe.go index e7eb33bd80f98..a3246848e1303 100644 --- a/pkg/gpu/probe.go +++ b/pkg/gpu/probe.go @@ -233,8 +233,7 @@ func (p *Probe) initRCGPU(cfg *config.Config) error { func (p *Probe) initCOREGPU(cfg *config.Config) error { asset := getAssetName("gpu", cfg.BPFDebug) - var err error //nolint:gosimple // TODO - err = ddebpf.LoadCOREAsset(asset, func(ar bytecode.AssetReader, o manager.Options) error { + err := ddebpf.LoadCOREAsset(asset, func(ar bytecode.AssetReader, o manager.Options) error { return p.setupManager(ar, o) }) return err diff --git a/pkg/gpu/stream.go b/pkg/gpu/stream.go index 031ff228e8a3f..d82a787d17c52 100644 --- a/pkg/gpu/stream.go +++ b/pkg/gpu/stream.go @@ -52,7 +52,6 @@ type streamKey struct { // streamData contains kernel spans and allocations for a stream type streamData struct { - key streamKey //nolint:unused // TODO spans []*kernelSpan allocations []*memoryAllocation } diff --git a/pkg/gpu/testutil/samplebins.go b/pkg/gpu/testutil/samplebins.go index c38865a405909..d6bf97b2ad283 100644 --- a/pkg/gpu/testutil/samplebins.go +++ b/pkg/gpu/testutil/samplebins.go @@ -46,7 +46,8 @@ const ( MinimalDockerImage dockerImage = "alpine:3.20.3" ) -type SampleArgs struct { //nolint:revive // TODO +// SampleArgs holds arguments for the sample binary +type SampleArgs struct { // StartWaitTimeSec represents the time in seconds to wait before the binary starting the CUDA calls StartWaitTimeSec int diff --git a/pkg/network/ebpf/bpf_module.go b/pkg/network/ebpf/bpf_module.go index dc9e6279c6d57..8e4d71bff3248 100644 --- a/pkg/network/ebpf/bpf_module.go +++ b/pkg/network/ebpf/bpf_module.go @@ -19,9 +19,10 @@ import ( // prebuiltModulesInUse is a global object which is responsible for keeping a list of all the prebuilt ebpf assets in use. // This is used to report ebpf asset telemetry var prebuiltModulesInUse = map[string]struct{}{} -var telemetrymu sync.Mutex +var telemetryMu sync.Mutex -func ModuleFileName(moduleName string, debug bool) string { //nolint:revive // TODO +// ModuleFileName constructs the module file name based on the module name +func ModuleFileName(moduleName string, debug bool) string { if debug { return fmt.Sprintf("%s-debug.o", moduleName) } @@ -35,8 +36,8 @@ func readModule(bpfDir, moduleName string, debug bool) (bytecode.AssetReader, er return nil, fmt.Errorf("couldn't find asset: %s", err) } - telemetrymu.Lock() - defer telemetrymu.Unlock() + telemetryMu.Lock() + defer telemetryMu.Unlock() prebuiltModulesInUse[moduleName] = struct{}{} return ebpfReader, nil } @@ -66,7 +67,8 @@ func ReadOffsetBPFModule(bpfDir string, debug bool) (bytecode.AssetReader, error return readModule(bpfDir, "offset-guess", debug) } -func ReadFentryTracerModule(bpfDir string, debug bool) (bytecode.AssetReader, error) { //nolint:revive // TODO +// ReadFentryTracerModule from the asset file +func ReadFentryTracerModule(bpfDir string, debug bool) (bytecode.AssetReader, error) { return readModule(bpfDir, "tracer-fentry", debug) } @@ -75,9 +77,10 @@ func ReadConntrackBPFModule(bpfDir string, debug bool) (bytecode.AssetReader, er return readModule(bpfDir, "conntrack", debug) } -func GetModulesInUse() []string { //nolint:revive // TODO - telemetrymu.Lock() - defer telemetrymu.Unlock() +// GetModulesInUse returns a list of modules in use +func GetModulesInUse() []string { + telemetryMu.Lock() + defer telemetryMu.Unlock() return maps.Keys(prebuiltModulesInUse) } diff --git a/pkg/network/netlink/consumer_test.go b/pkg/network/netlink/consumer_test.go index ef3b8008852bb..17e39646a7b52 100644 --- a/pkg/network/netlink/consumer_test.go +++ b/pkg/network/netlink/consumer_test.go @@ -47,8 +47,6 @@ func TestConsumerKeepsRunningAfterCircuitBreakerTrip(t *testing.T) { go func() { defer close(exited) - for range ev { //nolint:revive // TODO - } }() isRecvLoopRunning := c.recvLoopRunning.Load diff --git a/pkg/network/tracer/connection/batch_extractor.go b/pkg/network/tracer/connection/batch_extractor.go index bfe97da86c784..27a836ba79d7e 100644 --- a/pkg/network/tracer/connection/batch_extractor.go +++ b/pkg/network/tracer/connection/batch_extractor.go @@ -5,7 +5,7 @@ //go:build linux_bpf -package connection //nolint:revive // TODO +package connection import ( "time" diff --git a/pkg/network/tracer/connection/ebpf_tracer.go b/pkg/network/tracer/connection/ebpf_tracer.go index af8e7f2a573bf..56350cbd1f1eb 100644 --- a/pkg/network/tracer/connection/ebpf_tracer.go +++ b/pkg/network/tracer/connection/ebpf_tracer.go @@ -5,6 +5,7 @@ //go:build linux_bpf +// Package connection provides tracing for connections package connection import ( @@ -46,17 +47,18 @@ const ( var tcpOngoingConnectMapTTL = 30 * time.Minute.Nanoseconds() var tlsTagsMapTTL = 3 * time.Minute.Nanoseconds() -var EbpfTracerTelemetry = struct { //nolint:revive // TODO +// EbpfTracerTelemetry holds telemetry from the EBPF tracer +var EbpfTracerTelemetry = struct { connections telemetry.Gauge tcpFailedConnects *prometheus.Desc - TcpSentMiscounts *prometheus.Desc //nolint:revive // TODO - unbatchedTcpClose *prometheus.Desc //nolint:revive // TODO - unbatchedUdpClose *prometheus.Desc //nolint:revive // TODO - UdpSendsProcessed *prometheus.Desc //nolint:revive // TODO - UdpSendsMissed *prometheus.Desc //nolint:revive // TODO - UdpDroppedConns *prometheus.Desc //nolint:revive // TODO - // unsupportedTcpFailures is a counter measuring the number of attempts to flush a TCP failure that is not supported - unsupportedTcpFailures *prometheus.Desc //nolint:revive // TODO + tcpSentMiscounts *prometheus.Desc + unbatchedTCPClose *prometheus.Desc + unbatchedUDPClose *prometheus.Desc + udpSendsProcessed *prometheus.Desc + udpSendsMissed *prometheus.Desc + udpDroppedConns *prometheus.Desc + // unsupportedTCPFailures is a counter measuring the number of attempts to flush a TCP failure that is not supported + unsupportedTCPFailures *prometheus.Desc // tcpDoneMissingPid is a counter measuring the number of TCP connections with a PID mismatch between tcp_connect and tcp_done tcpDoneMissingPid *prometheus.Desc tcpConnectFailedTuple *prometheus.Desc @@ -70,23 +72,23 @@ var EbpfTracerTelemetry = struct { //nolint:revive // TODO iterationDups telemetry.Counter iterationAborts telemetry.Counter - lastTcpFailedConnects *atomic.Int64 //nolint:revive // TODO - LastTcpSentMiscounts *atomic.Int64 //nolint:revive // TODO - lastUnbatchedTcpClose *atomic.Int64 //nolint:revive // TODO - lastUnbatchedUdpClose *atomic.Int64 //nolint:revive // TODO - lastUdpSendsProcessed *atomic.Int64 //nolint:revive // TODO - lastUdpSendsMissed *atomic.Int64 //nolint:revive // TODO - lastUdpDroppedConns *atomic.Int64 //nolint:revive // TODO - // lastUnsupportedTcpFailures is a counter measuring the diff between the last two values of unsupportedTcpFailures - lastUnsupportedTcpFailures *atomic.Int64 //nolint:revive // TODO - // lastTcpDoneMissingPid is a counter measuring the diff between the last two values of tcpDoneMissingPid - lastTcpDoneMissingPid *atomic.Int64 //nolint:revive // TODO - lastTcpConnectFailedTuple *atomic.Int64 //nolint:revive // TODO - lastTcpDoneFailedTuple *atomic.Int64 //nolint:revive // TODO - lastTcpFinishConnectFailedTuple *atomic.Int64 //nolint:revive // TODO - lastTcpCloseTargetFailures *atomic.Int64 //nolint:revive // TODO - lastTcpDoneConnectionFlush *atomic.Int64 //nolint:revive // TODO - lastTcpCloseConnectionFlush *atomic.Int64 //nolint:revive // TODO + lastTCPFailedConnects *atomic.Int64 + LastTCPSentMiscounts *atomic.Int64 + lastUnbatchedTCPClose *atomic.Int64 + lastUnbatchedUDPClose *atomic.Int64 + lastUDPSendsProcessed *atomic.Int64 + lastUDPSendsMissed *atomic.Int64 + lastUDPDroppedConns *atomic.Int64 + // lastUnsupportedTCPFailures is a counter measuring the diff between the last two values of unsupportedTCPFailures + lastUnsupportedTCPFailures *atomic.Int64 + // lastTCPDoneMissingPid is a counter measuring the diff between the last two values of tcpDoneMissingPid + lastTCPDoneMissingPid *atomic.Int64 + lastTCPConnectFailedTuple *atomic.Int64 + lastTCPDoneFailedTuple *atomic.Int64 + lastTCPFinishConnectFailedTuple *atomic.Int64 + lastTCPCloseTargetFailures *atomic.Int64 + lastTCPDoneConnectionFlush *atomic.Int64 + lastTCPCloseConnectionFlush *atomic.Int64 }{ telemetry.NewGauge(connTracerModuleName, "connections", []string{"ip_proto", "family"}, "Gauge measuring the number of active connections in the EBPF map"), prometheus.NewDesc(connTracerModuleName+"__tcp_failed_connects", "Counter measuring the number of failed TCP connections in the EBPF map", nil, nil), @@ -558,13 +560,13 @@ func (t *ebpfTracer) getEBPFTelemetry() *netebpf.Telemetry { // Describe returns all descriptions of the collector func (t *ebpfTracer) Describe(ch chan<- *prometheus.Desc) { ch <- EbpfTracerTelemetry.tcpFailedConnects - ch <- EbpfTracerTelemetry.TcpSentMiscounts - ch <- EbpfTracerTelemetry.unbatchedTcpClose - ch <- EbpfTracerTelemetry.unbatchedUdpClose - ch <- EbpfTracerTelemetry.UdpSendsProcessed - ch <- EbpfTracerTelemetry.UdpSendsMissed - ch <- EbpfTracerTelemetry.UdpDroppedConns - ch <- EbpfTracerTelemetry.unsupportedTcpFailures + ch <- EbpfTracerTelemetry.tcpSentMiscounts + ch <- EbpfTracerTelemetry.unbatchedTCPClose + ch <- EbpfTracerTelemetry.unbatchedUDPClose + ch <- EbpfTracerTelemetry.udpSendsProcessed + ch <- EbpfTracerTelemetry.udpSendsMissed + ch <- EbpfTracerTelemetry.udpDroppedConns + ch <- EbpfTracerTelemetry.unsupportedTCPFailures ch <- EbpfTracerTelemetry.tcpDoneMissingPid ch <- EbpfTracerTelemetry.tcpConnectFailedTuple ch <- EbpfTracerTelemetry.tcpDoneFailedTuple @@ -580,64 +582,64 @@ func (t *ebpfTracer) Collect(ch chan<- prometheus.Metric) { if ebpfTelemetry == nil { return } - delta := int64(ebpfTelemetry.Tcp_failed_connect) - EbpfTracerTelemetry.lastTcpFailedConnects.Load() - EbpfTracerTelemetry.lastTcpFailedConnects.Store(int64(ebpfTelemetry.Tcp_failed_connect)) + delta := int64(ebpfTelemetry.Tcp_failed_connect) - EbpfTracerTelemetry.lastTCPFailedConnects.Load() + EbpfTracerTelemetry.lastTCPFailedConnects.Store(int64(ebpfTelemetry.Tcp_failed_connect)) ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.tcpFailedConnects, prometheus.CounterValue, float64(delta)) - delta = int64(ebpfTelemetry.Tcp_sent_miscounts) - EbpfTracerTelemetry.LastTcpSentMiscounts.Load() - EbpfTracerTelemetry.LastTcpSentMiscounts.Store(int64(ebpfTelemetry.Tcp_sent_miscounts)) - ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.TcpSentMiscounts, prometheus.CounterValue, float64(delta)) + delta = int64(ebpfTelemetry.Tcp_sent_miscounts) - EbpfTracerTelemetry.LastTCPSentMiscounts.Load() + EbpfTracerTelemetry.LastTCPSentMiscounts.Store(int64(ebpfTelemetry.Tcp_sent_miscounts)) + ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.tcpSentMiscounts, prometheus.CounterValue, float64(delta)) - delta = int64(ebpfTelemetry.Unbatched_tcp_close) - EbpfTracerTelemetry.lastUnbatchedTcpClose.Load() - EbpfTracerTelemetry.lastUnbatchedTcpClose.Store(int64(ebpfTelemetry.Unbatched_tcp_close)) - ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.unbatchedTcpClose, prometheus.CounterValue, float64(delta)) + delta = int64(ebpfTelemetry.Unbatched_tcp_close) - EbpfTracerTelemetry.lastUnbatchedTCPClose.Load() + EbpfTracerTelemetry.lastUnbatchedTCPClose.Store(int64(ebpfTelemetry.Unbatched_tcp_close)) + ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.unbatchedTCPClose, prometheus.CounterValue, float64(delta)) - delta = int64(ebpfTelemetry.Unbatched_udp_close) - EbpfTracerTelemetry.lastUnbatchedUdpClose.Load() - EbpfTracerTelemetry.lastUnbatchedUdpClose.Store(int64(ebpfTelemetry.Unbatched_udp_close)) - ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.unbatchedUdpClose, prometheus.CounterValue, float64(delta)) + delta = int64(ebpfTelemetry.Unbatched_udp_close) - EbpfTracerTelemetry.lastUnbatchedUDPClose.Load() + EbpfTracerTelemetry.lastUnbatchedUDPClose.Store(int64(ebpfTelemetry.Unbatched_udp_close)) + ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.unbatchedUDPClose, prometheus.CounterValue, float64(delta)) - delta = int64(ebpfTelemetry.Udp_sends_processed) - EbpfTracerTelemetry.lastUdpSendsProcessed.Load() - EbpfTracerTelemetry.lastUdpSendsProcessed.Store(int64(ebpfTelemetry.Udp_sends_processed)) - ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.UdpSendsProcessed, prometheus.CounterValue, float64(delta)) + delta = int64(ebpfTelemetry.Udp_sends_processed) - EbpfTracerTelemetry.lastUDPSendsProcessed.Load() + EbpfTracerTelemetry.lastUDPSendsProcessed.Store(int64(ebpfTelemetry.Udp_sends_processed)) + ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.udpSendsProcessed, prometheus.CounterValue, float64(delta)) - delta = int64(ebpfTelemetry.Udp_sends_missed) - EbpfTracerTelemetry.lastUdpSendsMissed.Load() - EbpfTracerTelemetry.lastUdpSendsMissed.Store(int64(ebpfTelemetry.Udp_sends_missed)) - ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.UdpSendsMissed, prometheus.CounterValue, float64(delta)) + delta = int64(ebpfTelemetry.Udp_sends_missed) - EbpfTracerTelemetry.lastUDPSendsMissed.Load() + EbpfTracerTelemetry.lastUDPSendsMissed.Store(int64(ebpfTelemetry.Udp_sends_missed)) + ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.udpSendsMissed, prometheus.CounterValue, float64(delta)) - delta = int64(ebpfTelemetry.Udp_dropped_conns) - EbpfTracerTelemetry.lastUdpDroppedConns.Load() - EbpfTracerTelemetry.lastUdpDroppedConns.Store(int64(ebpfTelemetry.Udp_dropped_conns)) - ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.UdpDroppedConns, prometheus.CounterValue, float64(delta)) + delta = int64(ebpfTelemetry.Udp_dropped_conns) - EbpfTracerTelemetry.lastUDPDroppedConns.Load() + EbpfTracerTelemetry.lastUDPDroppedConns.Store(int64(ebpfTelemetry.Udp_dropped_conns)) + ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.udpDroppedConns, prometheus.CounterValue, float64(delta)) - delta = int64(ebpfTelemetry.Unsupported_tcp_failures) - EbpfTracerTelemetry.lastUnsupportedTcpFailures.Load() - EbpfTracerTelemetry.lastUnsupportedTcpFailures.Store(int64(ebpfTelemetry.Unsupported_tcp_failures)) - ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.unsupportedTcpFailures, prometheus.CounterValue, float64(delta)) + delta = int64(ebpfTelemetry.Unsupported_tcp_failures) - EbpfTracerTelemetry.lastUnsupportedTCPFailures.Load() + EbpfTracerTelemetry.lastUnsupportedTCPFailures.Store(int64(ebpfTelemetry.Unsupported_tcp_failures)) + ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.unsupportedTCPFailures, prometheus.CounterValue, float64(delta)) - delta = int64(ebpfTelemetry.Tcp_done_missing_pid) - EbpfTracerTelemetry.lastTcpDoneMissingPid.Load() - EbpfTracerTelemetry.lastTcpDoneMissingPid.Store(int64(ebpfTelemetry.Tcp_done_missing_pid)) + delta = int64(ebpfTelemetry.Tcp_done_missing_pid) - EbpfTracerTelemetry.lastTCPDoneMissingPid.Load() + EbpfTracerTelemetry.lastTCPDoneMissingPid.Store(int64(ebpfTelemetry.Tcp_done_missing_pid)) ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.tcpDoneMissingPid, prometheus.CounterValue, float64(delta)) - delta = int64(ebpfTelemetry.Tcp_connect_failed_tuple) - EbpfTracerTelemetry.lastTcpConnectFailedTuple.Load() - EbpfTracerTelemetry.lastTcpConnectFailedTuple.Store(int64(ebpfTelemetry.Tcp_connect_failed_tuple)) + delta = int64(ebpfTelemetry.Tcp_connect_failed_tuple) - EbpfTracerTelemetry.lastTCPConnectFailedTuple.Load() + EbpfTracerTelemetry.lastTCPConnectFailedTuple.Store(int64(ebpfTelemetry.Tcp_connect_failed_tuple)) ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.tcpConnectFailedTuple, prometheus.CounterValue, float64(delta)) - delta = int64(ebpfTelemetry.Tcp_done_failed_tuple) - EbpfTracerTelemetry.lastTcpDoneFailedTuple.Load() - EbpfTracerTelemetry.lastTcpDoneFailedTuple.Store(int64(ebpfTelemetry.Tcp_done_failed_tuple)) + delta = int64(ebpfTelemetry.Tcp_done_failed_tuple) - EbpfTracerTelemetry.lastTCPDoneFailedTuple.Load() + EbpfTracerTelemetry.lastTCPDoneFailedTuple.Store(int64(ebpfTelemetry.Tcp_done_failed_tuple)) ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.tcpDoneFailedTuple, prometheus.CounterValue, float64(delta)) - delta = int64(ebpfTelemetry.Tcp_finish_connect_failed_tuple) - EbpfTracerTelemetry.lastTcpFinishConnectFailedTuple.Load() - EbpfTracerTelemetry.lastTcpFinishConnectFailedTuple.Store(int64(ebpfTelemetry.Tcp_finish_connect_failed_tuple)) + delta = int64(ebpfTelemetry.Tcp_finish_connect_failed_tuple) - EbpfTracerTelemetry.lastTCPFinishConnectFailedTuple.Load() + EbpfTracerTelemetry.lastTCPFinishConnectFailedTuple.Store(int64(ebpfTelemetry.Tcp_finish_connect_failed_tuple)) ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.tcpFinishConnectFailedTuple, prometheus.CounterValue, float64(delta)) - delta = int64(ebpfTelemetry.Tcp_close_target_failures) - EbpfTracerTelemetry.lastTcpCloseTargetFailures.Load() - EbpfTracerTelemetry.lastTcpCloseTargetFailures.Store(int64(ebpfTelemetry.Tcp_close_target_failures)) + delta = int64(ebpfTelemetry.Tcp_close_target_failures) - EbpfTracerTelemetry.lastTCPCloseTargetFailures.Load() + EbpfTracerTelemetry.lastTCPCloseTargetFailures.Store(int64(ebpfTelemetry.Tcp_close_target_failures)) ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.tcpCloseTargetFailures, prometheus.CounterValue, float64(delta)) - delta = int64(ebpfTelemetry.Tcp_done_connection_flush) - EbpfTracerTelemetry.lastTcpDoneConnectionFlush.Load() - EbpfTracerTelemetry.lastTcpDoneConnectionFlush.Store(int64(ebpfTelemetry.Tcp_done_connection_flush)) + delta = int64(ebpfTelemetry.Tcp_done_connection_flush) - EbpfTracerTelemetry.lastTCPDoneConnectionFlush.Load() + EbpfTracerTelemetry.lastTCPDoneConnectionFlush.Store(int64(ebpfTelemetry.Tcp_done_connection_flush)) ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.tcpDoneConnectionFlush, prometheus.CounterValue, float64(delta)) - delta = int64(ebpfTelemetry.Tcp_close_connection_flush) - EbpfTracerTelemetry.lastTcpCloseConnectionFlush.Load() - EbpfTracerTelemetry.lastTcpCloseConnectionFlush.Store(int64(ebpfTelemetry.Tcp_close_connection_flush)) + delta = int64(ebpfTelemetry.Tcp_close_connection_flush) - EbpfTracerTelemetry.lastTCPCloseConnectionFlush.Load() + EbpfTracerTelemetry.lastTCPCloseConnectionFlush.Store(int64(ebpfTelemetry.Tcp_close_connection_flush)) ch <- prometheus.MustNewConstMetric(EbpfTracerTelemetry.tcpCloseConnectionFlush, prometheus.CounterValue, float64(delta)) } diff --git a/pkg/network/tracer/connection/fentry/manager.go b/pkg/network/tracer/connection/fentry/manager.go index deddd6708f5fd..6936861aca94a 100644 --- a/pkg/network/tracer/connection/fentry/manager.go +++ b/pkg/network/tracer/connection/fentry/manager.go @@ -5,7 +5,8 @@ //go:build linux_bpf -package fentry //nolint:revive // TODO +// Package fentry provides connection tracing for fentry +package fentry import ( manager "github.com/DataDog/ebpf-manager" diff --git a/pkg/network/tracer/connection/fentry/probes.go b/pkg/network/tracer/connection/fentry/probes.go index 02ad4d6937c7c..3724d1be0dafe 100644 --- a/pkg/network/tracer/connection/fentry/probes.go +++ b/pkg/network/tracer/connection/fentry/probes.go @@ -46,8 +46,8 @@ const ( udpSendSkb = "kprobe__udp_send_skb" skbFreeDatagramLocked = "skb_free_datagram_locked" - __skbFreeDatagramLocked = "__skb_free_datagram_locked" //nolint:revive // TODO - skbConsumeUdp = "skb_consume_udp" //nolint:revive // TODO + __skbFreeDatagramLocked = "__skb_free_datagram_locked" // nolint:revive + skbConsumeUDP = "skb_consume_udp" udpv6RecvMsg = "udpv6_recvmsg" udpv6RecvMsgReturn = "udpv6_recvmsg_exit" @@ -112,7 +112,7 @@ var programs = map[string]struct{}{ udpv6DestroySockReturn: {}, skbFreeDatagramLocked: {}, __skbFreeDatagramLocked: {}, - skbConsumeUdp: {}, + skbConsumeUDP: {}, tcpRecvMsgPre5190Return: {}, udpRecvMsgPre5190Return: {}, udpv6RecvMsgPre5190Return: {}, @@ -203,7 +203,7 @@ func enableAdvancedUDP(enabled map[string]struct{}) error { return fmt.Errorf("error verifying kernel function presence: %s", err) } if _, miss := missing["skb_consume_udp"]; !miss { - enableProgram(enabled, skbConsumeUdp) + enableProgram(enabled, skbConsumeUDP) } else if _, miss := missing["__skb_free_datagram_locked"]; !miss { enableProgram(enabled, __skbFreeDatagramLocked) } else if _, miss := missing["skb_free_datagram_locked"]; !miss { diff --git a/pkg/network/tracer/connection/fentry/tracer.go b/pkg/network/tracer/connection/fentry/tracer.go index 0a88ad6710b74..42e96ba6f4129 100644 --- a/pkg/network/tracer/connection/fentry/tracer.go +++ b/pkg/network/tracer/connection/fentry/tracer.go @@ -26,7 +26,8 @@ import ( const probeUID = "net" -var ErrorNotSupported = errors.New("fentry tracer is only supported on Fargate") //nolint:revive // TODO +// ErrorNotSupported is the error when entry tracer is not supported on an environment +var ErrorNotSupported = errors.New("fentry tracer is only supported on Fargate") // LoadTracer loads a new tracer func LoadTracer(config *config.Config, mgrOpts manager.Options, connCloseEventHandler *perf.EventHandler) (*ddebpf.Manager, func(), error) { diff --git a/pkg/network/tracer/connection/kprobe/compile.go b/pkg/network/tracer/connection/kprobe/compile.go index a515480ba5194..9a8c2855f755a 100644 --- a/pkg/network/tracer/connection/kprobe/compile.go +++ b/pkg/network/tracer/connection/kprobe/compile.go @@ -5,7 +5,8 @@ //go:build linux_bpf -package kprobe //nolint:revive // TODO +// Package kprobe supports kprobe connecting tracing +package kprobe import ( "github.com/DataDog/datadog-agent/pkg/ebpf/bytecode/runtime" diff --git a/pkg/network/tracer/connection/kprobe/tracer.go b/pkg/network/tracer/connection/kprobe/tracer.go index 0fd21dd880531..09bee0db65855 100644 --- a/pkg/network/tracer/connection/kprobe/tracer.go +++ b/pkg/network/tracer/connection/kprobe/tracer.go @@ -31,12 +31,16 @@ import ( const probeUID = "net" -type TracerType int //nolint:revive // TODO +// TracerType is the type of tracer +type TracerType int const ( - TracerTypePrebuilt TracerType = iota //nolint:revive // TODO - TracerTypeRuntimeCompiled //nolint:revive // TODO - TracerTypeCORE //nolint:revive // TODO + // TracerTypePrebuilt is the prebuilt tracer type + TracerTypePrebuilt TracerType = iota + // TracerTypeRuntimeCompiled is the runtime compiled tracer type + TracerTypeRuntimeCompiled + // TracerTypeCORE is the CORE tracer type + TracerTypeCORE ) var ( diff --git a/pkg/network/tracer/connection/tracer.go b/pkg/network/tracer/connection/tracer.go index 7b73e332ba1a8..3720758649705 100644 --- a/pkg/network/tracer/connection/tracer.go +++ b/pkg/network/tracer/connection/tracer.go @@ -22,11 +22,16 @@ import ( type TracerType int const ( - TracerTypeKProbePrebuilt TracerType = iota //nolint:revive // TODO - TracerTypeKProbeRuntimeCompiled //nolint:revive // TODO - TracerTypeKProbeCORE //nolint:revive // TODO - TracerTypeFentry //nolint:revive // TODO - TracerTypeEbpfless //nolint:revive // TODO + // TracerTypeKProbePrebuilt is the TracerType for prebuilt kprobe tracer + TracerTypeKProbePrebuilt TracerType = iota + // TracerTypeKProbeRuntimeCompiled is the TracerType for the runtime compiled kprobe tracer + TracerTypeKProbeRuntimeCompiled + // TracerTypeKProbeCORE is the TracerType for the CORE kprobe tracer + TracerTypeKProbeCORE + // TracerTypeFentry is the TracerType for the fentry tracer + TracerTypeFentry + // TracerTypeEbpfless is the TracerType for the EBPF-less tracer + TracerTypeEbpfless ) const ( diff --git a/pkg/network/tracer/offsetguess/conntrack.go b/pkg/network/tracer/offsetguess/conntrack.go index 379340c44d89f..60752a56ae901 100644 --- a/pkg/network/tracer/offsetguess/conntrack.go +++ b/pkg/network/tracer/offsetguess/conntrack.go @@ -5,7 +5,8 @@ //go:build linux_bpf -package offsetguess //nolint:revive // TODO +// Package offsetguess provides offsetguesses for tracer +package offsetguess import ( "fmt" @@ -44,7 +45,8 @@ type conntrackOffsetGuesser struct { udpv6Enabled uint64 } -func NewConntrackOffsetGuesser(cfg *config.Config) (OffsetGuesser, error) { //nolint:revive // TODO +// NewConntrackOffsetGuesser creates a new OffsetGuesser +func NewConntrackOffsetGuesser(cfg *config.Config) (OffsetGuesser, error) { tcpv6Enabled, udpv6Enabled := getIpv6Configuration(cfg) tcpv6EnabledConst, udpv6EnabledConst := boolToUint64(tcpv6Enabled), boolToUint64(udpv6Enabled) return &conntrackOffsetGuesser{ diff --git a/pkg/network/tracer/offsetguess/offsetguess.go b/pkg/network/tracer/offsetguess/offsetguess.go index 8889b0e837fd6..164d629fb540d 100644 --- a/pkg/network/tracer/offsetguess/offsetguess.go +++ b/pkg/network/tracer/offsetguess/offsetguess.go @@ -80,7 +80,8 @@ var whatString = map[GuessWhat]string{ GuessCtNet: "conntrack network namespace", } -type OffsetGuesser interface { //nolint:revive // TODO +// OffsetGuesser provides offset guesses +type OffsetGuesser interface { Manager() *manager.Manager Probes(c *config.Config) (map[string]struct{}, error) Guess(c *config.Config) ([]manager.ConstantEditor, error) @@ -109,9 +110,6 @@ type fieldValues struct { daddrFl6 [4]uint32 sportFl6 uint16 dportFl6 uint16 - - //nolint:unused // TODO(NET) Fix unused linter - ctStatus uint32 } func idPair(name probes.ProbeFuncName) manager.ProbeIdentificationPair { @@ -186,7 +184,8 @@ func setupOffsetGuesser(guesser OffsetGuesser, config *config.Config, buf byteco return nil } -func RunOffsetGuessing(cfg *config.Config, buf bytecode.AssetReader, newGuesser func() (OffsetGuesser, error)) (editors []manager.ConstantEditor, err error) { //nolint:revive // TODO +// RunOffsetGuessing will run offset guessing +func RunOffsetGuessing(cfg *config.Config, buf bytecode.AssetReader, newGuesser func() (OffsetGuesser, error)) (editors []manager.ConstantEditor, err error) { // Offset guessing has been flaky for some customers, so if it fails we'll retry it up to 5 times start := time.Now() for i := 0; i < 5; i++ { diff --git a/pkg/network/tracer/offsetguess/tracer.go b/pkg/network/tracer/offsetguess/tracer.go index 20b4c4f4b3c45..1f2fa420074df 100644 --- a/pkg/network/tracer/offsetguess/tracer.go +++ b/pkg/network/tracer/offsetguess/tracer.go @@ -77,7 +77,8 @@ type tracerOffsetGuesser struct { guessUDPv6 bool } -func NewTracerOffsetGuesser() (OffsetGuesser, error) { //nolint:revive // TODO +// NewTracerOffsetGuesser creates a new OffsetGuesser +func NewTracerOffsetGuesser() (OffsetGuesser, error) { return &tracerOffsetGuesser{ m: &manager.Manager{ Maps: []*manager.Map{ @@ -161,7 +162,7 @@ func expectedValues(conn net.Conn) (*fieldValues, error) { return nil, err } - tcpInfo, err := TcpGetInfo(conn) + tcpInfo, err := TCPGetInfo(conn) if err != nil { return nil, err } @@ -286,7 +287,8 @@ func uint32ArrayFromIPv6(ip net.IP) (addr [4]uint32, err error) { // IPv6LinkLocalPrefix is only exposed for testing purposes var IPv6LinkLocalPrefix = "fe80::" -func GetIPv6LinkLocalAddress() ([]*net.UDPAddr, error) { //nolint:revive // TODO +// GetIPv6LinkLocalAddress returns the link local addresses +func GetIPv6LinkLocalAddress() ([]*net.UDPAddr, error) { ints, err := net.Interfaces() if err != nil { return nil, err @@ -1017,7 +1019,7 @@ func (e *tracerEventGenerator) Generate(status GuessWhat, expected *fieldValues) } // This triggers the KProbe handler attached to `tcp_getsockopt` - _, err := TcpGetInfo(e.conn) + _, err := TCPGetInfo(e.conn) return err } @@ -1080,12 +1082,12 @@ func acceptHandler(l net.Listener) { } } -// TcpGetInfo obtains information from a TCP socket via GETSOCKOPT(2) system call. +// TCPGetInfo obtains information from a TCP socket via GETSOCKOPT(2) system call. // The motivation for using this is twofold: 1) it is a way of triggering the kprobe // responsible for the V4 offset guessing in kernel-space and 2) using it we can obtain // in user-space TCP socket information such as RTT and use it for setting the expected // values in the `fieldValues` struct. -func TcpGetInfo(conn net.Conn) (*unix.TCPInfo, error) { //nolint:revive // TODO +func TCPGetInfo(conn net.Conn) (*unix.TCPInfo, error) { tcpConn, ok := conn.(*net.TCPConn) if !ok { return nil, fmt.Errorf("not a TCPConn") @@ -1149,7 +1151,8 @@ func newUDPServer(addr string) (string, func(), error) { return ln.LocalAddr().String(), doneFn, nil } -var TracerOffsets tracerOffsets //nolint:revive // TODO +// TracerOffsets is the global tracer offsets +var TracerOffsets tracerOffsets type tracerOffsets struct { offsets []manager.ConstantEditor diff --git a/pkg/network/tracer/offsetguess_test.go b/pkg/network/tracer/offsetguess_test.go index a73523d48207b..b024e0e2ccfca 100644 --- a/pkg/network/tracer/offsetguess_test.go +++ b/pkg/network/tracer/offsetguess_test.go @@ -300,7 +300,7 @@ func testOffsetGuess(t *testing.T) { } var offset uint64 - var name offsetT = o //nolint:revive // TODO + var name = o require.NoError(t, mp.Lookup(&name, &offset)) assert.Equal(t, offset, consts[o], "unexpected offset for %s", o) t.Logf("offset %s expected: %d guessed: %d", o, offset, consts[o]) diff --git a/pkg/network/tracer/tracer_dump_conntrack.go b/pkg/network/tracer/tracer_dump_conntrack.go index d1d4f0680ee07..8bd078bbd1bff 100644 --- a/pkg/network/tracer/tracer_dump_conntrack.go +++ b/pkg/network/tracer/tracer_dump_conntrack.go @@ -58,7 +58,7 @@ func (table *DebugConntrackTable) WriteTo(w io.Writer, maxEntries int) error { // in this case the table itself is incomplete due to closing the netlink socket part-way if table.IsTruncated { - _, err = fmt.Fprintln(w, "netlink table truncated due to response timeout, some entries may be missing") //nolint:ineffassign, staticcheck // TODO + _, _ = fmt.Fprintln(w, "netlink table truncated due to response timeout, some entries may be missing") } // used to stop writing once we reach maxEntries diff --git a/pkg/network/tracer/tracer_linux_test.go b/pkg/network/tracer/tracer_linux_test.go index a94e2700aac4b..bcd9ad785c7ff 100644 --- a/pkg/network/tracer/tracer_linux_test.go +++ b/pkg/network/tracer/tracer_linux_test.go @@ -308,7 +308,7 @@ func (s *TracerSuite) TestTCPRTT() { require.NoError(t, err) // Obtain information from a TCP socket via GETSOCKOPT(2) system call. - tcpInfo, err := offsetguess.TcpGetInfo(c) + tcpInfo, err := offsetguess.TCPGetInfo(c) require.NoError(t, err) require.EventuallyWithT(t, func(ct *assert.CollectT) { @@ -386,7 +386,7 @@ func (s *TracerSuite) TestTCPMiscount() { assert.False(t, uint64(len(x)) == conn.Monotonic.SentBytes) } - assert.NotZero(t, connection.EbpfTracerTelemetry.LastTcpSentMiscounts.Load()) + assert.NotZero(t, connection.EbpfTracerTelemetry.LastTCPSentMiscounts.Load()) } func (s *TracerSuite) TestConnectionExpirationRegression() { @@ -1200,7 +1200,7 @@ func (s *TracerSuite) TestSelfConnect() { // sets up two udp sockets talking to each other locally. // returns (listener, dialer) -func setupUdpSockets(t *testing.T, udpnet, ip string) (*net.UDPConn, *net.UDPConn) { //nolint:revive // TODO +func setupUDPSockets(t *testing.T, udpnet, ip string) (*net.UDPConn, *net.UDPConn) { serverAddr := fmt.Sprintf("%s:%d", ip, 0) laddr, err := net.ResolveUDPAddr(udpnet, serverAddr) @@ -1246,7 +1246,7 @@ func testUDPPeekCount(t *testing.T, udpnet, ip string) { config := testConfig() tr := setupTracer(t, config) - ln, c := setupUdpSockets(t, udpnet, ip) + ln, c := setupUDPSockets(t, udpnet, ip) msg := []byte("asdf") _, err := c.Write(msg) @@ -1335,7 +1335,7 @@ func testUDPPacketSumming(t *testing.T, udpnet, ip string) { config := testConfig() tr := setupTracer(t, config) - ln, c := setupUdpSockets(t, udpnet, ip) + ln, c := setupUDPSockets(t, udpnet, ip) msg := []byte("asdf") // send UDP packets of increasing length @@ -1540,7 +1540,7 @@ func testUDPReusePort(t *testing.T, udpnet string, ip string) { // Iterate through active connections until we find connection created above, and confirm send + recv counts t.Logf("port: %d", assignedPort) - assert.EventuallyWithT(t, func(ct *assert.CollectT) { //nolint:revive // TODO + assert.EventuallyWithT(t, func(ct *assert.CollectT) { // use t instead of ct because getConnections uses require (not assert), and we get a better error message that way connections := getConnections(ct, tr) diff --git a/pkg/process/metadata/parser/dockerproxy.go b/pkg/process/metadata/parser/dockerproxy.go index 52c8f48450b48..1ef92e547671b 100644 --- a/pkg/process/metadata/parser/dockerproxy.go +++ b/pkg/process/metadata/parser/dockerproxy.go @@ -3,7 +3,7 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2016-present Datadog, Inc. -//nolint:revive // TODO(PROC) Fix revive linter +// Package parser parses service metadata package parser import ( @@ -37,7 +37,7 @@ func NewDockerProxy() *DockerProxy { } } -//nolint:revive // TODO(PROC) Fix revive linter +// Extract the process metadata from the processes func (d *DockerProxy) Extract(processes map[int32]*procutil.Process) { proxyByPID := make(map[int32]*proxy) proxyByTarget := make(map[model.ContainerAddr]*proxy) diff --git a/pkg/process/metadata/parser/scm_reader.go b/pkg/process/metadata/parser/scm_reader.go index 5de1102b821ab..b368227937fc1 100644 --- a/pkg/process/metadata/parser/scm_reader.go +++ b/pkg/process/metadata/parser/scm_reader.go @@ -19,7 +19,6 @@ func newSCMReader() *scmReader { return &scmReader{} } -//nolint:revive // TODO(PROC) Fix revive linter func (s *scmReader) getServiceInfo(_ uint64) (*WindowsServiceInfo, error) { return nil, fmt.Errorf("scm service info is only available on windows") } diff --git a/pkg/process/metadata/parser/service.go b/pkg/process/metadata/parser/service.go index bacff8563b51c..5aa71d3d648ee 100644 --- a/pkg/process/metadata/parser/service.go +++ b/pkg/process/metadata/parser/service.go @@ -89,7 +89,7 @@ func NewServiceExtractor(enabled, useWindowsServiceName, useImprovedAlgorithm bo } } -//nolint:revive // TODO(PROC) Fix revive linter +// Extract the process metadata from the processes func (d *ServiceExtractor) Extract(processes map[int32]*procutil.Process) { if !d.enabled { return @@ -117,7 +117,7 @@ func (d *ServiceExtractor) Extract(processes map[int32]*procutil.Process) { d.serviceByPID = serviceByPID } -//nolint:revive // TODO(PROC) Fix revive linter +// GetServiceContext returns the service context for the PID func (d *ServiceExtractor) GetServiceContext(pid int32) []string { if !d.enabled { return nil diff --git a/pkg/process/net/resolver/resolver.go b/pkg/process/net/resolver/resolver.go index fc196bfe37f18..59d3afd98a703 100644 --- a/pkg/process/net/resolver/resolver.go +++ b/pkg/process/net/resolver/resolver.go @@ -3,7 +3,7 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2016-present Datadog, Inc. -//nolint:revive // TODO(PROC) Fix revive linter +// Package resolver resolves local Raddrs package resolver import ( @@ -52,6 +52,7 @@ type LocalResolver struct { done chan bool } +// NewLocalResolver creates a new LocalResolver func NewLocalResolver(containerProvider proccontainers.ContainerProvider, clock clock.Clock, maxAddrCacheSize, maxPidCacheSize int) *LocalResolver { return &LocalResolver{ ContainerProvider: containerProvider, @@ -64,12 +65,14 @@ func NewLocalResolver(containerProvider proccontainers.ContainerProvider, clock } } +// Run the resolver func (l *LocalResolver) Run() { pullContainerFrequency := 10 * time.Second ticker := l.Clock.Ticker(pullContainerFrequency) go l.pullContainers(ticker) } +// Stop the resolver func (l *LocalResolver) Stop() { l.done <- true }