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

Run config check in CI #322

Merged
merged 2 commits into from
Nov 16, 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
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,43 @@ jobs:
- name: Build example bpf probes
run: make -j $(nproc) -C examples build

- name: Save built examples into examples.x86_64.tar.gz
run: tar -cvzf examples.x86_64.tar.gz -T <(find examples | grep -E "\.(yaml|bpf.o)$")

- name: Upload examples.x86_64.tar.gz
uses: actions/upload-artifact@v3
with:
name: examples.x86_64.tar.gz
path: examples.x86_64.tar.gz

check-configs-x86_64:
name: Check examples
runs-on: ubuntu-22.04
needs:
- build-ebpf-exporter-docker-x86_64
- build-examples-x86_64-built-in-libbpf
steps:
- uses: actions/checkout@v3

- name: Download examples.x86_64.tar.gz
uses: actions/download-artifact@v3
with:
name: examples.x86_64.tar.gz

- name: Extract examples.x86_64.tar.gz
run: tar -xzvf examples.x86_64.tar.gz

- name: Download ebpf_exporter.x86_64
uses: actions/download-artifact@v3
with:
name: ebpf_exporter.x86_64

- name: Put ebpf_exporter.x86_64 into place
run: mv ebpf_exporter.x86_64 ebpf_exporter && chmod +x ebpf_exporter

- name: Run configuration check
run: make config-check

clang-format:
name: Run clang-format check
runs-on: ubuntu-22.04
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +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}

# * kfree_skb doesn't load in ci, possibly due to older verifier
# * 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_CHECK := $(filter-out $(CONFIGS_TO_IGNORE_IN_CHECK), ${patsubst examples/%.yaml, %, ${wildcard examples/*.yaml}})

export CGO_LDFLAGS := -l bpf

include Makefile.libbpf
Expand Down Expand Up @@ -53,6 +59,10 @@ test: $(LIBBPF_DEPS)
test-privileged:
sudo go test $(GO_TEST_ARGS) ./cgroup

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

.PHONY: build
build: build-static

Expand Down
6 changes: 6 additions & 0 deletions cmd/ebpf_exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
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()
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:https://0 for systemd activation).").Default(":9435").String()
Expand Down Expand Up @@ -72,6 +73,11 @@ func main() {

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

if *configCheck {
log.Printf("Config check successful, exiting")
return
}

err = prometheus.Register(version.NewCollector("ebpf_exporter"))
if err != nil {
log.Fatalf("Error registering version collector: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ func validateMaps(module *libbpfgo.Module, cfg config.Config) error {
maps := []string{}

for _, counter := range cfg.Metrics.Counters {
if counter.Name != "" {
if counter.Name != "" && !counter.PerfEventArray {
maps = append(maps, counter.Name)
}
}
Expand Down