Skip to content

Commit

Permalink
Replace use of github.com/hashicorp/go-version
Browse files Browse the repository at this point in the history
Replace with github.com/Masterminds/semver/v3

Resolve open-telemetry#1753
  • Loading branch information
MrAlias committed Feb 7, 2025
1 parent d116894 commit 4e7e890
Show file tree
Hide file tree
Showing 29 changed files with 212 additions and 238 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ retract (
)

require (
github.com/Masterminds/semver/v3 v3.3.1
github.com/cilium/ebpf v0.17.2
github.com/go-logr/stdr v1.2.2
github.com/hashicorp/go-version v1.7.0
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.10.0
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/Masterminds/semver/v3 v3.3.1 h1:QtNSWtVZ3nBfk8mAOu/B6v7FMJ+NHTIgUPi7rj+4nv4=
github.com/Masterminds/semver/v3 v3.3.1/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
Expand Down Expand Up @@ -27,8 +29,6 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 h1:VD1gqscl4nYs1YxVuSdemTrSgTKrwOWDK0FVFMqm+Cg=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0/go.mod h1:4EgsQoS4TOhJizV+JTFg40qx1Ofh3XmXEQNBpgvNT40=
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA=
github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
github.com/jsimonetti/rtnetlink/v2 v2.0.1 h1:xda7qaHDSVOsADNouv7ukSuicKZO7GgVUCXxpaIEIlM=
Expand Down
8 changes: 4 additions & 4 deletions internal/pkg/inject/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"errors"
"fmt"

"github.com/Masterminds/semver/v3"
"github.com/cilium/ebpf"
"github.com/hashicorp/go-version"

"go.opentelemetry.io/auto/internal/pkg/process"
"go.opentelemetry.io/auto/internal/pkg/structfield"
Expand Down Expand Up @@ -139,7 +139,7 @@ func WithKeyValue(key string, value interface{}) Option {
//
// If the offset value is not known, an error is returned when the returned
// Option is used.
func WithOffset(key string, id structfield.ID, ver *version.Version) Option {
func WithOffset(key string, id structfield.ID, ver *semver.Version) Option {
if ver == nil {
return errOpt{
err: fmt.Errorf("missing version: %s", id),
Expand Down Expand Up @@ -187,10 +187,10 @@ func FindOffset(id structfield.ID, td *process.TargetDetails) (structfield.Offse
return structfield.OffsetKey{Offset: uint64(v), Valid: true}, err // nolint: gosec // Bounded.
}

func GetOffset(id structfield.ID, ver *version.Version) (structfield.OffsetKey, bool) {
func GetOffset(id structfield.ID, ver *semver.Version) (structfield.OffsetKey, bool) {
return offsets.GetOffset(id, ver)
}

func GetLatestOffset(id structfield.ID) (structfield.OffsetKey, *version.Version) {
func GetLatestOffset(id structfield.ID) (structfield.OffsetKey, *semver.Version) {
return offsets.GetLatestOffset(id)
}
8 changes: 3 additions & 5 deletions internal/pkg/inject/consts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package inject
import (
"testing"

"github.com/hashicorp/go-version"
"github.com/Masterminds/semver/v3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -54,10 +54,8 @@ func TestWithAllocationDetails(t *testing.T) {
}

func TestWithOffset(t *testing.T) {
v10, err := version.NewVersion("1.0")
require.NoError(t, err)
v18, err := version.NewVersion("1.8")
require.NoError(t, err)
v10 := semver.New(1, 0, 0, "", "")
v18 := semver.New(1, 8, 0, "", "")

const off uint64 = 1
id := structfield.NewID("std", "net/http", "Request", "Method")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"go.opentelemetry.io/auto/internal/pkg/process"
"go.opentelemetry.io/auto/internal/pkg/structfield"

"github.com/Masterminds/semver/v3"
"github.com/cilium/ebpf/perf"
"github.com/hashicorp/go-version"
"golang.org/x/sys/unix"

"go.opentelemetry.io/otel/attribute"
Expand All @@ -42,26 +42,27 @@ const (
minGoMaps = "1.24.0"
)

func must(c *semver.Constraints, err error) *semver.Constraints {
if err != nil {
panic(err)
}
return c
}

var (
otelWithAutoSDK = probe.PackageConstraints{
Package: "go.opentelemetry.io/otel",
Constraints: version.MustConstraints(
version.NewConstraint(">= " + minAutoSDK),
),
Package: "go.opentelemetry.io/otel",
Constraints: must(semver.NewConstraint(">= " + minAutoSDK)),
FailureMode: probe.FailureModeIgnore,
}
otelWithoutAutoSDK = probe.PackageConstraints{
Package: "go.opentelemetry.io/otel",
Constraints: version.MustConstraints(
version.NewConstraint("< " + minAutoSDK),
),
Package: "go.opentelemetry.io/otel",
Constraints: must(semver.NewConstraint("< " + minAutoSDK)),
FailureMode: probe.FailureModeIgnore,
}
goWithoutSwissMaps = probe.PackageConstraints{
Package: "std",
Constraints: version.MustConstraints(
version.NewConstraint("< " + minGoMaps),
),
Package: "std",
Constraints: must(semver.NewConstraint("< " + minGoMaps)),
// Warn in logs that this is not supported.
FailureMode: probe.FailureModeWarn,
}
Expand Down Expand Up @@ -251,20 +252,20 @@ type tracerIDContainsSchemaURL struct{}
// Prior to v1.28 the tracer key did not contain schemaURL. However, in that version a
// change was made to include it.
// https://github.com/open-telemetry/opentelemetry-go/pull/5426/files
var schemaAddedToTracerKeyVer = version.Must(version.NewVersion("1.28.0"))
var schemaAddedToTracerKeyVer = semver.New(1, 28, 0, "", "")

func (c tracerIDContainsSchemaURL) InjectOption(td *process.TargetDetails) (inject.Option, error) {
ver, ok := td.Modules["go.opentelemetry.io/otel"]
if !ok {
return nil, fmt.Errorf("unknown module version: %s", pkg)
}

return inject.WithKeyValue("tracer_id_contains_schemaURL", ver.GreaterThanOrEqual(schemaAddedToTracerKeyVer)), nil
return inject.WithKeyValue("tracer_id_contains_schemaURL", ver.GreaterThanEqual(schemaAddedToTracerKeyVer)), nil
}

// In v1.32.0 the tracer key was updated to include the scope attributes.
// https://github.com/open-telemetry/opentelemetry-go/pull/5924/files
var scopeAttributesAddedToTracerKeyVer = version.Must(version.NewVersion("1.32.0"))
var scopeAttributesAddedToTracerKeyVer = semver.New(1, 32, 0, "", "")

// tracerIDContainsScopeAttributes is a Probe Const defining whether the tracer key contains scope attributes.
type tracerIDContainsScopeAttributes struct{}
Expand All @@ -275,7 +276,7 @@ func (c tracerIDContainsScopeAttributes) InjectOption(td *process.TargetDetails)
return nil, fmt.Errorf("unknown module version: %s", pkg)
}

return inject.WithKeyValue("tracer_id_contains_scope_attributes", ver.GreaterThanOrEqual(scopeAttributesAddedToTracerKeyVer)), nil
return inject.WithKeyValue("tracer_id_contains_scope_attributes", ver.GreaterThanEqual(scopeAttributesAddedToTracerKeyVer)), nil
}

type attributeKeyVal struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"net"
"strconv"

"github.com/Masterminds/semver/v3"
"github.com/cilium/ebpf"
"github.com/hashicorp/go-version"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.opentelemetry.io/otel/attribute"
Expand All @@ -36,7 +36,7 @@ const (

var (
writeStatus = false
writeStatusMinVersion = version.Must(version.NewVersion("1.40.0"))
writeStatusMinVersion = semver.New(1, 40, 0, "", "")
)

type writeStatusConst struct{}
Expand All @@ -46,7 +46,7 @@ func (w writeStatusConst) InjectOption(td *process.TargetDetails) (inject.Option
if !ok {
return nil, fmt.Errorf("unknown module version: %s", pkg)
}
if ver.GreaterThanOrEqual(writeStatusMinVersion) {
if ver.GreaterThanEqual(writeStatusMinVersion) {
writeStatus = true
}
return inject.WithKeyValue("write_status_supported", writeStatus), nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"log/slog"
"net"

"github.com/hashicorp/go-version"
"github.com/Masterminds/semver/v3"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.opentelemetry.io/otel/attribute"
Expand All @@ -27,23 +27,17 @@ import (

//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -target amd64,arm64 bpf ./bpf/probe.bpf.c

const (
// pkg is the package being instrumented.
pkg = "google.golang.org/grpc"

// writeStatusMin is the minimum version of grpc that supports status
// parsing.
writeStatusMin = "1.40.0"

// serverStream is the version the both the writeStatus and handleStream
// methods changed to accept a *transport.ServerStream instead of a
// *transport.Stream.
serverStream = "1.69.0"
)
// pkg is the package being instrumented.
const pkg = "google.golang.org/grpc"

var (
writeStatusMinVersion = version.Must(version.NewVersion(writeStatusMin))
serverStreamVersion = version.Must(version.NewVersion(serverStream))
// writeStatusMinVersion is the minimum version of grpc that supports
// status parsing.
writeStatusMinVersion = semver.New(1, 40, 0, "", "")
// serverStreamVersion is the version the both the writeStatus and
// handleStream methods changed to accept a *transport.ServerStream instead
// of a *transport.Stream.
serverStreamVersion = semver.New(1, 69, 0, "", "")
)

// New returns a new [probe.Probe].
Expand Down Expand Up @@ -133,10 +127,8 @@ func New(logger *slog.Logger, ver string) probe.Probe {
ReturnProbe: "uprobe_server_handleStream_Returns",
PackageConstraints: []probe.PackageConstraints{
{
Package: "google.golang.org/grpc",
Constraints: version.MustConstraints(
version.NewConstraint("< " + serverStream),
),
Package: "google.golang.org/grpc",
Constraints: must(semver.NewConstraint("< " + serverStreamVersion.String())),
FailureMode: probe.FailureModeIgnore,
},
},
Expand All @@ -147,10 +139,8 @@ func New(logger *slog.Logger, ver string) probe.Probe {
ReturnProbe: "uprobe_server_handleStream2_Returns",
PackageConstraints: []probe.PackageConstraints{
{
Package: "google.golang.org/grpc",
Constraints: version.MustConstraints(
version.NewConstraint(">= " + serverStream),
),
Package: "google.golang.org/grpc",
Constraints: must(semver.NewConstraint(">= " + serverStreamVersion.String())),
FailureMode: probe.FailureModeIgnore,
},
},
Expand All @@ -165,11 +155,9 @@ func New(logger *slog.Logger, ver string) probe.Probe {
PackageConstraints: []probe.PackageConstraints{
{
Package: "google.golang.org/grpc",
Constraints: version.MustConstraints(
version.NewConstraint(
fmt.Sprintf("> %s, < %s", writeStatusMin, serverStream),
),
),
Constraints: must(semver.NewConstraint(
fmt.Sprintf("> %s, < %s", writeStatusMinVersion, serverStreamVersion),
)),
FailureMode: probe.FailureModeIgnore,
},
},
Expand All @@ -179,10 +167,8 @@ func New(logger *slog.Logger, ver string) probe.Probe {
EntryProbe: "uprobe_http2Server_WriteStatus2",
PackageConstraints: []probe.PackageConstraints{
{
Package: "google.golang.org/grpc",
Constraints: version.MustConstraints(
version.NewConstraint(">= " + serverStream),
),
Package: "google.golang.org/grpc",
Constraints: must(semver.NewConstraint(">= " + serverStreamVersion.String())),
FailureMode: probe.FailureModeIgnore,
},
},
Expand All @@ -196,6 +182,13 @@ func New(logger *slog.Logger, ver string) probe.Probe {
}
}

func must(c *semver.Constraints, err error) *semver.Constraints {
if err != nil {
panic(err)
}
return c
}

// framePosConst is a Probe Const defining the position of the
// http.MetaHeadersFrame parameter of the http2Server.operateHeaders method.
type framePosConst struct{}
Expand All @@ -204,21 +197,21 @@ type framePosConst struct{}
// context was added as the first parameter. The frame became the second
// parameter:
// https://github.com/grpc/grpc-go/pull/6716/files#diff-4058722211b8d52e2d5b0c0b7542059ed447a04017b69520d767e94a9493409eR334
var paramChangeVer = version.Must(version.NewVersion("1.60.0"))
var paramChangeVer = semver.New(1, 60, 0, "", "")

func (c framePosConst) InjectOption(td *process.TargetDetails) (inject.Option, error) {
ver, ok := td.Modules[pkg]
if !ok {
return nil, fmt.Errorf("unknown module version: %s", pkg)
}

return inject.WithKeyValue("is_new_frame_pos", ver.GreaterThanOrEqual(paramChangeVer)), nil
return inject.WithKeyValue("is_new_frame_pos", ver.GreaterThanEqual(paramChangeVer)), nil
}

type serverAddrConst struct{}

var (
serverAddrMinVersion = version.Must(version.NewVersion("1.60.0"))
serverAddrMinVersion = semver.New(1, 60, 0, "", "")
serverAddr = false
)

Expand All @@ -227,7 +220,7 @@ func (w serverAddrConst) InjectOption(td *process.TargetDetails) (inject.Option,
if !ok {
return nil, fmt.Errorf("unknown module version: %s", pkg)
}
if ver.GreaterThanOrEqual(serverAddrMinVersion) {
if ver.GreaterThanEqual(serverAddrMinVersion) {
serverAddr = true
}
return inject.WithKeyValue("server_addr_supported", serverAddr), nil
Expand Down
Loading

0 comments on commit 4e7e890

Please sign in to comment.