Skip to content

Commit 5266845

Browse files
authored
bpf: make event naming consistent, fix typos (#733)
Signed-off-by: Mattia Meleleo <[email protected]>
1 parent 33fea61 commit 5266845

File tree

9 files changed

+26
-28
lines changed

9 files changed

+26
-28
lines changed

bpf/common/common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#include <common/common.h>
1818

1919
// Force emitting struct http_request_trace into the ELF for automatic creation of Golang struct
20-
const http_request_trace *unused_4 __attribute__((unused));
21-
const sql_request_trace *unused_3 __attribute__((unused));
20+
const http_request_trace_t *unused_4 __attribute__((unused));
21+
const sql_request_trace_t *unused_3 __attribute__((unused));
2222
const tcp_req_t *unused_5 __attribute__((unused));
2323
const kafka_client_req_t *unused_6 __attribute__((unused));
2424
const redis_client_req_t *unused_7 __attribute__((unused));

bpf/common/common.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ enum large_buf_action : u8 {
5252

5353
// Trace of an HTTP call invocation. It is instantiated by the return uprobe and forwarded to the
5454
// user space through the events ringbuffer.
55-
// TODO(matt): fix naming
56-
typedef struct http_request_trace_t {
55+
typedef struct http_request_trace {
5756
u8 type; // Must be first
5857
u8 _pad0[1];
5958
u16 status;
@@ -70,10 +69,9 @@ typedef struct http_request_trace_t {
7069
tp_info_t tp;
7170
connection_info_t conn;
7271
pid_info pid;
73-
} http_request_trace;
72+
} http_request_trace_t;
7473

75-
// TODO(matt): fix naming
76-
typedef struct sql_request_trace_t {
74+
typedef struct sql_request_trace {
7775
u8 type; // Must be first
7876
u8 _pad[1];
7977
u16 status;
@@ -83,7 +81,7 @@ typedef struct sql_request_trace_t {
8381
tp_info_t tp;
8482
connection_info_t conn;
8583
unsigned char sql[SQL_MAX_LEN];
86-
} sql_request_trace;
84+
} sql_request_trace_t;
8785

8886
typedef struct kafka_client_req {
8987
u8 type; // Must be first
@@ -194,18 +192,18 @@ typedef struct go_otel_key_value {
194192

195193
#define OTEL_ATTRIBUTE_KEY_MAX_LEN (32)
196194
#define OTEL_ATTRIBUTE_VALUE_MAX_LEN (128)
197-
#define OTEL_ATTRUBUTE_MAX_COUNT (16)
195+
#define OTEL_ATTRIBUTE_MAX_COUNT (16)
198196

199-
typedef struct otel_attirbute {
197+
typedef struct otel_attribute {
200198
u16 val_length;
201199
u8 vtype;
202200
u8 reserved;
203201
unsigned char key[OTEL_ATTRIBUTE_KEY_MAX_LEN];
204202
unsigned char value[OTEL_ATTRIBUTE_VALUE_MAX_LEN];
205-
} otel_attirbute_t;
203+
} otel_attribute_t;
206204

207205
typedef struct otel_attributes {
208-
otel_attirbute_t attrs[OTEL_ATTRUBUTE_MAX_COUNT];
206+
otel_attribute_t attrs[OTEL_ATTRIBUTE_MAX_COUNT];
209207
u8 valid_attrs;
210208
u8 _apad;
211209
} otel_attributes_t;

bpf/common/http_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ typedef struct http2_grpc_request {
103103
tp_info_t tp;
104104
} http2_grpc_request_t;
105105

106-
// Force emitting struct http_request_trace into the ELF for automatic creation of Golang struct
106+
// Force emitting struct http_info_t and http2_grpc_request_t into the ELF for automatic creation of Golang struct
107107
const http_info_t *unused __attribute__((unused));
108108
const http2_grpc_request_t *unused_http2 __attribute__((unused));
109109

bpf/gotracer/go_grpc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ int obi_uprobe_server_handleStream_return(struct pt_regs *ctx) {
258258
st_ptr,
259259
grpc_stream_method_ptr_pos);
260260

261-
http_request_trace *trace = bpf_ringbuf_reserve(&events, sizeof(http_request_trace), 0);
261+
http_request_trace_t *trace = bpf_ringbuf_reserve(&events, sizeof(http_request_trace_t), 0);
262262
if (!trace) {
263263
bpf_dbg_printk("can't reserve space in the ringbuffer");
264264
goto done;
@@ -439,7 +439,7 @@ static __always_inline int grpc_connect_done(struct pt_regs *ctx, void *err) {
439439
goto done;
440440
}
441441

442-
http_request_trace *trace = bpf_ringbuf_reserve(&events, sizeof(http_request_trace), 0);
442+
http_request_trace_t *trace = bpf_ringbuf_reserve(&events, sizeof(http_request_trace_t), 0);
443443
if (!trace) {
444444
bpf_dbg_printk("can't reserve space in the ringbuffer");
445445
goto done;

bpf/gotracer/go_nethttp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ static __always_inline int serve_http_returns(struct pt_regs *ctx) {
377377
make_tp_string(tp_buf, &invocation->tp);
378378
bpf_dbg_printk("tp: %s", tp_buf);
379379

380-
http_request_trace *trace = bpf_ringbuf_reserve(&events, sizeof(http_request_trace), 0);
380+
http_request_trace_t *trace = bpf_ringbuf_reserve(&events, sizeof(http_request_trace_t), 0);
381381
if (!trace) {
382382
bpf_dbg_printk("can't reserve space in the ringbuffer");
383383
goto done;
@@ -571,7 +571,7 @@ int obi_uprobe_roundTripReturn(struct pt_regs *ctx) {
571571
goto done;
572572
}
573573

574-
http_request_trace *trace = bpf_ringbuf_reserve(&events, sizeof(http_request_trace), 0);
574+
http_request_trace_t *trace = bpf_ringbuf_reserve(&events, sizeof(http_request_trace_t), 0);
575575
if (!trace) {
576576
bpf_dbg_printk("can't reserve space in the ringbuffer");
577577
goto done;

bpf/gotracer/go_sdk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ int obi_uprobe_RecordError(struct pt_regs *ctx) {
427427
"valid_attrs %d, len %d, go_str %s", valid_attrs, go_str.len, go_str.str);
428428

429429
if ((go_str.len < OTEL_ATTRIBUTE_KEY_MAX_LEN) &&
430-
(valid_attrs < OTEL_ATTRUBUTE_MAX_COUNT)) {
430+
(valid_attrs < OTEL_ATTRIBUTE_MAX_COUNT)) {
431431
__builtin_memcpy(
432432
span->span_attrs.attrs[valid_attrs].key, ERROR_KEY, ERROR_KEY_SIZE);
433433
bpf_probe_read_user(span->span_attrs.attrs[valid_attrs].value,
@@ -441,4 +441,4 @@ int obi_uprobe_RecordError(struct pt_regs *ctx) {
441441
}
442442

443443
return 0;
444-
}
444+
}

bpf/gotracer/go_sql.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ int obi_uprobe_queryReturn(struct pt_regs *ctx) {
8484
}
8585
bpf_map_delete_elem(&ongoing_sql_queries, &g_key);
8686

87-
sql_request_trace *trace = bpf_ringbuf_reserve(&events, sizeof(sql_request_trace), 0);
87+
sql_request_trace_t *trace = bpf_ringbuf_reserve(&events, sizeof(sql_request_trace_t), 0);
8888
if (trace) {
8989
task_pid(&trace->pid);
9090
trace->type = EVENT_SQL_CLIENT;

bpf/gotracer/types/otel_types.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ volatile const u64 attr_type_int64slice;
2626
volatile const u64 attr_type_float64slice;
2727
volatile const u64 attr_type_stringslice;
2828

29-
static __always_inline bool set_attr_value(otel_attirbute_t *attr,
29+
static __always_inline bool set_attr_value(otel_attribute_t *attr,
3030
go_otel_attr_value_t *go_attr_value) {
3131
u64 vtype = go_attr_value->vtype;
3232

@@ -67,11 +67,11 @@ convert_go_otel_attributes(void *attrs_buf, u64 slice_len, otel_attributes_t *en
6767
go_otel_attr_value_t go_attr_value = {0};
6868
struct go_string go_str = {0};
6969
u8 valid_attrs = enc_attrs->valid_attrs;
70-
if (valid_attrs >= OTEL_ATTRUBUTE_MAX_COUNT) {
70+
if (valid_attrs >= OTEL_ATTRIBUTE_MAX_COUNT) {
7171
return;
7272
}
7373

74-
for (u8 go_attr_index = 0; go_attr_index < OTEL_ATTRUBUTE_MAX_COUNT; go_attr_index++) {
74+
for (u8 go_attr_index = 0; go_attr_index < OTEL_ATTRIBUTE_MAX_COUNT; go_attr_index++) {
7575
if (go_attr_index >= slice_len) {
7676
break;
7777
}
@@ -94,7 +94,7 @@ convert_go_otel_attributes(void *attrs_buf, u64 slice_len, otel_attributes_t *en
9494
// Need to check valid_attrs otherwise the ebpf verifier thinks it's possible to exceed
9595
// the max register value for a downstream call, even though it's not possible with
9696
// this same check at the end of the loop.
97-
if (valid_attrs >= OTEL_ATTRUBUTE_MAX_COUNT) {
97+
if (valid_attrs >= OTEL_ATTRIBUTE_MAX_COUNT) {
9898
break;
9999
}
100100

@@ -108,7 +108,7 @@ convert_go_otel_attributes(void *attrs_buf, u64 slice_len, otel_attributes_t *en
108108

109109
enc_attrs->attrs[valid_attrs].vtype = go_attr_value.vtype;
110110
valid_attrs++;
111-
if (valid_attrs >= OTEL_ATTRUBUTE_MAX_COUNT) {
111+
if (valid_attrs >= OTEL_ATTRIBUTE_MAX_COUNT) {
112112
// No more space for attributes
113113
break;
114114
}

pkg/components/ebpf/common/common.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ import (
2929
"go.opentelemetry.io/obi/pkg/config"
3030
)
3131

32-
//go:generate $BPF2GO -cc $BPF_CLANG -cflags $BPF_CFLAGS -target amd64,arm64 -type http_request_trace -type sql_request_trace -type http_info_t -type connection_info_t -type http2_grpc_request_t -type tcp_req_t -type kafka_client_req_t -type kafka_go_req_t -type redis_client_req_t -type tcp_large_buffer_t -type otel_span_t -type mongo_go_client_req_t Bpf ../../../../bpf/common/common.c -- -I../../../../bpf
32+
//go:generate $BPF2GO -cc $BPF_CLANG -cflags $BPF_CFLAGS -target amd64,arm64 -type http_request_trace_t -type sql_request_trace_t -type http_info_t -type connection_info_t -type http2_grpc_request_t -type tcp_req_t -type kafka_client_req_t -type kafka_go_req_t -type redis_client_req_t -type tcp_large_buffer_t -type otel_span_t -type mongo_go_client_req_t Bpf ../../../../bpf/common/common.c -- -I../../../../bpf
3333

3434
// HTTPRequestTrace contains information from an HTTP request as directly received from the
3535
// eBPF layer. This contains low-level C structures for accurate binary read from ring buffer.
3636
type (
37-
HTTPRequestTrace BpfHttpRequestTrace
38-
SQLRequestTrace BpfSqlRequestTrace
37+
HTTPRequestTrace BpfHttpRequestTraceT
38+
SQLRequestTrace BpfSqlRequestTraceT
3939
BPFHTTPInfo BpfHttpInfoT
4040
BPFConnInfo BpfConnectionInfoT
4141
TCPRequestInfo BpfTcpReqT

0 commit comments

Comments
 (0)