Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not allow missed attachments with a strict check #326

Merged
merged 1 commit into from
Nov 18, 2023
Merged
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
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ GO_LDFLAGS_VARS := -X $(BUILD_VAR_PREFIX).Version=$(BUILD_VERSION) \

CLANG_FORMAT_FILES = ${wildcard examples/*.c examples/*.h benchmark/probes/*.c benchmark/probes/*.h}

# * cachestat fails to attach in newer kernels (see code)
# * kfree_skb doesn't load in ci, possibly due to older verifier
# * llcstat requires real hardware to attach perf events, which is not present in ci
# * pci doesn't load in ci, possibly due to older verifier
# * unix-socket-backlog requires a newer kernel than we have in ci
CONFIGS_TO_IGNORE_IN_CHECK := kfree_skb pci unix-socket-backlog
CONFIGS_TO_IGNORE_IN_CHECK := cachestat kfree_skb llcstat pci unix-socket-backlog
CONFIGS_TO_CHECK := $(filter-out $(CONFIGS_TO_IGNORE_IN_CHECK), ${patsubst examples/%.yaml, %, ${wildcard examples/*.yaml}})

export CGO_LDFLAGS := -l bpf
Expand Down Expand Up @@ -61,7 +63,7 @@ test-privileged:

.PHONY: config-check
config-check:
sudo ./ebpf_exporter --config.check --config.dir=examples --config.names=$(shell echo $(CONFIGS_TO_CHECK) | tr ' ' ',')
sudo ./ebpf_exporter --capabilities.keep=none --config.check --config.strict --config.dir=examples --config.names=$(shell echo $(CONFIGS_TO_CHECK) | tr ' ' ',')

.PHONY: build
build: build-static
Expand Down
8 changes: 8 additions & 0 deletions cmd/ebpf_exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func main() {
configDir := kingpin.Flag("config.dir", "Config dir path.").Required().ExistingDir()
configNames := kingpin.Flag("config.names", "Comma separated names of configs to load.").Required().String()
configCheck := kingpin.Flag("config.check", "Check whether configs attach and exit.").Bool()
configStrict := kingpin.Flag("config.strict", "Make sure every probe registered.").Bool()
debug := kingpin.Flag("debug", "Enable debug.").Bool()
noLogTime := kingpin.Flag("log.no-timestamps", "Disable timestamps in log.").Bool()
listenAddress := kingpin.Flag("web.listen-address", "The address to listen on for HTTP requests (fd://0 for systemd activation).").Default(":9435").String()
Expand Down Expand Up @@ -74,6 +75,13 @@ func main() {

log.Printf("Started with %d programs found in the config in %dms", len(configs), time.Since(started).Milliseconds())

if *configStrict {
missed := e.MissedAttachments()
if len(missed) > 0 {
log.Fatalf("Missed attachments (module:prog): %v", strings.Join(missed, ", "))
}
}

if *configCheck {
log.Printf("Config check successful, exiting")
return
Expand Down
17 changes: 17 additions & 0 deletions exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,23 @@ func (e *Exporter) Attach() error {
return nil
}

// MissedAttachments returns the list of module:prog names that failed to attach
func (e *Exporter) MissedAttachments() []string {
missed := []string{}

for name, progs := range e.attachedProgs {
for prog, attached := range progs {
if attached {
continue
}

missed = append(missed, fmt.Sprintf("%s:%s", name, prog.Name()))
}
}

return missed
}

func (e *Exporter) passKaddrs(module *libbpfgo.Module, cfg config.Config) error {
if len(e.kaddrs) == 0 {
if err := e.populateKaddrs(); err != nil {
Expand Down