Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/system-probe/api/module/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@rules_go//go:def.bzl", "go_library")
load("//bazel/rules/go:dd_agent_go_test.bzl", "dd_agent_go_test")

go_library(
name = "module",
Expand Down Expand Up @@ -47,3 +48,11 @@ go_library(
"//conditions:default": [],
}),
)

dd_agent_go_test(
name = "module_test",
srcs = ["loader_test.go"],
embed = [":module"],
gotags_sets = [["linux_bpf"]],
deps = ["//pkg/system-probe/config/types"],
)
17 changes: 14 additions & 3 deletions pkg/system-probe/api/module/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type loader struct {
}

func (l *loader) forEachModule(fn func(name sysconfigtypes.ModuleName, mod Module)) {
// Caller must hold l.Lock() (or ensure no concurrent access).
for name, mod := range l.modules {
withModule(name, func() {
fn(name, mod)
Expand Down Expand Up @@ -115,17 +116,27 @@ func Register(cfg *sysconfigtypes.Config, httpMux *http.ServeMux, factories []*F
return fmt.Errorf("error in post-register hook: %w", err)
}

l.Lock()
l.cfg = cfg
if len(l.modules) == 0 {
l.Unlock()
return errors.New("no module could be loaded")
}
l.Unlock()

l.configureTelemetry(deps.Telemetry)

l.Lock()
l.stats = make(map[string]any)
l.forEachModule(func(name sysconfigtypes.ModuleName, mod Module) {
go updateModuleStats(name, mod)
})
for name, mod := range l.modules {
// Snapshot the module so the goroutine doesn't read the map after unlock.
modCopy := mod
nameCopy := name
go func() {
updateModuleStats(nameCopy, modCopy)
}()
}
l.Unlock()
go updateGlobalStats()

return nil
Expand Down
Loading