Skip to content

Fix FootprintForkedTest that was also measuring Spock mock #9298

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

Merged
merged 1 commit into from
Aug 4, 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
2 changes: 1 addition & 1 deletion dd-trace-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ dependencies {
testImplementation project(':remote-config:remote-config-core')
testImplementation group: 'org.msgpack', name: 'msgpack-core', version: '0.8.20'
testImplementation group: 'org.msgpack', name: 'jackson-dataformat-msgpack', version: '0.8.20'
testImplementation group: 'org.openjdk.jol', name: 'jol-core', version: '0.16'
testImplementation group: 'org.openjdk.jol', name: 'jol-core', version: '0.17'
testImplementation group: 'commons-codec', name: 'commons-codec', version: '1.3'
testImplementation group: 'com.amazonaws', name: 'aws-lambda-java-events', version:'3.11.0'
testImplementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.14.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ class FootprintForkedTest extends DDSpecification {
setup:
CountDownLatch latch = new CountDownLatch(1)
ValidatingSink sink = new ValidatingSink(latch)
DDAgentFeaturesDiscovery features = Mock(DDAgentFeaturesDiscovery)
features.supportsMetrics() >> true
DDAgentFeaturesDiscovery features = Stub(DDAgentFeaturesDiscovery) {
it.supportsMetrics() >> true
}
ConflatingMetricsAggregator aggregator = new ConflatingMetricsAggregator(
new WellKnownTags("runtimeid","hostname", "env", "service", "version","language"),
[].toSet() as Set<String>,
Expand All @@ -35,8 +36,10 @@ class FootprintForkedTest extends DDSpecification {
1000,
1000,
100,
SECONDS)
long baseline = footprint(aggregator)
SECONDS
)
// Removing the 'features' as it's a mock, and mocks are heavyweight, e.g. around 22MiB
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: features is now a stub, not a mock (stubs can still be heavyweight)

Copy link
Contributor Author

@bric3 bric3 Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true, indeed I found that a stub is pretty heavy with all the Spock plus Groovy "magic". I believe this is not what the test wants to measure, so kept it excluded from the footprint.

I found that using a Stub reduces the test memory footprint.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, was just thinking the comment should read:

    // Removing 'features' as it's a stub, and stubs/mocks are heavyweight, e.g. around 22MiB

but not a big deal

def baseline = footprint(aggregator, features)
aggregator.start()

when: "lots of traces are published"
Expand Down Expand Up @@ -70,7 +73,8 @@ class FootprintForkedTest extends DDSpecification {
assert latch.await(30, SECONDS)

then:
footprint(aggregator) - baseline <= 10 * 1024 * 1024
def layout = footprint(aggregator, features)
layout.totalSize() - baseline.totalSize() <= 10 * 1024 * 1024

cleanup:
aggregator.close()
Expand Down Expand Up @@ -134,9 +138,14 @@ class FootprintForkedTest extends DDSpecification {
}


static long footprint(Object o) {
GraphLayout layout = GraphLayout.parseInstance(o)
System.err.println(layout.toFootprint())
return layout.totalSize()
static GraphLayout footprint(Object root, Object... excludedRootFieldInstance) {
GraphLayout layout = GraphLayout.parseInstance(root)

excludedRootFieldInstance.each {
layout = layout.subtract(GraphLayout.parseInstance(it))
}

println layout.toFootprint()
return layout
}
}