Skip to content

Commit 8014571

Browse files
authored
Rework Go custom labels offsets handling (open-telemetry#12)
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.
1 parent 0220589 commit 8014571

File tree

2 files changed

+44
-1279
lines changed

2 files changed

+44
-1279
lines changed

interpreter/golang/golang.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package golang
33
import (
44
"errors"
55
"fmt"
6+
"regexp"
67
"unsafe"
78

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

20+
var goMajorMinorRegex = regexp.MustCompile(`^go\d+\.\d+`)
21+
1922
type data struct {
2023
goVersion string
2124
offsets C.GoCustomLabelsOffsets
@@ -37,6 +40,13 @@ func (d data) Detach(ebpf interpreter.EbpfHandler, pid libpf.PID) error {
3740
}
3841

3942
func Loader(_ interpreter.EbpfHandler, info *interpreter.LoaderInfo) (interpreter.Data, error) {
43+
// Note: So far we have observed that offsets are always the same for any
44+
// go1.mm.yy with fixed mm and any value of yy. That is; the major and minor
45+
// version determine the offsets, while the patch version has no effect.
46+
//
47+
// If this should change in some future Go patch release, we'll need to change
48+
// this function.
49+
4050
file, err := info.GetELF()
4151
if err != nil {
4252
return nil, err
@@ -50,10 +60,25 @@ func Loader(_ interpreter.EbpfHandler, info *interpreter.LoaderInfo) (interprete
5060
return nil, err
5161
}
5262
log.Debugf("file %s detected as go version %s", info.FileName(), goVersion)
63+
majorMinor := goMajorMinorRegex.FindString(goVersion)
64+
if majorMinor == "" {
65+
return nil, fmt.Errorf("failed to parse go version %s into goM.mm", goVersion)
66+
}
5367

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

5984
return data{

0 commit comments

Comments
 (0)