From 1942c31f27809f6c25ab179809248c99fd401814 Mon Sep 17 00:00:00 2001 From: simont1 Date: Tue, 2 Apr 2024 15:31:52 -0400 Subject: [PATCH 1/4] fix flaky test --- pkg/trace/stats/aggregation.go | 1 + pkg/trace/stats/concentrator_test.go | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/pkg/trace/stats/aggregation.go b/pkg/trace/stats/aggregation.go index 08cab775ef0c1..9fc8f696ae957 100644 --- a/pkg/trace/stats/aggregation.go +++ b/pkg/trace/stats/aggregation.go @@ -146,6 +146,7 @@ func NewAggregationFromGroup(g *pb.ClientGroupedStats) Aggregation { StatusCode: g.HTTPStatusCode, Synthetics: g.Synthetics, PeerTagsHash: peerTagsHash(g.PeerTags), + IsTraceRoot: g.IsTraceRoot, }, } } diff --git a/pkg/trace/stats/concentrator_test.go b/pkg/trace/stats/concentrator_test.go index 4bd378a52f936..8b8bf7e8c92b8 100644 --- a/pkg/trace/stats/concentrator_test.go +++ b/pkg/trace/stats/concentrator_test.go @@ -546,14 +546,15 @@ func TestConcentratorStatsCounts(t *testing.T) { func TestRootTag(t *testing.T) { now := time.Now() spans := []*pb.Span{ - testSpan(now, 1, 0, 40, 10, "A1", "resource1", 0, nil), - testSpan(now, 2, 1, 30, 10, "A1", "resource1", 0, nil), - testSpan(now, 3, 2, 20, 10, "A1", "resource1", 0, map[string]string{"span.kind": "client"}), - testSpan(now, 4, 1000, 10, 10, "A1", "resource1", 0, nil), + testSpan(now, 1, 0, 40, 10, "A1", "resource1", 0, nil), // root span + testSpan(now, 2, 1, 30, 10, "A1", "resource1", 0, nil), // not top level, doesn't produce stats + testSpan(now, 3, 2, 20, 10, "A1", "resource1", 0, map[string]string{"span.kind": "client"}), // non-root, non-top level, but client span + testSpan(now, 4, 1000, 10, 10, "A1", "resource1", 0, nil), // non-root but top level span } traceutil.ComputeTopLevel(spans) testTrace := toProcessedTrace(spans, "none", "", "", "", "") c := NewTestConcentrator(now) + c.computeStatsBySpanKind = true c.addNow(testTrace, "") expected := []*pb.ClientGroupedStats{ @@ -562,9 +563,9 @@ func TestRootTag(t *testing.T) { Resource: "resource1", Type: "db", Name: "query", - Duration: 60, - Hits: 2, - TopLevelHits: 2, + Duration: 40, + Hits: 1, + TopLevelHits: 1, Errors: 0, IsTraceRoot: pb.TraceRootFlag_TRUE, }, @@ -579,6 +580,18 @@ func TestRootTag(t *testing.T) { Errors: 0, IsTraceRoot: pb.TraceRootFlag_FALSE, }, + { + Service: "A1", + Resource: "resource1", + Type: "db", + Name: "query", + Duration: 20, + Hits: 1, + TopLevelHits: 0, + Errors: 0, + IsTraceRoot: pb.TraceRootFlag_FALSE, + SpanKind: "client", + }, } stats := c.flushNow(now.UnixNano()+int64(c.bufferLen)*testBucketInterval, false) From 792f007e566ec3deb10325432ef936ac39cdd5da Mon Sep 17 00:00:00 2001 From: simont1 Date: Thu, 11 Apr 2024 12:28:12 -0400 Subject: [PATCH 2/4] root tag e2e test --- test/new-e2e/tests/apm/tests.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/new-e2e/tests/apm/tests.go b/test/new-e2e/tests/apm/tests.go index a3214c469ab07..34f0e8d349522 100644 --- a/test/new-e2e/tests/apm/tests.go +++ b/test/new-e2e/tests/apm/tests.go @@ -110,6 +110,25 @@ func testAutoVersionStats(t *testing.T, c *assert.CollectT, intake *components.F } } +func testIsTraceRootTag(t *testing.T, c *assert.CollectT, intake *components.FakeIntake) { + t.Helper() + stats, err := intake.Client().GetAPMStats() + assert.NoError(c, err) + assert.NotEmpty(c, stats) + t.Log("Got apm stats:", spew.Sdump(stats)) + for _, p := range stats { + for _, s := range p.StatsPayload.Stats { + t.Log("Client Payload:", spew.Sdump(s)) + for _, b := range s.Stats { + for _, cs := range b.Stats { + t.Logf("Got IsTraceRoot: %v", cs.GetIsTraceRoot()) + assert.Equal(t, "true", cs.GetIsTraceRoot()) + } + } + } + } +} + func getContainerTags(t *testing.T, tp *trace.TracerPayload) (map[string]string, bool) { ctags, ok := tp.Tags["_dd.tags.container"] if !ok { From d7c20866b2ffde8727461ffd0c2271e129b42e5f Mon Sep 17 00:00:00 2001 From: simont1 Date: Thu, 11 Apr 2024 14:35:36 -0400 Subject: [PATCH 3/4] use tests --- test/new-e2e/tests/apm/docker_test.go | 12 ++++++++++++ test/new-e2e/tests/apm/vm_test.go | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/test/new-e2e/tests/apm/docker_test.go b/test/new-e2e/tests/apm/docker_test.go index cf78c1842074a..fb1761f3b0077 100644 --- a/test/new-e2e/tests/apm/docker_test.go +++ b/test/new-e2e/tests/apm/docker_test.go @@ -113,6 +113,18 @@ func (s *DockerFakeintakeSuite) TestAutoVersionStats() { }, 2*time.Minute, 10*time.Second, "Failed finding version tags") } +func (s *DockerFakeintakeSuite) TestIsTraceRootTag() { + err := s.Env().FakeIntake.Client().FlushServerAndResetAggregators() + s.Require().NoError(err) + + service := fmt.Sprintf("tracegen-auto-is-trace-root-tag-%s", s.transport) + defer waitTracegenShutdown(&s.Suite, s.Env().FakeIntake) + defer runTracegenDocker(s.Env().RemoteHost, service, tracegenCfg{transport: s.transport})() + s.EventuallyWithTf(func(c *assert.CollectT) { + testIsTraceRootTag(s.T(), c, s.Env().FakeIntake) + }, 2*time.Minute, 10*time.Second, "Failed finding is_trace_root tag") +} + func (s *DockerFakeintakeSuite) TestStatsForService() { err := s.Env().FakeIntake.Client().FlushServerAndResetAggregators() s.Require().NoError(err) diff --git a/test/new-e2e/tests/apm/vm_test.go b/test/new-e2e/tests/apm/vm_test.go index 145223e668381..1870590cb0b79 100644 --- a/test/new-e2e/tests/apm/vm_test.go +++ b/test/new-e2e/tests/apm/vm_test.go @@ -220,6 +220,29 @@ func (s *VMFakeintakeSuite) TestAutoVersionStats() { }, 3*time.Minute, 10*time.Second, "Failed finding stats") } +func (s *VMFakeintakeSuite) TestIsTraceRootTag() { + err := s.Env().FakeIntake.Client().FlushServerAndResetAggregators() + s.Require().NoError(err) + + service := fmt.Sprintf("tracegen-stats-%s", s.transport) + + // Wait for agent to be live + s.T().Log("Waiting for Trace Agent to be live.") + s.Require().NoError(waitRemotePort(s, 8126)) + + // Run Trace Generator + s.T().Log("Starting Trace Generator.") + defer waitTracegenShutdown(&s.Suite, s.Env().FakeIntake) + shutdown := runTracegenDocker(s.Env().RemoteHost, service, tracegenCfg{transport: s.transport}) + defer shutdown() + + s.EventuallyWithTf(func(c *assert.CollectT) { + s.logStatus() + testIsTraceRootTag(s.T(), c, s.Env().FakeIntake) + s.logJournal() + }, 3*time.Minute, 10*time.Second, "Failed finding stats") +} + func (s *VMFakeintakeSuite) TestBasicTrace() { err := s.Env().FakeIntake.Client().FlushServerAndResetAggregators() s.Require().NoError(err) From 7d4288390934dcbe68e3ae83abe451d265071dd1 Mon Sep 17 00:00:00 2001 From: simont1 Date: Fri, 12 Apr 2024 10:17:28 -0400 Subject: [PATCH 4/4] use the root flag enum value --- test/new-e2e/tests/apm/tests.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/new-e2e/tests/apm/tests.go b/test/new-e2e/tests/apm/tests.go index 34f0e8d349522..5a45b6c0e5318 100644 --- a/test/new-e2e/tests/apm/tests.go +++ b/test/new-e2e/tests/apm/tests.go @@ -122,7 +122,7 @@ func testIsTraceRootTag(t *testing.T, c *assert.CollectT, intake *components.Fak for _, b := range s.Stats { for _, cs := range b.Stats { t.Logf("Got IsTraceRoot: %v", cs.GetIsTraceRoot()) - assert.Equal(t, "true", cs.GetIsTraceRoot()) + assert.Equal(t, trace.TraceRootFlag_TRUE, cs.GetIsTraceRoot()) } } }