Skip to content

Commit

Permalink
Use updated context propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
RonFed committed Aug 7, 2023
1 parent 0164f3d commit 21be897
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 33 deletions.
31 changes: 18 additions & 13 deletions pkg/instrumentors/bpf/database/sql/bpf/probe.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct {
__type(key, void*);
__type(value, struct sql_request_t);
__uint(max_entries, MAX_CONCURRENT);
} context_to_sql_events SEC(".maps");
} sql_events SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
Expand Down Expand Up @@ -50,11 +50,11 @@ int uprobe_queryDC(struct pt_regs *ctx) {
bpf_probe_read(sql_request.query, query_size, query_str_ptr);
}

// Get goroutine as the key fro the SQL request context
void *goroutine = get_goroutine_address(ctx, context_ptr_pos);

// Get parent if exists
struct span_context *span_ctx = bpf_map_lookup_elem(&spans_in_progress, &goroutine);
void *context_ptr = get_argument(ctx, context_ptr_pos);
void *context_ptr_val = 0;
bpf_probe_read(&context_ptr_val, sizeof(context_ptr_val), context_ptr);
struct span_context *span_ctx = get_parent_span_context(context_ptr_val);
if (span_ctx != NULL) {
// Set the parent context
bpf_probe_read(&sql_request.psc, sizeof(sql_request.psc), span_ctx);
Expand All @@ -64,9 +64,11 @@ int uprobe_queryDC(struct pt_regs *ctx) {
sql_request.sc = generate_span_context();
}

bpf_map_update_elem(&context_to_sql_events, &goroutine, &sql_request, 0);
// TODO : is this realy necessery if this is a leaf
bpf_map_update_elem(&spans_in_progress, &goroutine, &sql_request.sc, 0);
// Get key
void *key = get_consistent_key(ctx, context_ptr);

bpf_map_update_elem(&sql_events, &key, &sql_request, 0);
start_tracking_span(context_ptr_val, &sql_request.sc);
return 0;
}

Expand All @@ -75,16 +77,19 @@ int uprobe_queryDC(struct pt_regs *ctx) {
SEC("uprobe/queryDC")
int uprobe_queryDC_Returns(struct pt_regs *ctx) {
u64 context_ptr_pos = 3;
void *goroutine = get_goroutine_address(ctx, context_ptr_pos);
void *sqlReq_ptr = bpf_map_lookup_elem(&context_to_sql_events, &goroutine);
// Find the corresponding sql event we return from
void *context_ptr = get_argument(ctx, context_ptr_pos);
void *key = get_consistent_key(ctx, context_ptr);
void *sqlReq_ptr = bpf_map_lookup_elem(&sql_events, &key);

struct sql_request_t sqlReq = {0};
bpf_probe_read(&sqlReq, sizeof(sqlReq), sqlReq_ptr);
sqlReq.end_time = bpf_ktime_get_ns();

// Send event
bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU, &sqlReq, sizeof(sqlReq));

bpf_map_delete_elem(&context_to_sql_events, &goroutine);
bpf_map_delete_elem(&spans_in_progress, &goroutine);
// Clean the sql event
bpf_map_delete_elem(&sql_events, &key);
stop_tracking_span(&sqlReq.sc);
return 0;
}
23 changes: 13 additions & 10 deletions pkg/instrumentors/bpf/database/sql/bpf_bpfel_arm64.go

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

23 changes: 13 additions & 10 deletions pkg/instrumentors/bpf/database/sql/bpf_bpfel_x86.go

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

0 comments on commit 21be897

Please sign in to comment.