Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new CallContext APIs #17

Merged
merged 3 commits into from
Jul 30, 2024
Merged

feat: new CallContext APIs #17

merged 3 commits into from
Jul 30, 2024

Conversation

y1yang0
Copy link
Member

@y1yang0 y1yang0 commented Jul 29, 2024

Currently, if we want to change the parameters or return values of the original function, we are using a very error-prone and meticulously written code:

*(call.Params[0].(*string)) = "olleH%s\n"
(*(call.Params[1].(*[]any)))[0] = "goodcatch"
}

This troubles rule authors and is highly prone to errors. We should consider providing APIs in the CallContext to allow rule authors to easily modify parameters or return values without needing to understand the "pointer to a pointer is the original value" magic. For example:

call.SetParam(0, "olleH%s\n")
call.SetParam(1, "goodcatch")
call.SetReturnVal(0, 1024)

This patch significantly changes the form of the hook code; specifically, CallContext is no longer a struct but an interface. The reason for this change is that we might be instrumenting different methods within the same package, and we need to generate the get/setParam functions at compile time. The parameter types of different methods are different, so we need to dynamically generate different struct implementations for different methods.

related to #4

@y1yang0 y1yang0 force-pushed the yyang/callcontext_api branch from 29aa830 to c64cb0e Compare July 29, 2024 08:47
@y1yang0 y1yang0 merged commit 44a837d into main Jul 30, 2024
5 checks passed
y1yang0 added a commit that referenced this pull request Jul 30, 2024
* feat: new CallContext APIs

* fix TestGoMongo111

* consolidate dst node replication
y1yang0 added a commit that referenced this pull request Jul 30, 2024
* feat: new CallContext APIs

* fix TestGoMongo111

* consolidate dst node replication
y1yang0 added a commit that referenced this pull request Jul 30, 2024
* feat: new CallContext APIs

* fix TestGoMongo111

* consolidate dst node replication
123liuziming added a commit that referenced this pull request Aug 9, 2024
* Test/ut (#21)

add more tests!

* chore: move rp.writeTrampoline into proper file (#18)

* fix: otel_setup_inst.go executes after RawFunc causing HookFunc to be nil resulting in panic (#22)

* docs: update how-it-works.md

* ci: add test for dynamic CallContext APIs generation (#17)

* docs: update README.md (#18)

* refine: simplify insertAtBody (#18)

* refine: check GO111MODULE env

* feat: support mysql and refactor test framework (#29)

* feat: support mysql and refactor test framework

* feat: fix test

* feat: fix test

* test: add test for database/sql

* test: skip nil test

* fix: SetParam panics if argument is nil (#31)

* feat: support redisv9 (#30)

* feat: support redisv9

* feat: add test for redis

* feat: fix muzzle

* Update integration_test.go

* feat/nethttp (#26)

* add test for instrumenter package

* add test in cicd

* add test in cicd

* fix test

* improve test coverage

* add more test

* feat: nethttp and gls

* fix mongo test

* fix http_attrs_extractor_test.go

* fix compile error

* add test for net http

* fix test

* add example

* go mod tidy

---------

Co-authored-by: Yi Yang <[email protected]>
@y1yang0 y1yang0 deleted the yyang/callcontext_api branch October 16, 2024 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants