Skip to content

Commit db01c3d

Browse files
committed
tetragon: Add map_errors_update_total/map_errors_delete_total metrics
Adding map_errors_update_total/map_errors_delete_total metrics, which replace current tetragon_map_errors_total. Signed-off-by: Jiri Olsa <[email protected]>
1 parent 79d863d commit db01c3d

File tree

4 files changed

+35
-31
lines changed

4 files changed

+35
-31
lines changed

contrib/upgrade-notes/latest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ Depending on your setup, changes listed here might require a manual intervention
2323

2424
### Metrics
2525

26-
* TBD
26+
* `tetragon_map_errors_total` metric is replaced by `map_errors_update_total` and `map_errors_delete_total`.

docs/content/en/docs/reference/metrics.md

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/metrics/mapmetrics/mapmetrics.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@ var (
2626
"Capacity of a BPF map. Expected to be constant.",
2727
nil, []metrics.ConstrainedLabel{MapLabel}, nil,
2828
))
29-
MapErrors = metrics.MustNewCustomGauge(metrics.NewOpts(
30-
consts.MetricsNamespace, "", "map_errors_total",
31-
"The number of errors per map.",
29+
MapErrorsUpdate = metrics.MustNewCustomGauge(metrics.NewOpts(
30+
consts.MetricsNamespace, "", "map_errors_update_total",
31+
"The number of failed updates per map.",
32+
nil, []metrics.ConstrainedLabel{MapLabel}, nil,
33+
))
34+
MapErrorsDelete = metrics.MustNewCustomGauge(metrics.NewOpts(
35+
consts.MetricsNamespace, "", "map_errors_delete_total",
36+
"The number of failed deletes per map.",
3237
nil, []metrics.ConstrainedLabel{MapLabel}, nil,
3338
))
3439
)

pkg/observer/observer_stats.go

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ func NewBPFCollector() metrics.CollectorWithInit {
2222
metrics.CustomMetrics{
2323
mapmetrics.MapSize,
2424
mapmetrics.MapCapacity,
25-
mapmetrics.MapErrors,
25+
mapmetrics.MapErrorsUpdate,
26+
mapmetrics.MapErrorsDelete,
2627
},
2728
collect,
2829
collectForDocs,
@@ -72,51 +73,41 @@ func collect(ch chan<- prometheus.Metric) {
7273
}
7374
defer mapLink.Close()
7475

75-
updateMapSize(ch, mapLinkStats, name)
7676
ch <- mapmetrics.MapCapacity.MustMetric(
7777
float64(mapLink.MaxEntries()),
7878
name,
7979
)
80-
updateMapErrors(ch, mapLinkStats, name)
80+
update(mapLinkStats, 0, func(sum float64) {
81+
ch <- mapmetrics.MapSize.MustMetric(sum, name)
82+
})
83+
update(mapLinkStats, 1, func(sum float64) {
84+
ch <- mapmetrics.MapErrorsUpdate.MustMetric(sum, name)
85+
})
86+
update(mapLinkStats, 2, func(sum float64) {
87+
ch <- mapmetrics.MapErrorsDelete.MustMetric(sum, name)
88+
})
8189
}
8290
}
8391

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

90-
sum := int64(0)
91-
for _, n := range values {
92-
sum += n
93-
}
94-
ch <- mapmetrics.MapSize.MustMetric(
95-
float64(sum),
96-
name,
97-
)
98-
}
99-
100-
func updateMapErrors(ch chan<- prometheus.Metric, mapLinkStats *ebpf.Map, name string) {
101-
var values []int64
102-
if err := mapLinkStats.Lookup(int32(1), &values); err != nil {
95+
if err := mapLinkStats.Lookup(key, &values); err != nil {
10396
return
10497
}
10598

10699
sum := int64(0)
107100
for _, n := range values {
108101
sum += n
109102
}
110-
ch <- mapmetrics.MapErrors.MustMetric(
111-
float64(sum),
112-
name,
113-
)
103+
update(float64(sum))
114104
}
115105

116106
func collectForDocs(ch chan<- prometheus.Metric) {
117107
for _, m := range mapmetrics.MapLabel.Values {
118108
ch <- mapmetrics.MapSize.MustMetric(0, m)
119109
ch <- mapmetrics.MapCapacity.MustMetric(0, m)
120-
ch <- mapmetrics.MapErrors.MustMetric(0, m)
110+
ch <- mapmetrics.MapErrorsUpdate.MustMetric(0, m)
111+
ch <- mapmetrics.MapErrorsDelete.MustMetric(0, m)
121112
}
122113
}

0 commit comments

Comments
 (0)