Skip to content

Commit

Permalink
remove flakyness from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
t00mas committed May 22, 2024
1 parent 30bdc11 commit a11082d
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 125 deletions.
55 changes: 37 additions & 18 deletions connector/servicegraphconnector/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ func TestExtraDimensionsLabels(t *testing.T) {
require.NoError(t, err)
}

func TestVirtualNodeLabels(t *testing.T) {
func TestVirtualNodeServerLabels(t *testing.T) {
virtualNodeDimensions := []string{"peer.service", "db.system", "messaging.system"}
cfg := &Config{
Dimensions: virtualNodeDimensions,
Expand All @@ -484,27 +484,46 @@ func TestVirtualNodeLabels(t *testing.T) {

set := componenttest.NewNopTelemetrySettings()
set.Logger = zaptest.NewLogger(t)
conn := newConnector(set, cfg, newMockMetricsExporter())

assert.NoError(t, conn.Start(context.Background(), componenttest.NewNopHost()))
testcases := []struct {
name string
trace string
expected string
}{
{
name: "server",
trace: "testdata/virtual-node-label-server-trace.yaml",
expected: "testdata/virtual-node-label-server-expected-metrics.yaml",
},
{
name: "client",
trace: "testdata/virtual-node-label-client-trace.yaml",
expected: "testdata/virtual-node-label-client-expected-metrics.yaml",
},
}

td, err := golden.ReadTraces("testdata/virtual-node-label-trace.yaml")
assert.NoError(t, err)
assert.NoError(t, conn.ConsumeTraces(context.Background(), td))
for _, tc := range testcases {
conn := newConnector(set, cfg, newMockMetricsExporter())
assert.NoError(t, conn.Start(context.Background(), componenttest.NewNopHost()))

conn.store.Expire()
time.Sleep(1 * time.Millisecond) // Wait for metrics to be flushed
require.NoError(t, conn.Shutdown(context.Background()))
td, err := golden.ReadTraces(tc.trace)
assert.NoError(t, err)
assert.NoError(t, conn.ConsumeTraces(context.Background(), td))

metrics := conn.metricsConsumer.(*mockMetricsExporter).md
require.GreaterOrEqual(t, len(metrics), 1) // Unreliable sleep-based check
conn.store.Expire()
time.Sleep(2 * time.Millisecond) // Wait for metrics to be flushed
require.NoError(t, conn.Shutdown(context.Background()))

expectedMetrics, err := golden.ReadMetrics("testdata/virtual-node-label-expected-metrics.yaml")
assert.NoError(t, err)
metrics := conn.metricsConsumer.(*mockMetricsExporter).md
require.GreaterOrEqual(t, len(metrics), 1) // Unreliable sleep-based check

err = pmetrictest.CompareMetrics(expectedMetrics, metrics[0],
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreTimestamp(),
)
require.NoError(t, err)
expectedMetrics, err := golden.ReadMetrics(tc.expected)
assert.NoError(t, err)

err = pmetrictest.CompareMetrics(expectedMetrics, metrics[0],
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreTimestamp(),
)
require.NoError(t, err)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,6 @@ resourceMetrics:
- resource: {}
scopeMetrics:
- metrics:
- name: traces_service_graph_request_total
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "1"
attributes:
- key: client
value:
stringValue: foo-server
- key: connection_type
value:
stringValue: virtual_node
- key: failed
value:
boolValue: false
- key: server
value:
stringValue: unknown
- key: virtual_node
value:
stringValue: server
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
isMonotonic: true
- name: traces_service_graph_request_total
sum:
aggregationTemporality: 2
Expand Down Expand Up @@ -53,39 +29,6 @@ resourceMetrics:
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
isMonotonic: true
- histogram:
aggregationTemporality: 2
dataPoints:
- attributes:
- key: client
value:
stringValue: foo-server
- key: connection_type
value:
stringValue: virtual_node
- key: failed
value:
boolValue: false
- key: server
value:
stringValue: unknown
- key: virtual_node
value:
stringValue: server
bucketCounts:
- "1"
- "0"
- "0"
- "0"
count: "1"
explicitBounds:
- 0.1
- 1
- 10
startTimeUnixNano: "1000000"
sum: 0.000001
timeUnixNano: "2000000"
name: traces_service_graph_request_server_seconds
- histogram:
aggregationTemporality: 2
dataPoints:
Expand Down Expand Up @@ -122,39 +65,6 @@ resourceMetrics:
sum: 0.000000
timeUnixNano: "2000000"
name: traces_service_graph_request_server_seconds
- histogram:
aggregationTemporality: 2
dataPoints:
- attributes:
- key: client
value:
stringValue: foo-server
- key: connection_type
value:
stringValue: virtual_node
- key: failed
value:
boolValue: false
- key: server
value:
stringValue: unknown
- key: virtual_node
value:
stringValue: server
bucketCounts:
- "1"
- "0"
- "0"
- "0"
count: "1"
explicitBounds:
- 0.1
- 1
- 10
startTimeUnixNano: "1000000"
sum: 0.000000
timeUnixNano: "2000000"
name: traces_service_graph_request_client_seconds
- histogram:
aggregationTemporality: 2
dataPoints:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
resourceSpans:
- resource:
attributes:
- key: service.name
value:
stringValue: foo-server
scopeSpans:
- scope:
name: foo-server
spans:
- traceId: a0000000000000000000000000000000
spanId: a000000000000000
name: server
kind: 3
startTimeUnixNano: "1800000000000000000"
endTimeUnixNano: "1800000000000001000"
parentSpanId: ""
- resource:
attributes:
- key: service.name
Expand All @@ -34,4 +18,4 @@ resourceSpans:
attributes:
- key: peer.service
value:
stringValue: external-platform
stringValue: external-platform
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
resourceMetrics:
- resource: {}
scopeMetrics:
- metrics:
- name: traces_service_graph_request_total
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "1"
attributes:
- key: client
value:
stringValue: foo-server
- key: connection_type
value:
stringValue: virtual_node
- key: failed
value:
boolValue: false
- key: server
value:
stringValue: unknown
- key: virtual_node
value:
stringValue: server
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
isMonotonic: true
- histogram:
aggregationTemporality: 2
dataPoints:
- attributes:
- key: client
value:
stringValue: foo-server
- key: connection_type
value:
stringValue: virtual_node
- key: failed
value:
boolValue: false
- key: server
value:
stringValue: unknown
- key: virtual_node
value:
stringValue: server
bucketCounts:
- "1"
- "0"
- "0"
- "0"
count: "1"
explicitBounds:
- 0.1
- 1
- 10
startTimeUnixNano: "1000000"
sum: 0.000001
timeUnixNano: "2000000"
name: traces_service_graph_request_server_seconds
- histogram:
aggregationTemporality: 2
dataPoints:
- attributes:
- key: client
value:
stringValue: foo-server
- key: connection_type
value:
stringValue: virtual_node
- key: failed
value:
boolValue: false
- key: server
value:
stringValue: unknown
- key: virtual_node
value:
stringValue: server
bucketCounts:
- "1"
- "0"
- "0"
- "0"
count: "1"
explicitBounds:
- 0.1
- 1
- 10
startTimeUnixNano: "1000000"
sum: 0.000000
timeUnixNano: "2000000"
name: traces_service_graph_request_client_seconds
scope:
name: traces_service_graph
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resourceSpans:
- resource:
attributes:
- key: service.name
value:
stringValue: foo-server
scopeSpans:
- scope:
name: foo-server
spans:
- traceId: a0000000000000000000000000000000
spanId: a000000000000000
name: server
kind: 3
startTimeUnixNano: "1800000000000000000"
endTimeUnixNano: "1800000000000001000"
parentSpanId: ""

0 comments on commit a11082d

Please sign in to comment.