Skip to content

Commit

Permalink
metrics: Do not return when we cannot find a _stats map
Browse files Browse the repository at this point in the history
In Tetragon, we have maps ending with _stats that contain metadata about
the main maps. An example is that we have execve_map and
execve_map_stats that contains errors and other information related to
execve_map map.

Now when we fail to open the _stats map, we just stop the loop and we
can possibly miss to check for other maps. This patch change that and
tries for the next map.

Additionally we do not try to collect stats for maps that already end up
with _stats as this would result in _stats_stats map names.

Signed-off-by: Anastasios Papagiannis <tasos.papagiannnis@gmail.com>
  • Loading branch information
tpapagian committed Jan 9, 2024
1 parent 8c7ebee commit 8b7b418
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pkg/observer/observer_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package observer
import (
"fmt"
"path/filepath"
"strings"

"github.com/cilium/ebpf"
"github.com/cilium/tetragon/pkg/metrics/mapmetrics"
Expand All @@ -27,19 +28,29 @@ func (c *bpfCollector) Describe(ch chan<- *prometheus.Desc) {
}

func (c *bpfCollector) Collect(ch chan<- prometheus.Metric) {
statsSuffix := "_stats"
for _, m := range sensors.AllMaps {
name := m.Name
pin := filepath.Join(option.Config.MapDir, name)
pinStats := pin + "_stats"
// Skip map names that end up with _stats.
// This will result in _stats_stats suffixes that we don't care about
if strings.HasSuffix(pin, statsSuffix) {
continue
}
pinStats := pin + statsSuffix

mapLinkStats, err := ebpf.LoadPinnedMap(pinStats, nil)
if err != nil {
return
// If we fail to open the map with _stats suffix
// continue to the next map.
continue
}
defer mapLinkStats.Close()
mapLink, err := ebpf.LoadPinnedMap(pin, nil)
if err != nil {
return
// We have already opened the map with _stats suffix
// so we don't expect that to fail.
continue
}
defer mapLink.Close()

Expand Down

0 comments on commit 8b7b418

Please # to comment.