Skip to content

Commit

Permalink
tetragon: Add map_errors_update_total/map_errors_delete_total metrics
Browse files Browse the repository at this point in the history
Adding map_errors_update_total/map_errors_delete_total metrics,
which replace current tetragon_map_errors_total.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
  • Loading branch information
olsajiri committed Jan 30, 2025
1 parent 79d863d commit db01c3d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 31 deletions.
2 changes: 1 addition & 1 deletion contrib/upgrade-notes/latest.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ Depending on your setup, changes listed here might require a manual intervention

### Metrics

* TBD
* `tetragon_map_errors_total` metric is replaced by `map_errors_update_total` and `map_errors_delete_total`.
12 changes: 10 additions & 2 deletions docs/content/en/docs/reference/metrics.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions pkg/metrics/mapmetrics/mapmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ var (
"Capacity of a BPF map. Expected to be constant.",
nil, []metrics.ConstrainedLabel{MapLabel}, nil,
))
MapErrors = metrics.MustNewCustomGauge(metrics.NewOpts(
consts.MetricsNamespace, "", "map_errors_total",
"The number of errors per map.",
MapErrorsUpdate = metrics.MustNewCustomGauge(metrics.NewOpts(
consts.MetricsNamespace, "", "map_errors_update_total",
"The number of failed updates per map.",
nil, []metrics.ConstrainedLabel{MapLabel}, nil,
))
MapErrorsDelete = metrics.MustNewCustomGauge(metrics.NewOpts(
consts.MetricsNamespace, "", "map_errors_delete_total",
"The number of failed deletes per map.",
nil, []metrics.ConstrainedLabel{MapLabel}, nil,
))
)
41 changes: 16 additions & 25 deletions pkg/observer/observer_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ func NewBPFCollector() metrics.CollectorWithInit {
metrics.CustomMetrics{
mapmetrics.MapSize,
mapmetrics.MapCapacity,
mapmetrics.MapErrors,
mapmetrics.MapErrorsUpdate,
mapmetrics.MapErrorsDelete,
},
collect,
collectForDocs,
Expand Down Expand Up @@ -72,51 +73,41 @@ func collect(ch chan<- prometheus.Metric) {
}
defer mapLink.Close()

updateMapSize(ch, mapLinkStats, name)
ch <- mapmetrics.MapCapacity.MustMetric(
float64(mapLink.MaxEntries()),
name,
)
updateMapErrors(ch, mapLinkStats, name)
update(mapLinkStats, 0, func(sum float64) {
ch <- mapmetrics.MapSize.MustMetric(sum, name)
})
update(mapLinkStats, 1, func(sum float64) {
ch <- mapmetrics.MapErrorsUpdate.MustMetric(sum, name)
})
update(mapLinkStats, 2, func(sum float64) {
ch <- mapmetrics.MapErrorsDelete.MustMetric(sum, name)
})
}
}

func updateMapSize(ch chan<- prometheus.Metric, mapLinkStats *ebpf.Map, name string) {
func update(mapLinkStats *ebpf.Map, key int32, update func(sum float64)) {
var values []int64
if err := mapLinkStats.Lookup(int32(0), &values); err != nil {
return
}

sum := int64(0)
for _, n := range values {
sum += n
}
ch <- mapmetrics.MapSize.MustMetric(
float64(sum),
name,
)
}

func updateMapErrors(ch chan<- prometheus.Metric, mapLinkStats *ebpf.Map, name string) {
var values []int64
if err := mapLinkStats.Lookup(int32(1), &values); err != nil {
if err := mapLinkStats.Lookup(key, &values); err != nil {
return
}

sum := int64(0)
for _, n := range values {
sum += n
}
ch <- mapmetrics.MapErrors.MustMetric(
float64(sum),
name,
)
update(float64(sum))
}

func collectForDocs(ch chan<- prometheus.Metric) {
for _, m := range mapmetrics.MapLabel.Values {
ch <- mapmetrics.MapSize.MustMetric(0, m)
ch <- mapmetrics.MapCapacity.MustMetric(0, m)
ch <- mapmetrics.MapErrors.MustMetric(0, m)
ch <- mapmetrics.MapErrorsUpdate.MustMetric(0, m)
ch <- mapmetrics.MapErrorsDelete.MustMetric(0, m)
}
}

0 comments on commit db01c3d

Please sign in to comment.