|
@@ -16,6 +16,8 @@
|
|
|
#define MAX_HEADERS 20
|
|
#define MAX_HEADERS 20
|
|
|
#define MAX_HEADER_STRING 50
|
|
#define MAX_HEADER_STRING 50
|
|
|
|
|
|
|
|
|
|
+#define PROTOCOL_GRPC 15
|
|
|
|
|
+
|
|
|
struct grpc_request_t {
|
|
struct grpc_request_t {
|
|
|
BASE_SPAN_PROPERTIES
|
|
BASE_SPAN_PROPERTIES
|
|
|
char method[MAX_SIZE];
|
|
char method[MAX_SIZE];
|
|
@@ -23,6 +25,7 @@ struct grpc_request_t {
|
|
|
net_addr_t local_addr;
|
|
net_addr_t local_addr;
|
|
|
u8 has_status;
|
|
u8 has_status;
|
|
|
u32 stream_id;
|
|
u32 stream_id;
|
|
|
|
|
+ u64 method_size;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
struct {
|
|
struct {
|
|
@@ -196,7 +199,7 @@ handleStream(struct pt_regs *ctx, void *stream_ptr, struct go_iface *go_context)
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- bpf_printk("start get apm data\n");
|
|
|
|
|
|
|
+ // bpf_printk("start get apm data\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
struct apm_span_context *cw_parent_span_context = bpf_map_lookup_elem(&apm_span_context_heap3, &zero);
|
|
struct apm_span_context *cw_parent_span_context = bpf_map_lookup_elem(&apm_span_context_heap3, &zero);
|
|
@@ -220,23 +223,41 @@ handleStream(struct pt_regs *ctx, void *stream_ptr, struct go_iface *go_context)
|
|
|
|
|
|
|
|
e->fd = k.fd;
|
|
e->fd = k.fd;
|
|
|
e->pid = k.pid;
|
|
e->pid = k.pid;
|
|
|
- e->protocol = PROTOCOL_UNKNOWN;
|
|
|
|
|
e->status = STATUS_UNKNOWN;
|
|
e->status = STATUS_UNKNOWN;
|
|
|
e->method = METHOD_UNKNOWN;
|
|
e->method = METHOD_UNKNOWN;
|
|
|
e->statement_id = 0;
|
|
e->statement_id = 0;
|
|
|
- e->payload_size = 0;
|
|
|
|
|
- e->trace_id = 0;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 拷贝 grpcReq->method 到 payload 并设置 payload_size
|
|
|
|
|
+ // 手动计算字符串长度(在 eBPF 中不能使用 strlen)
|
|
|
|
|
+ u32 method_len = 0;
|
|
|
|
|
+ for (int i = 0; i < MAX_SIZE; i++) {
|
|
|
|
|
+ if (grpcReq->method[i] == '\0') {
|
|
|
|
|
+ method_len = i;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 如果没有找到 '\0',使用最大长度
|
|
|
|
|
+ if (method_len == 0) {
|
|
|
|
|
+ method_len = MAX_SIZE - 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ grpcReq->method_size = method_len;
|
|
|
|
|
+ e->payload_size = method_len;
|
|
|
|
|
+ COPY_PAYLOAD(e->payload, method_len, grpcReq->method);
|
|
|
|
|
+
|
|
|
|
|
+ bpf_printk("grpc:server:handleStream: get the payload size is %d\n", e->payload_size);
|
|
|
|
|
|
|
|
struct apm_trace_info_t trace_info = cw_save_trace_info(id,pid, k.fd);
|
|
struct apm_trace_info_t trace_info = cw_save_trace_info(id,pid, k.fd);
|
|
|
|
|
|
|
|
e->trace_start = 1;
|
|
e->trace_start = 1;
|
|
|
e->trace_end = 0;
|
|
e->trace_end = 0;
|
|
|
|
|
+ e->trace_type = 1;
|
|
|
e->protocol = PROTOCOL_TRACE;
|
|
e->protocol = PROTOCOL_TRACE;
|
|
|
e->trace_id = trace_info.trace_id;
|
|
e->trace_id = trace_info.trace_id;
|
|
|
|
|
|
|
|
|
|
|
|
|
//不发送payload
|
|
//不发送payload
|
|
|
- // bpf_perf_event_output(ctx, &l7_events, BPF_F_CURRENT_CPU, e, sizeof(*e));
|
|
|
|
|
|
|
+ bpf_perf_event_output(ctx, &l7_events, BPF_F_CURRENT_CPU, e, sizeof(*e));
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
@@ -289,7 +310,7 @@ SEC("uprobe/server_handleStream")
|
|
|
int uprobe_server_handleStream(struct pt_regs *ctx) {
|
|
int uprobe_server_handleStream(struct pt_regs *ctx) {
|
|
|
u64 stream_pos = 4;
|
|
u64 stream_pos = 4;
|
|
|
void *stream_ptr = get_argument(ctx, stream_pos);
|
|
void *stream_ptr = get_argument(ctx, stream_pos);
|
|
|
- bpf_printk("enter uprobe_server_handleStream\n");
|
|
|
|
|
|
|
+ // bpf_printk("enter uprobe_server_handleStream\n");
|
|
|
// Get key
|
|
// Get key
|
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
|
__u32 tgid = pid_tgid >> 32;
|
|
__u32 tgid = pid_tgid >> 32;
|
|
@@ -318,7 +339,7 @@ int uprobe_server_handleStream_Returns(struct pt_regs *ctx) {
|
|
|
|
|
|
|
|
pid = id >> 32;
|
|
pid = id >> 32;
|
|
|
tid = (__u32)id;
|
|
tid = (__u32)id;
|
|
|
- bpf_printk("enter uprobe_server_handleStream_Returns\n");
|
|
|
|
|
|
|
+ // bpf_printk("enter uprobe_server_handleStream_Returns\n");
|
|
|
|
|
|
|
|
struct l7_request_key k = {};
|
|
struct l7_request_key k = {};
|
|
|
k.pid = pid;
|
|
k.pid = pid;
|
|
@@ -381,10 +402,13 @@ int uprobe_server_handleStream_Returns(struct pt_regs *ctx) {
|
|
|
// e->connection_timestamp = get_connection_timestamp(k.pid, k.fd);
|
|
// e->connection_timestamp = get_connection_timestamp(k.pid, k.fd);
|
|
|
e->trace_start = 0;
|
|
e->trace_start = 0;
|
|
|
e->trace_end = 1;
|
|
e->trace_end = 1;
|
|
|
|
|
+ e->trace_type = 1;
|
|
|
e->trace_id = trace_id;
|
|
e->trace_id = trace_id;
|
|
|
e->payload_size = 0;
|
|
e->payload_size = 0;
|
|
|
e->event_count = event_count;
|
|
e->event_count = event_count;
|
|
|
- // COPY_PAYLOAD(e->payload, size, payload);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ e->payload_size = event->method_size;
|
|
|
|
|
+ COPY_PAYLOAD(e->payload, event->method_size, event->method);
|
|
|
// bpf_map_delete_elem(&active_l7_requests, &k);
|
|
// bpf_map_delete_elem(&active_l7_requests, &k);
|
|
|
// 清除事件计数
|
|
// 清除事件计数
|
|
|
bpf_map_delete_elem(&trace_event_count_heap, &trace_id);
|
|
bpf_map_delete_elem(&trace_event_count_heap, &trace_id);
|
|
@@ -403,9 +427,9 @@ int uprobe_server_handleStream_Returns(struct pt_regs *ctx) {
|
|
|
// __builtin_memcpy(&e->daddr, &accept_conn->daddr, sizeof(e->daddr));
|
|
// __builtin_memcpy(&e->daddr, &accept_conn->daddr, sizeof(e->daddr));
|
|
|
// }
|
|
// }
|
|
|
//不发送payload
|
|
//不发送payload
|
|
|
- // bpf_perf_event_output(ctx, &l7_events, BPF_F_CURRENT_CPU, e, sizeof(*e));
|
|
|
|
|
|
|
+ bpf_perf_event_output(ctx, &l7_events, BPF_F_CURRENT_CPU, e, sizeof(*e));
|
|
|
|
|
|
|
|
- bpf_printk("stop get apm data\n");
|
|
|
|
|
|
|
+ // bpf_printk("stop get apm data\n");
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -417,7 +441,7 @@ int uprobe_server_handleStream_Returns(struct pt_regs *ctx) {
|
|
|
SEC("uprobe/server_handleStream2")
|
|
SEC("uprobe/server_handleStream2")
|
|
|
int uprobe_server_handleStream2(struct pt_regs *ctx) {
|
|
int uprobe_server_handleStream2(struct pt_regs *ctx) {
|
|
|
u64 server_stream_pos = 4;
|
|
u64 server_stream_pos = 4;
|
|
|
- bpf_printk("enter uprobe_server_handleStream2\n");
|
|
|
|
|
|
|
+ // bpf_printk("enter uprobe_server_handleStream2\n");
|
|
|
void *server_stream_ptr = get_argument(ctx, server_stream_pos);
|
|
void *server_stream_ptr = get_argument(ctx, server_stream_pos);
|
|
|
if (server_stream_ptr == NULL) {
|
|
if (server_stream_ptr == NULL) {
|
|
|
bpf_printk("grpc:server:uprobe/server_handleStream2: failed to get ServerStream arg");
|
|
bpf_printk("grpc:server:uprobe/server_handleStream2: failed to get ServerStream arg");
|
|
@@ -467,7 +491,7 @@ int uprobe_server_handleStream2_Returns(struct pt_regs *ctx) {
|
|
|
|
|
|
|
|
pid = id >> 32;
|
|
pid = id >> 32;
|
|
|
tid = (__u32)id;
|
|
tid = (__u32)id;
|
|
|
- bpf_printk("enter uprobe_server_handleStream2_Returns\n");
|
|
|
|
|
|
|
+ // bpf_printk("enter uprobe_server_handleStream2_Returns\n");
|
|
|
|
|
|
|
|
struct l7_request_key k = {};
|
|
struct l7_request_key k = {};
|
|
|
k.pid = pid;
|
|
k.pid = pid;
|
|
@@ -547,6 +571,7 @@ lookup:
|
|
|
// e->connection_timestamp = get_connection_timestamp(k.pid, k.fd);
|
|
// e->connection_timestamp = get_connection_timestamp(k.pid, k.fd);
|
|
|
e->trace_start = 0;
|
|
e->trace_start = 0;
|
|
|
e->trace_end = 1;
|
|
e->trace_end = 1;
|
|
|
|
|
+ e->trace_type = 1;
|
|
|
e->trace_id = trace_id;
|
|
e->trace_id = trace_id;
|
|
|
e->payload_size = 0;
|
|
e->payload_size = 0;
|
|
|
e->event_count = event_count;
|
|
e->event_count = event_count;
|
|
@@ -583,7 +608,7 @@ int uprobe_http2Server_operateHeader(struct pt_regs *ctx) {
|
|
|
struct go_slice header_fields = {};
|
|
struct go_slice header_fields = {};
|
|
|
bpf_probe_read(&header_fields, sizeof(header_fields), (void *)(frame_ptr + frame_fields_pos));
|
|
bpf_probe_read(&header_fields, sizeof(header_fields), (void *)(frame_ptr + frame_fields_pos));
|
|
|
char key[W3C_KEY_LENGTH] = "traceparent";
|
|
char key[W3C_KEY_LENGTH] = "traceparent";
|
|
|
- bpf_printk("enter the uprobe_http2Server_operateHeader\n");
|
|
|
|
|
|
|
+ // bpf_printk("enter the uprobe_http2Server_operateHeader\n");
|
|
|
|
|
|
|
|
__u32 zero = 0;
|
|
__u32 zero = 0;
|
|
|
struct apm_span_context *cw_parent_span_context = bpf_map_lookup_elem(&apm_span_context_heap3, &zero);
|
|
struct apm_span_context *cw_parent_span_context = bpf_map_lookup_elem(&apm_span_context_heap3, &zero);
|
|
@@ -648,7 +673,7 @@ int uprobe_http2Server_operateHeader(struct pt_regs *ctx) {
|
|
|
// This is only compatible with versions > 1.40 and < 1.69.0 of the Server.
|
|
// This is only compatible with versions > 1.40 and < 1.69.0 of the Server.
|
|
|
SEC("uprobe/http2Server_WriteStatus")
|
|
SEC("uprobe/http2Server_WriteStatus")
|
|
|
int uprobe_http2Server_WriteStatus(struct pt_regs *ctx) {
|
|
int uprobe_http2Server_WriteStatus(struct pt_regs *ctx) {
|
|
|
- bpf_printk("enter uprobe_http2Server_WriteStatus\n");
|
|
|
|
|
|
|
+ // bpf_printk("enter uprobe_http2Server_WriteStatus\n");
|
|
|
void *status_ptr = get_argument(ctx, 3);
|
|
void *status_ptr = get_argument(ctx, 3);
|
|
|
return writeStatus(ctx, status_ptr);
|
|
return writeStatus(ctx, status_ptr);
|
|
|
}
|
|
}
|
|
@@ -659,7 +684,7 @@ int uprobe_http2Server_WriteStatus(struct pt_regs *ctx) {
|
|
|
// This is only compatible with versions > 1.69.0 of the Server.
|
|
// This is only compatible with versions > 1.69.0 of the Server.
|
|
|
SEC("uprobe/http2Server_WriteStatus2")
|
|
SEC("uprobe/http2Server_WriteStatus2")
|
|
|
int uprobe_http2Server_WriteStatus2(struct pt_regs *ctx) {
|
|
int uprobe_http2Server_WriteStatus2(struct pt_regs *ctx) {
|
|
|
- bpf_printk("enter uprobe_http2Server_WriteStatus2\n");
|
|
|
|
|
|
|
+ // bpf_printk("enter uprobe_http2Server_WriteStatus2\n");
|
|
|
u64 server_stream_pos = 2;
|
|
u64 server_stream_pos = 2;
|
|
|
void *server_stream_ptr = get_argument(ctx, server_stream_pos);
|
|
void *server_stream_ptr = get_argument(ctx, server_stream_pos);
|
|
|
if (server_stream_ptr == NULL) {
|
|
if (server_stream_ptr == NULL) {
|