Skip to content

Commit

Permalink
fix offset address ref in probe
Browse files Browse the repository at this point in the history
  • Loading branch information
vreynolds committed Apr 18, 2023
1 parent 527036e commit 092168e
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions pkg/instrumentors/bpf/net/http/client/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@ type HttpEvent struct {
ParentSpanContext context.EbpfSpanContext
}

type httpServerInstrumentor struct {
type httpClientInstrumentor struct {
bpfObjects *bpfObjects
uprobe link.Link
returnProbs []link.Link
eventsReader *perf.Reader
}

func New() *httpServerInstrumentor {
return &httpServerInstrumentor{}
func New() *httpClientInstrumentor {
return &httpClientInstrumentor{}
}

func (h *httpServerInstrumentor) LibraryName() string {
func (h *httpClientInstrumentor) LibraryName() string {
return "net/http/client"
}

func (h *httpServerInstrumentor) FuncNames() []string {
func (h *httpClientInstrumentor) FuncNames() []string {
return []string{"net/http.(*Client).do"}
}

func (h *httpServerInstrumentor) Load(ctx *context.InstrumentorContext) error {
func (h *httpClientInstrumentor) Load(ctx *context.InstrumentorContext) error {
spec, err := ctx.Injector.Inject(loadBpf, "go", ctx.TargetDetails.GoVersion.Original(), []*inject.InjectStructField{
{
VarName: "method_ptr_pos",
Expand Down Expand Up @@ -100,7 +100,7 @@ func (h *httpServerInstrumentor) Load(ctx *context.InstrumentorContext) error {
offset, err := ctx.TargetDetails.GetFunctionOffset(h.FuncNames()[0])

up, err := ctx.Executable.Uprobe("", h.bpfObjects.UprobeHttpClientDo, &link.UprobeOptions{
Offset: offset,
Address: offset,
})
if err != nil {
return err
Expand All @@ -116,7 +116,7 @@ func (h *httpServerInstrumentor) Load(ctx *context.InstrumentorContext) error {

for _, ret := range retOffsets {
retProbe, err := ctx.Executable.Uprobe("", h.bpfObjects.UprobeHttpClientDoReturns, &link.UprobeOptions{
Offset: ret,
Address: ret,
})
if err != nil {
return err
Expand All @@ -130,10 +130,11 @@ func (h *httpServerInstrumentor) Load(ctx *context.InstrumentorContext) error {
}
h.eventsReader = rd

fmt.Println("HO HO HO probe loaded")
return nil
}

func (h *httpServerInstrumentor) Run(eventsChan chan<- *events.Event) {
func (h *httpClientInstrumentor) Run(eventsChan chan<- *events.Event) {
logger := log.Logger.WithName("net/http/client-instrumentor")
var event HttpEvent
for {
Expand All @@ -160,7 +161,7 @@ func (h *httpServerInstrumentor) Run(eventsChan chan<- *events.Event) {
}
}

func (h *httpServerInstrumentor) convertEvent(e *HttpEvent) *events.Event {
func (h *httpClientInstrumentor) convertEvent(e *HttpEvent) *events.Event {
method := unix.ByteSliceToString(e.Method[:])
path := unix.ByteSliceToString(e.Path[:])

Expand Down Expand Up @@ -198,7 +199,7 @@ func (h *httpServerInstrumentor) convertEvent(e *HttpEvent) *events.Event {
}
}

func (h *httpServerInstrumentor) Close() {
func (h *httpClientInstrumentor) Close() {
log.Logger.V(0).Info("closing net/http/client instrumentor")
if h.eventsReader != nil {
h.eventsReader.Close()
Expand Down

0 comments on commit 092168e

Please sign in to comment.