Skip to content

Commit

Permalink
api/ops: Remove MsgOp* constants
Browse files Browse the repository at this point in the history
MsgOp* constants were duplicating MSG_OP_*. There is no point in maintaining
two lists, and MsgOp* constants weren't added for some new features. Let's keep
MSG_OP_* for consistency with other types and bpf.

Also remove MsgOpKfreeSkb (not used and not existing in bpf) and update metrics
docs with missing opcodes.

Signed-off-by: Anna Kapuscinska <[email protected]>
  • Loading branch information
lambdanis authored and jrfastab committed Aug 16, 2024
1 parent ddbac43 commit 4fb2c0b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 46 deletions.
8 changes: 4 additions & 4 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.

58 changes: 21 additions & 37 deletions pkg/api/ops/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (
"github.com/cilium/tetragon/pkg/logger"
)

type OpCode int

// OpCodes must be in sync with msg_ops enum in bpf/lib/msg_types.h
// and should have a human-readable representation in OpCodeStrings.
const (
MSG_OP_UNDEF = 0
// MSG_OP_EXECVE event indicates a process was created. The 'PID'
Expand All @@ -26,14 +30,10 @@ const (
MSG_OP_GENERIC_LSM = 16

// MSG_OP_CLONE notifies user-space that a clone() event has occurred.
MSG_OP_CLONE = 23

MSG_OP_DATA = 24

MSG_OP_CGROUP = 25

MSG_OP_LOADER = 26

MSG_OP_CLONE = 23
MSG_OP_DATA = 24
MSG_OP_CGROUP = 25
MSG_OP_LOADER = 26
MSG_OP_THROTTLE = 27

// just for testing
Expand Down Expand Up @@ -65,36 +65,20 @@ const (
_CGROUP_STATE_MAX CgroupState = 4
)

type OpCode int

const (
MsgOpUndef = iota
MsgOpExecve = 5
MsgOpExit = 7
MsgOpKfreeSkb = 11
MsgOpGenericKprobe = 13
MsgOpGeneric_Tracepoint = 14
MsgOpGenericUprobe = 15
MsgOpClone = 23
MsgOpData = 24
MsgOpCgroup = 25
MsgOpLoader = 26
MsgOpTest = 254
)

var OpCodeStrings = map[OpCode]string{
MsgOpUndef: "Undef",
MsgOpExecve: "Execve",
MsgOpExit: "Exit",
MsgOpKfreeSkb: "KfreeSkb",
MsgOpGenericKprobe: "GenericKprobe",
MsgOpGeneric_Tracepoint: "GenericTracepoint",
MsgOpGenericUprobe: "GenericUprobe",
MsgOpClone: "Clone",
MsgOpData: "Data",
MsgOpCgroup: "Cgroup",
MsgOpLoader: "Loader",
MsgOpTest: "Test",
MSG_OP_UNDEF: "Undef",
MSG_OP_EXECVE: "Execve",
MSG_OP_EXIT: "Exit",
MSG_OP_GENERIC_KPROBE: "GenericKprobe",
MSG_OP_GENERIC_TRACEPOINT: "GenericTracepoint",
MSG_OP_GENERIC_UPROBE: "GenericUprobe",
MSG_OP_GENERIC_LSM: "GenericLSM",
MSG_OP_CLONE: "Clone",
MSG_OP_DATA: "Data",
MSG_OP_CGROUP: "Cgroup",
MSG_OP_LOADER: "Loader",
MSG_OP_THROTTLE: "Throttle",
MSG_OP_TEST: "Test",
}

func (op OpCode) String() string {
Expand Down
6 changes: 3 additions & 3 deletions pkg/metrics/errormetrics/errormetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ func InitMetrics() {
GetErrorTotal(er).Add(0)
}
for opcode := range ops.OpCodeStrings {
if opcode != ops.MsgOpUndef && opcode != ops.MsgOpTest {
if opcode != ops.MSG_OP_UNDEF && opcode != ops.MSG_OP_TEST {
GetHandlerErrors(opcode, HandlePerfHandlerError).Add(0)
}
}
// NB: We initialize only ops.MsgOpUndef here, but unknown_opcode can occur for any opcode
// NB: We initialize only ops.MSG_OP_UNDEF here, but unknown_opcode can occur for any opcode
// that is not explicitly handled.
GetHandlerErrors(ops.MsgOpUndef, HandlePerfUnknownOp).Add(0)
GetHandlerErrors(ops.MSG_OP_UNDEF, HandlePerfUnknownOp).Add(0)
}

// Get a new handle on an ErrorTotal metric for an ErrorType
Expand Down
2 changes: 1 addition & 1 deletion pkg/metrics/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func getOpcodes() []string {
result := make([]string, len(ops.OpCodeStrings)-2)
i := 0
for opcode := range ops.OpCodeStrings {
if opcode != ops.MsgOpUndef && opcode != ops.MsgOpTest {
if opcode != ops.MSG_OP_UNDEF && opcode != ops.MSG_OP_TEST {
result[i] = fmt.Sprint(int32(opcode))
i++
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/metrics/opcodemetrics/opcodemetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func RegisterMetrics(group metrics.Group) {
func InitMetrics() {
// Initialize all metrics
for opcode := range ops.OpCodeStrings {
if opcode != ops.MsgOpUndef && opcode != ops.MsgOpTest {
if opcode != ops.MSG_OP_UNDEF && opcode != ops.MSG_OP_TEST {
GetOpTotal(opcode).Add(0)
LatencyStats.WithLabelValues(fmt.Sprint(int32(opcode)))
}
Expand Down

0 comments on commit 4fb2c0b

Please sign in to comment.