Skip to content

Commit

Permalink
metrics: Expose more errors in tetragon_bpf_missed_events_total counter
Browse files Browse the repository at this point in the history
When testing I saw a bunch of "unknown" errors. To further investigate, let's
split out ENOENT, E2BIG and EINVAL into separate label values. This should be
almost all errors returned by perf_event_output, I left out only EOPNOTSUPP.

Signed-off-by: Anna Kapuscinska <anna@isovalent.com>
  • Loading branch information
lambdanis committed Sep 2, 2024
1 parent b7ef6aa commit 4166a3f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
17 changes: 13 additions & 4 deletions bpf/lib/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,12 @@ _Static_assert(sizeof(struct execve_map_value) % 8 == 0,
"struct execve_map_value should have size multiple of 8 bytes");

#define SENT_FAILED_UNKNOWN 0 // unknown error
#define SENT_FAILED_EBUSY 1 // EBUSY
#define SENT_FAILED_ENOSPC 2 // ENOSPC
#define SENT_FAILED_MAX 3
#define SENT_FAILED_ENOENT 1 // ENOENT
#define SENT_FAILED_E2BIG 2 // E2BIG
#define SENT_FAILED_EBUSY 3 // EBUSY
#define SENT_FAILED_EINVAL 4 // EINVAL
#define SENT_FAILED_ENOSPC 5 // ENOSPC
#define SENT_FAILED_MAX 6

struct kernel_stats {
__u64 sent_failed[256][SENT_FAILED_MAX];
Expand All @@ -591,8 +594,14 @@ perf_event_output_metric(void *ctx, u8 msg_op, void *map, u64 flags, void *data,
if (err < 0) {
valp = map_lookup_elem(&tg_stats_map, &zero);
if (valp) {
if (err == -16) // EBUSY
if (err == -2) // ENOENT
__sync_fetch_and_add(&valp->sent_failed[msg_op][SENT_FAILED_ENOENT], 1);
else if (err == -7) // E2BIG
__sync_fetch_and_add(&valp->sent_failed[msg_op][SENT_FAILED_E2BIG], 1);
else if (err == -16) // EBUSY
__sync_fetch_and_add(&valp->sent_failed[msg_op][SENT_FAILED_EBUSY], 1);
else if (err == -22) // EINVAL
__sync_fetch_and_add(&valp->sent_failed[msg_op][SENT_FAILED_EINVAL], 1);
else if (err == -28) // ENOSPC
__sync_fetch_and_add(&valp->sent_failed[msg_op][SENT_FAILED_ENOSPC], 1);
else
Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/docs/reference/metrics.md

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

3 changes: 3 additions & 0 deletions pkg/api/processapi/processapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ const (

const (
SentFailedUnknown = iota
SentFailedEnoent
SentFailedE2big
SentFailedEbusy
SentFailedEinval
SentFailedEnospc
SentFailedMax
)
Expand Down
3 changes: 3 additions & 0 deletions pkg/metrics/eventmetrics/eventmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import (
var (
perfEventErrors = map[int]string{
processapi.SentFailedUnknown: "unknown",
processapi.SentFailedEnoent: "ENOENT",
processapi.SentFailedE2big: "E2BIG",
processapi.SentFailedEbusy: "EBUSY",
processapi.SentFailedEinval: "EINVAL",
processapi.SentFailedEnospc: "ENOSPC",
}
perfEventErrorLabel = metrics.ConstrainedLabel{
Expand Down

0 comments on commit 4166a3f

Please sign in to comment.