Skip to content

Commit

Permalink
Rework Go custom labels offsets handling (open-telemetry#12)
Browse files Browse the repository at this point in the history
Rather than require a match on the exact version, we should just match
on major+minor, and fall back to the latest version if we don't find a result.
  • Loading branch information
umanwizard authored Sep 26, 2024
1 parent 0220589 commit 8014571
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1,279 deletions.
29 changes: 27 additions & 2 deletions interpreter/golang/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package golang
import (
"errors"
"fmt"
"regexp"
"unsafe"

log "github.com/sirupsen/logrus"
Expand All @@ -16,6 +17,8 @@ import (
// #include "../../support/ebpf/types.h"
import "C"

var goMajorMinorRegex = regexp.MustCompile(`^go\d+\.\d+`)

type data struct {
goVersion string
offsets C.GoCustomLabelsOffsets
Expand All @@ -37,6 +40,13 @@ func (d data) Detach(ebpf interpreter.EbpfHandler, pid libpf.PID) error {
}

func Loader(_ interpreter.EbpfHandler, info *interpreter.LoaderInfo) (interpreter.Data, error) {
// Note: So far we have observed that offsets are always the same for any
// go1.mm.yy with fixed mm and any value of yy. That is; the major and minor
// version determine the offsets, while the patch version has no effect.
//
// If this should change in some future Go patch release, we'll need to change
// this function.

file, err := info.GetELF()
if err != nil {
return nil, err
Expand All @@ -50,10 +60,25 @@ func Loader(_ interpreter.EbpfHandler, info *interpreter.LoaderInfo) (interprete
return nil, err
}
log.Debugf("file %s detected as go version %s", info.FileName(), goVersion)
majorMinor := goMajorMinorRegex.FindString(goVersion)
if majorMinor == "" {
return nil, fmt.Errorf("failed to parse go version %s into goM.mm", goVersion)
}

offsets, ok := allOffsets[goVersion]
offsets, ok := allOffsets[majorMinor]
if !ok {
return nil, fmt.Errorf("no offsets found for go version %s", goVersion)
// Info instead of warn: this is often going to be fine,
// as the offsets tend not to change every release cycle.
//
// TODO: Reword the message if we upstream this,
// since it mentions `parca-agent` by name.
log.Infof("version %s unknown; using offsets for latest known Go version %s."+
"If Go traceID integration and other custom labels support is buggy,"+
" try upgrading parca-agent to the latest version.", goVersion, defaultVersion)
return data{
goVersion: goVersion,
offsets: allOffsets[defaultVersion],
}, nil
}

return data{
Expand Down
Loading

0 comments on commit 8014571

Please sign in to comment.