Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added fix for the delayed span testcase failures #1024

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 55 additions & 38 deletions delayed_spans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ func TestAppendALotDelayedSpans(t *testing.T) {
assert.Len(t, ds.spans, maxDelayedSpans)
}

func resetDelayedSpans() {
delayed = &delayedSpans{
spans: make(chan *spanS, maxDelayedSpans),
}
}

func TestPartiallyFlushDelayedSpans(t *testing.T) {
defer resetDelayedSpans()

//We need to simulate that the agent is not ready.
ok, cleanupFunc := setupEnv()
if ok {
defer cleanupFunc()
}

recorder := NewTestRecorder()
c := InitCollector(&Options{
Service: "go-sensor-test",
Expand All @@ -52,12 +52,6 @@ func TestPartiallyFlushDelayedSpans(t *testing.T) {

generateSomeTraffic(c, maxDelayedSpans)

// serverless agent should not be present for this test to pass.
// following check is added for debugging random failures in the unit tests of delayed spans
// TODO: remove it once the issue is resolved.
url, _ := os.LookupEnv("INSTANA_ENDPOINT_URL")
assert.Equal(t, "", url)

assert.Len(t, delayed.spans, maxDelayedSpans)

notReadyAfter := maxDelayedSpans / 10
Expand All @@ -73,6 +67,12 @@ func TestPartiallyFlushDelayedSpans(t *testing.T) {
func TestFlushDelayedSpans(t *testing.T) {
defer resetDelayedSpans()

//We need to simulate that the agent is not ready.
ok, cleanupFunc := setupEnv()
if ok {
defer cleanupFunc()
}

recorder := NewTestRecorder()
c := InitCollector(&Options{
Service: "go-sensor-test",
Expand All @@ -85,12 +85,6 @@ func TestFlushDelayedSpans(t *testing.T) {

generateSomeTraffic(c, maxDelayedSpans)

// serverless agent should not be present for this test to pass.
// following check is added for debugging random failures in the unit tests of delayed spans
// TODO: remove it once the issue is resolved.
_, isURLPresent := os.LookupEnv("INSTANA_ENDPOINT_URL")
assert.Equal(t, false, isURLPresent)

assert.Len(t, delayed.spans, maxDelayedSpans)

sensor.agent = alwaysReadyClient{}
Expand All @@ -103,6 +97,12 @@ func TestFlushDelayedSpans(t *testing.T) {
func TestParallelFlushDelayedSpans(t *testing.T) {
defer resetDelayedSpans()

//We need to simulate that the agent is not ready.
ok, cleanupFunc := setupEnv()
if ok {
defer cleanupFunc()
}

m, _ := NamedMatcher(ContainsIgnoreCaseMatcher, []string{"q", "secret"})

recorder := NewTestRecorder()
Expand All @@ -117,12 +117,6 @@ func TestParallelFlushDelayedSpans(t *testing.T) {

generateSomeTraffic(c, maxDelayedSpans*2)

// serverless agent should not be present for this test to pass.
// following check is added for debugging random failures in the unit tests of delayed spans
// TODO: remove it once the issue is resolved.
_, isURLPresent := os.LookupEnv("INSTANA_ENDPOINT_URL")
assert.Equal(t, false, isURLPresent)

assert.Len(t, delayed.spans, maxDelayedSpans)

workers := 15
Expand Down Expand Up @@ -154,6 +148,43 @@ func TestParallelFlushDelayedSpans(t *testing.T) {
}
}

func generateSomeTraffic(s TracerLogger, amount int) {
h := TracingNamedHandlerFunc(s, "action", "/{action}", func(w http.ResponseWriter, req *http.Request) {
_, _ = fmt.Fprintln(w, "Ok")
})

req := httptest.NewRequest(http.MethodGet, "/test?q=term&secret=mypassword", nil)

rec := httptest.NewRecorder()

for i := 0; i < amount; i++ {
h.ServeHTTP(rec, req)
}
}

func resetDelayedSpans() {
delayed = &delayedSpans{
spans: make(chan *spanS, maxDelayedSpans),
}
}

func setupEnv() (bool, func()) {
// The presence of INSTANA_ENDPOINT_URL will lead to the creation of serverless agent client.
if url, ok := os.LookupEnv("INSTANA_ENDPOINT_URL"); ok {
if err := os.Unsetenv("INSTANA_ENDPOINT_URL"); err != nil {
fmt.Println("failed to unset INSTANA_ENDPOINT_URL")
panic(err)
}
return ok, func() {
if err := os.Setenv("INSTANA_ENDPOINT_URL", url); err != nil {
fmt.Println("failed to set INSTANA_ENDPOINT_URL")
panic(err)
}
}
}
return false, nil
}

type eventuallyNotReadyClient struct {
notReadyAfter uint64
ops uint64
Expand All @@ -169,17 +200,3 @@ func (*eventuallyNotReadyClient) SendEvent(event *EventData) error
func (*eventuallyNotReadyClient) SendSpans(spans []Span) error { return nil }
func (*eventuallyNotReadyClient) SendProfiles(profiles []autoprofile.Profile) error { return nil }
func (*eventuallyNotReadyClient) Flush(context.Context) error { return nil }

func generateSomeTraffic(s TracerLogger, amount int) {
h := TracingNamedHandlerFunc(s, "action", "/{action}", func(w http.ResponseWriter, req *http.Request) {
fmt.Fprintln(w, "Ok")
})

req := httptest.NewRequest(http.MethodGet, "/test?q=term&secret=mypassword", nil)

rec := httptest.NewRecorder()

for i := 0; i < amount; i++ {
h.ServeHTTP(rec, req)
}
}
6 changes: 3 additions & 3 deletions example/grpc-client-server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ require (
github.com/instana/go-sensor v1.66.1
github.com/instana/go-sensor/instrumentation/instagrpc v1.11.0
github.com/opentracing/opentracing-go v1.2.0
google.golang.org/grpc v1.69.4
google.golang.org/protobuf v1.35.1
google.golang.org/grpc v1.70.0
google.golang.org/protobuf v1.35.2
)

require (
Expand All @@ -16,7 +16,7 @@ require (
golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a // indirect
)

replace (
Expand Down
32 changes: 16 additions & 16 deletions example/grpc-client-server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY=
go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE=
go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE=
go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY=
go.opentelemetry.io/otel/sdk v1.31.0 h1:xLY3abVHYZ5HSfOg3l2E5LUj2Cwva5Y7yGxnSW9H5Gk=
go.opentelemetry.io/otel/sdk v1.31.0/go.mod h1:TfRbMdhvxIIr/B2N2LQW2S5v9m3gOQ/08KsbbO5BPT0=
go.opentelemetry.io/otel/sdk/metric v1.31.0 h1:i9hxxLJF/9kkvfHppyLL55aW7iIJz4JjxTeYusH7zMc=
go.opentelemetry.io/otel/sdk/metric v1.31.0/go.mod h1:CRInTMVvNhUKgSAMbKyTMxqOBC0zgyxzW55lZzX43Y8=
go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys=
go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A=
go.opentelemetry.io/otel v1.32.0 h1:WnBN+Xjcteh0zdk01SVqV55d/m62NJLJdIyb4y/WO5U=
go.opentelemetry.io/otel v1.32.0/go.mod h1:00DCVSB0RQcnzlwyTfqtxSm+DRr9hpYrHjNGiBHVQIg=
go.opentelemetry.io/otel/metric v1.32.0 h1:xV2umtmNcThh2/a/aCP+h64Xx5wsj8qqnkYZktzNa0M=
go.opentelemetry.io/otel/metric v1.32.0/go.mod h1:jH7CIbbK6SH2V2wE16W05BHCtIDzauciCRLoc/SyMv8=
go.opentelemetry.io/otel/sdk v1.32.0 h1:RNxepc9vK59A8XsgZQouW8ue8Gkb4jpWtJm9ge5lEG4=
go.opentelemetry.io/otel/sdk v1.32.0/go.mod h1:LqgegDBjKMmb2GC6/PrTnteJG39I8/vJCAP9LlJXEjU=
go.opentelemetry.io/otel/sdk/metric v1.32.0 h1:rZvFnvmvawYb0alrYkjraqJq0Z4ZUJAiyYCU9snn1CU=
go.opentelemetry.io/otel/sdk/metric v1.32.0/go.mod h1:PWeZlq0zt9YkYAp3gjKZ0eicRYvOh1Gd+X99x6GHpCQ=
go.opentelemetry.io/otel/trace v1.32.0 h1:WIC9mYrXf8TmY/EXuULKc8hR17vE+Hjv2cssQDe03fM=
go.opentelemetry.io/otel/trace v1.32.0/go.mod h1:+i4rkvCraA+tG6AzwloGaCtkx53Fa+L+V8e9a7YvhT8=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 h1:X58yt85/IXCx0Y3ZwN6sEIKZzQtDEYaBWrDvErdXrRE=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
google.golang.org/grpc v1.69.4 h1:MF5TftSMkd8GLw/m0KM6V8CMOCY6NZ1NQDPGFgbTt4A=
google.golang.org/grpc v1.69.4/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a h1:hgh8P4EuoxpsuKMXX/To36nOFD7vixReXgn8lPGnt+o=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU=
google.golang.org/grpc v1.70.0 h1:pWFv03aZoHzlRKHWicjsZytKAiYCtNS0dHbXnIdq7jQ=
google.golang.org/grpc v1.70.0/go.mod h1:ofIJqVKDXx/JiXrwr2IG4/zwdH9txy3IlF40RmcJSQw=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading