@@ -3,6 +3,7 @@ package golang
3
3
import (
4
4
"errors"
5
5
"fmt"
6
+ "regexp"
6
7
"unsafe"
7
8
8
9
log "github.com/sirupsen/logrus"
@@ -16,6 +17,8 @@ import (
16
17
// #include "../../support/ebpf/types.h"
17
18
import "C"
18
19
20
+ var goMajorMinorRegex = regexp .MustCompile (`^go\d+\.\d+` )
21
+
19
22
type data struct {
20
23
goVersion string
21
24
offsets C.GoCustomLabelsOffsets
@@ -37,6 +40,13 @@ func (d data) Detach(ebpf interpreter.EbpfHandler, pid libpf.PID) error {
37
40
}
38
41
39
42
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
+
40
50
file , err := info .GetELF ()
41
51
if err != nil {
42
52
return nil , err
@@ -50,10 +60,25 @@ func Loader(_ interpreter.EbpfHandler, info *interpreter.LoaderInfo) (interprete
50
60
return nil , err
51
61
}
52
62
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
+ }
53
67
54
- offsets , ok := allOffsets [goVersion ]
68
+ offsets , ok := allOffsets [majorMinor ]
55
69
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
57
82
}
58
83
59
84
return data {
0 commit comments