Skip to content

Commit

Permalink
only use one http function in http server instr
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieDanielson committed Apr 19, 2023
1 parent b2d441b commit c1bc4d0
Showing 1 changed file with 19 additions and 31 deletions.
50 changes: 19 additions & 31 deletions pkg/instrumentors/bpf/net/http/server/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type HttpEvent struct {

type httpServerInstrumentor struct {
bpfObjects *bpfObjects
uprobes []link.Link
uprobe link.Link
returnProbs []link.Link
eventsReader *perf.Reader
}
Expand All @@ -61,7 +61,7 @@ func (h *httpServerInstrumentor) LibraryName() string {
}

func (h *httpServerInstrumentor) FuncNames() []string {
return []string{"net/http.(*ServeMux).ServeHTTP", "net/http.HandlerFunc.ServeHTTP"}
return []string{"net/http.HandlerFunc.ServeHTTP"}
}

func (h *httpServerInstrumentor) Load(ctx *context.InstrumentorContext) error {
Expand Down Expand Up @@ -97,53 +97,41 @@ func (h *httpServerInstrumentor) Load(ctx *context.InstrumentorContext) error {
return err
}

for _, funcName := range h.FuncNames() {
h.registerProbes(ctx, funcName)
}
offset, err := ctx.TargetDetails.GetFunctionOffset(h.FuncNames()[0])

rd, err := perf.NewReader(h.bpfObjects.Events, os.Getpagesize())
if err != nil {
return err
}
h.eventsReader = rd

return nil
}

func (h *httpServerInstrumentor) registerProbes(ctx *context.InstrumentorContext, funcName string) {
logger := log.Logger.WithName("net/http-instrumentor").WithValues("function", funcName)
offset, err := ctx.TargetDetails.GetFunctionOffset(funcName)
if err != nil {
logger.Error(err, "could not find function start offset. Skipping")
return
}
retOffsets, err := ctx.TargetDetails.GetFunctionReturns(funcName)
if err != nil {
logger.Error(err, "could not find function end offsets. Skipping")
return
}

up, err := ctx.Executable.Uprobe("", h.bpfObjects.UprobeServerMuxServeHTTP, &link.UprobeOptions{
Address: offset,
})
if err != nil {
logger.V(1).Info("could not insert start uprobe. Skipping",
"error", err.Error())
return
return err
}

h.uprobes = append(h.uprobes, up)
h.uprobe = up
retOffsets, err := ctx.TargetDetails.GetFunctionReturns(h.FuncNames()[0])
if err != nil {
return err
}

for _, ret := range retOffsets {
retProbe, err := ctx.Executable.Uprobe("", h.bpfObjects.UprobeServerMuxServeHTTP_Returns, &link.UprobeOptions{
Address: ret,
})
if err != nil {
logger.Error(err, "could not insert return uprobe. Skipping")
return
return err
}
h.returnProbs = append(h.returnProbs, retProbe)
}

rd, err := perf.NewReader(h.bpfObjects.Events, os.Getpagesize())
if err != nil {
return err
}
h.eventsReader = rd
return nil
}

func (h *httpServerInstrumentor) Run(eventsChan chan<- *events.Event) {
Expand Down Expand Up @@ -203,8 +191,8 @@ func (h *httpServerInstrumentor) Close() {
h.eventsReader.Close()
}

for _, r := range h.uprobes {
r.Close()
if h.uprobe != nil {
h.uprobe.Close()
}

for _, r := range h.returnProbs {
Expand Down

0 comments on commit c1bc4d0

Please sign in to comment.