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

StartupHook: Introduce AssemblyLoadContext to load agent assemblies #1169

Closed
wants to merge 8 commits into from
Closed

StartupHook: Introduce AssemblyLoadContext to load agent assemblies #1169

wants to merge 8 commits into from

Conversation

gregkalapos
Copy link
Contributor

Prior to this PR with the startuphook feature we loaded everything into AssemblyLoadContext.Default. This PR introduces a separate AssemblyLoadContext to load agent assemblies and dependencies of agent assemblies.

Why we need this?

  • The agent depends on Newtonsoft.Json Version="11.0.2"
  • If the application depends on a different version (which is not unlikely), we cause a conflict. What happens in those cases is that when we try to load Newtonsoft.Json with AssemblyLoadContext.Default, it throws an exception and the agent won't work.
  • With an extra load context we can load the two versions at the same time, the app uses its own version and the agent also uses its own version, all good.

The problem this PR solves can be reproduced by creating an empty project, adding <PackageReference Include="Newtonsoft.Json" Version="9.0.2" /> (or any version) to its csproj file and use the startuphook feature. Same happens when there is a dependency in the app which depends on Newtonsoft.Json.

@gregkalapos gregkalapos self-assigned this Feb 8, 2021
@gregkalapos gregkalapos requested a review from russcam February 8, 2021 21:39
@apmmachine
Copy link
Contributor

apmmachine commented Feb 8, 2021

💔 Tests Failed

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Branch indexing

  • Start Time: 2021-03-12T02:20:20.705+0000

  • Duration: 63 min 53 sec

  • Commit: c71b835

Test stats 🧪

Test Results
Failed 1
Passed 18610
Skipped 80
Total 18691

Trends 🧪

Image of Build Times

Image of Tests

Test errors 1

Expand to view the tests failures

[failed-to-read] – junit-NETCoreApp21-Elastic.Apm.StartupHook.Tests.xml
  • no error details
  • Expand to view the stacktrace

     Failed to read test report file /var/lib/jenkins/workspace/net_apm-agent-dotnet-mbp_PR-1169/apm-agent-dotnet/test/Elastic.Apm.StartupHook.Tests/junit-NETCoreApp21-Elastic.Apm.StartupHook.Tests.xml
    org.dom4j.DocumentException: Error on line 6 of document  : XML document structures must start and end within the same entity.
    	at org.dom4j.io.SAXReader.read(SAXReader.java:511)
    	at org.dom4j.io.SAXReader.read(SAXReader.java:392)
    	at hudson.tasks.junit.SuiteResult.parse(SuiteResult.java:178)
    	at hudson.tasks.junit.TestResult.parse(TestResult.java:378)
    	at hudson.tasks.junit.TestResult.parsePossiblyEmpty(TestResult.java:308)
    	at hudson.tasks.junit.TestResult.parse(TestResult.java:224)
    	at hudson.tasks.junit.TestResult.parse(TestResult.java:196)
    	at hudson.tasks.junit.TestResult.<init>(TestResult.java:151)
    	at hudson.tasks.junit.JUnitParser$ParseResultCallable.invoke(JUnitParser.java:144)
    	at hudson.FilePath$FileCallableWrapper.call(FilePath.java:3314)
    	at hudson.remoting.UserRequest.perform(UserRequest.java:211)
    	at hudson.remoting.UserRequest.perform(UserRequest.java:54)
    	at hudson.remoting.Request$2.run(Request.java:375)
    	at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:73)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    	at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:118)
    	at java.lang.Thread.run(Thread.java:748)
    Caused by: org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 40; XML document structures must start and end within the same entity.
    	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
    	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
    	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)
    	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
    	at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1473)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.endEntity(XMLDocumentFragmentScannerImpl.java:899)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.endEntity(XMLDocumentScannerImpl.java:559)
    	at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.endEntity(XMLEntityManager.java:1410)
    	at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1916)
    	at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.scanLiteral(XMLEntityScanner.java:1187)
    	at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanAttributeValue(XMLScanner.java:859)
    	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanAttribute(XMLNSDocumentScannerImpl.java:447)
    	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:250)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2784)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
    	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
    	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
    	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
    	at org.dom4j.io.SAXReader.read(SAXReader.java:494)
    	... 18 more
     
    

Steps errors 4

Expand to view the steps failures

Test & coverage
  • Took 9 min 14 sec . View more details on here
  • Description: .ci/windows/testnet461.bat
Archive the artifacts
  • Took 0 min 0 sec . View more details on here
  • Description: [2021-03-12T03:05:31.388Z] Archiving artifacts script returned exit code 1
Test & coverage
  • Took 15 min 28 sec . View more details on here
  • Description: .ci/windows/test.bat
Archive the artifacts
  • Took 0 min 0 sec . View more details on here
  • Description: [2021-03-12T02:53:29.472Z] Archiving artifacts script returned exit code 1

Log output

Expand to view the last 100 lines of log output

[2021-03-12T03:23:08.119Z]     + ./target/119551ff-cccd-4f8b-8dc1-f9ef0db22aef/119551ff-cccd-4f8b-8dc1-f9ef0db22aef-coverage.cobertura.xml bytes=1511504
[2021-03-12T03:23:08.119Z]     + ./target/5d9e8785-467e-40c0-8cfb-cbc3cafa560b/5d9e8785-467e-40c0-8cfb-cbc3cafa560b-coverage.cobertura.xml bytes=1508258
[2021-03-12T03:23:08.119Z]     + ./target/3ea9aabf-d83b-4db5-9789-642e7079eeba/3ea9aabf-d83b-4db5-9789-642e7079eeba-coverage.cobertura.xml bytes=1479850
[2021-03-12T03:23:08.119Z]     + ./target/f6e86984-9483-41f4-9726-b355cf080452/f6e86984-9483-41f4-9726-b355cf080452-coverage.cobertura.xml bytes=1508887
[2021-03-12T03:23:08.119Z]     + ./target/b362a155-8b6d-485c-8161-897b268f0687/b362a155-8b6d-485c-8161-897b268f0687-coverage.cobertura.xml bytes=1702524
[2021-03-12T03:23:08.119Z]     + ./target/e216fb26-2926-4f1f-bb9b-d6d58c957bce/e216fb26-2926-4f1f-bb9b-d6d58c957bce-coverage.cobertura.xml bytes=1438208
[2021-03-12T03:23:08.119Z]     + ./target/f30d8baa-e489-4be4-91c2-5c1d797c6377/f30d8baa-e489-4be4-91c2-5c1d797c6377-coverage.cobertura.xml bytes=1450487
[2021-03-12T03:23:08.120Z]     + ./target/11760637-5797-4e90-a152-30bfe5582eda/11760637-5797-4e90-a152-30bfe5582eda-coverage.cobertura.xml bytes=1530470
[2021-03-12T03:23:08.120Z]     + ./target/aec4460b-14cc-438e-85f3-9f146cbe381a/aec4460b-14cc-438e-85f3-9f146cbe381a-coverage.cobertura.xml bytes=1422958
[2021-03-12T03:23:08.120Z]     + ./target/cb537dfb-7b7f-4d4c-ba47-d65c6fae463a/cb537dfb-7b7f-4d4c-ba47-d65c6fae463a-coverage.cobertura.xml bytes=1774521
[2021-03-12T03:23:08.120Z]     + ./target/4a55f545-c117-4735-9fda-e5f2df21748e/4a55f545-c117-4735-9fda-e5f2df21748e-coverage.cobertura.xml bytes=1684365
[2021-03-12T03:23:08.120Z]     + ./target/5be8d087-3751-4b9d-9733-c377bbc747ef/5be8d087-3751-4b9d-9733-c377bbc747ef-coverage.cobertura.xml bytes=1438078
[2021-03-12T03:23:08.120Z]     + ./target/fc2a8211-9dc0-410a-b9de-32fcb28f56c1/fc2a8211-9dc0-410a-b9de-32fcb28f56c1-coverage.cobertura.xml bytes=1702446
[2021-03-12T03:23:08.120Z]     + ./target/d5003fcd-ffa5-4c5f-a86e-f48d8ae5cbfc/d5003fcd-ffa5-4c5f-a86e-f48d8ae5cbfc-coverage.cobertura.xml bytes=1684334
[2021-03-12T03:23:08.120Z]     + ./target/b20c9750-0e76-4aa0-8f77-3c06d06683fc/b20c9750-0e76-4aa0-8f77-3c06d06683fc-coverage.cobertura.xml bytes=1511560
[2021-03-12T03:23:08.120Z]     + ./target/53699696-d062-48ab-be00-57518b86d14a/53699696-d062-48ab-be00-57518b86d14a-coverage.cobertura.xml bytes=1684401
[2021-03-12T03:23:08.121Z]     + ./target/ebeb5c19-e1db-43fd-ba42-f584232d734d/ebeb5c19-e1db-43fd-ba42-f584232d734d-coverage.cobertura.xml bytes=1562264
[2021-03-12T03:23:08.121Z]     + ./target/28042ede-62e1-4673-9b80-db097b4bd696/28042ede-62e1-4673-9b80-db097b4bd696-coverage.cobertura.xml bytes=1773911
[2021-03-12T03:23:08.383Z]     + ./target/aad45ad3-b17e-4770-b48d-53a9e23839e5/aad45ad3-b17e-4770-b48d-53a9e23839e5-coverage.cobertura.xml bytes=1479888
[2021-03-12T03:23:08.383Z]     + ./target/0ad1c836-c630-420f-b810-430c438c18ff/0ad1c836-c630-420f-b810-430c438c18ff-coverage.cobertura.xml bytes=1438071
[2021-03-12T03:23:08.383Z]     + ./target/385f9d78-e640-490f-a071-1f375f96bc08/385f9d78-e640-490f-a071-1f375f96bc08-coverage.cobertura.xml bytes=1684365
[2021-03-12T03:23:08.383Z]     + ./target/a087fcb4-6c27-4721-9b05-a203a3e21997/a087fcb4-6c27-4721-9b05-a203a3e21997-coverage.cobertura.xml bytes=1530957
[2021-03-12T03:23:08.384Z]     + ./.nuget/packages/microsoft.codecoverage/16.8.3/microsoft.codecoverage.16.8.3.nupkg bytes=2859149
[2021-03-12T03:23:08.384Z]     + ./.nuget/packages/microsoft.codecoverage/16.8.3/microsoft.codecoverage.nuspec bytes=972
[2021-03-12T03:23:08.384Z]     + ./.nuget/packages/microsoft.codecoverage/16.8.3/microsoft.codecoverage.16.8.3.nupkg.sha512 bytes=88
[2021-03-12T03:23:08.384Z]     + ./.nuget/packages/microsoft.codecoverage/16.8.3/build/netstandard1.0/CodeCoverage/codecoveragemessages.dll bytes=35208
[2021-03-12T03:23:08.384Z] ==> Appending adjustments
[2021-03-12T03:23:08.384Z]     https://docs.codecov.io/docs/fixing-reports
[2021-03-12T03:23:08.955Z]     + Found adjustments
[2021-03-12T03:23:08.956Z] ==> Gzipping contents
[2021-03-12T03:23:11.499Z]         7.9M	/tmp/codecov.WcmkY9.gz
[2021-03-12T03:23:11.499Z] ==> Uploading reports
[2021-03-12T03:23:11.500Z]     url: https://codecov.io
[2021-03-12T03:23:11.500Z]     query: branch=gregkalapos%2FStartupHookLoadContext&commit=d8a051be9fb57b67554464bff108d85a40af7332&build=8&build_url=https%3A%2F%2Fapm-ci.elastic.co%2Fjob%2Fapm-agent-dotnet%2Fjob%2Fapm-agent-dotnet-mbp%2Fjob%2FPR-1169%2F8%2F&name=&tag=&slug=elastic%2Fapm-agent-dotnet&service=jenkins&flags=&pr=1169&job=&cmd_args=
[2021-03-12T03:23:11.500Z] ->  Pinging Codecov
[2021-03-12T03:23:11.500Z] https://codecov.io/upload/v4?package=bash-20210309-2b87ace&token=secret&branch=gregkalapos%2FStartupHookLoadContext&commit=d8a051be9fb57b67554464bff108d85a40af7332&build=8&build_url=https%3A%2F%2Fapm-ci.elastic.co%2Fjob%2Fapm-agent-dotnet%2Fjob%2Fapm-agent-dotnet-mbp%2Fjob%2FPR-1169%2F8%2F&name=&tag=&slug=elastic%2Fapm-agent-dotnet&service=jenkins&flags=&pr=1169&job=&cmd_args=
[2021-03-12T03:23:11.500Z] ->  Uploading to
[2021-03-12T03:23:11.500Z] https://storage.googleapis.com/codecov/v4/raw/2021-03-12/DB094A53A8E3E06DBBF05BB7869242D5/d8a051be9fb57b67554464bff108d85a40af7332/595ba961-50e8-455f-959c-f73b6ae57afe.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=GOOG1EQX6OZVJGHKK3633AAFGLBUCOOATRACRQRQF6HMSMLYUP6EAD6XSWAAY%2F20210312%2FUS%2Fs3%2Faws4_request&X-Amz-Date=20210312T032311Z&X-Amz-Expires=10&X-Amz-SignedHeaders=host&X-Amz-Signature=6a62f57e92bb878ce522af0aa3af06cb2c128cae6de025a01f0b347cb33a3d8a
[2021-03-12T03:23:11.500Z]   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
[2021-03-12T03:23:11.500Z]                                  Dload  Upload   Total   Spent    Left  Speed
[2021-03-12T03:23:11.500Z] 
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 8056k    0     0  100 8056k      0  34.8M --:--:-- --:--:-- --:--:-- 34.8M
[2021-03-12T03:23:11.500Z]     -> Reports have been successfully queued for processing at https://codecov.io/github/elastic/apm-agent-dotnet/commit/d8a051be9fb57b67554464bff108d85a40af7332
[2021-03-12T03:23:11.631Z] Archiving artifacts
[2021-03-12T03:23:11.724Z] java.lang.InterruptedException: no matches found within 10000
[2021-03-12T03:23:11.724Z] 	at hudson.FilePath$ValidateAntFileMask.hasMatch(FilePath.java:3067)
[2021-03-12T03:23:11.724Z] 	at hudson.FilePath$ValidateAntFileMask.invoke(FilePath.java:2976)
[2021-03-12T03:23:11.724Z] 	at hudson.FilePath$ValidateAntFileMask.invoke(FilePath.java:2927)
[2021-03-12T03:23:11.724Z] 	at hudson.FilePath$FileCallableWrapper.call(FilePath.java:3314)
[2021-03-12T03:23:11.724Z] Also:   hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from apm-ci-immutable-ubuntu-1804-1615515639913431845.c.elastic-ci-prod.internal/10.224.1.255:60578
[2021-03-12T03:23:11.724Z] 		at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1800)
[2021-03-12T03:23:11.724Z] 		at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356)
[2021-03-12T03:23:11.724Z] 		at hudson.remoting.Channel.call(Channel.java:1001)
[2021-03-12T03:23:11.724Z] 		at hudson.FilePath.act(FilePath.java:1158)
[2021-03-12T03:23:11.724Z] 		at hudson.FilePath.act(FilePath.java:1147)
[2021-03-12T03:23:11.724Z] 		at hudson.FilePath.validateAntFileMask(FilePath.java:2925)
[2021-03-12T03:23:11.724Z] 		at hudson.tasks.ArtifactArchiver.perform(ArtifactArchiver.java:270)
[2021-03-12T03:23:11.724Z] 		at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:99)
[2021-03-12T03:23:11.724Z] 		at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:69)
[2021-03-12T03:23:11.724Z] 		at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
[2021-03-12T03:23:11.724Z] 		at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[2021-03-12T03:23:11.724Z] 		at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[2021-03-12T03:23:11.724Z] 		at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[2021-03-12T03:23:11.724Z] 		at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[2021-03-12T03:23:11.724Z] Caused: hudson.FilePath$TunneledInterruptedException
[2021-03-12T03:23:11.724Z] 	at hudson.FilePath$FileCallableWrapper.call(FilePath.java:3316)
[2021-03-12T03:23:11.724Z] 	at hudson.remoting.UserRequest.perform(UserRequest.java:211)
[2021-03-12T03:23:11.724Z] 	at hudson.remoting.UserRequest.perform(UserRequest.java:54)
[2021-03-12T03:23:11.724Z] 	at hudson.remoting.Request$2.run(Request.java:375)
[2021-03-12T03:23:11.724Z] 	at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:73)
[2021-03-12T03:23:11.724Z] 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[2021-03-12T03:23:11.724Z] 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[2021-03-12T03:23:11.724Z] 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[2021-03-12T03:23:11.724Z] 	at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:118)
[2021-03-12T03:23:11.724Z] Caused: java.lang.InterruptedException: java.lang.InterruptedException: no matches found within 10000
[2021-03-12T03:23:11.724Z] 	at hudson.FilePath.act(FilePath.java:1160)
[2021-03-12T03:23:11.725Z] 	at hudson.FilePath.act(FilePath.java:1147)
[2021-03-12T03:23:11.725Z] 	at hudson.FilePath.validateAntFileMask(FilePath.java:2925)
[2021-03-12T03:23:11.725Z] 	at hudson.tasks.ArtifactArchiver.perform(ArtifactArchiver.java:270)
[2021-03-12T03:23:11.725Z] 	at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:99)
[2021-03-12T03:23:11.725Z] 	at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:69)
[2021-03-12T03:23:11.725Z] 	at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
[2021-03-12T03:23:11.725Z] 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[2021-03-12T03:23:11.725Z] 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[2021-03-12T03:23:11.725Z] 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[2021-03-12T03:23:11.725Z] 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[2021-03-12T03:23:11.725Z] 	at java.lang.Thread.run(Thread.java:748)
[2021-03-12T03:23:11.725Z] No artifacts found that match the file pattern "/var/lib/jenkins/workspace/net_apm-agent-dotnet-mbp_PR-1169/**/MSBuild_*.failure.txt". Configuration error?
[2021-03-12T03:23:11.939Z] Stage "Release to feedz.io" skipped due to earlier failure(s)
[2021-03-12T03:23:11.995Z] Stage "Release" skipped due to earlier failure(s)
[2021-03-12T03:23:12.018Z] Stage "Release" skipped due to earlier failure(s)
[2021-03-12T03:23:12.068Z] Stage "Release" skipped due to earlier failure(s)
[2021-03-12T03:23:12.158Z] Stage "AfterRelease" skipped due to earlier failure(s)
[2021-03-12T03:23:12.183Z] Stage "AfterRelease" skipped due to earlier failure(s)
[2021-03-12T03:23:12.600Z] Running on worker-854309 in /var/lib/jenkins/workspace/net_apm-agent-dotnet-mbp_PR-1169
[2021-03-12T03:23:12.677Z] [INFO] getVaultSecret: Getting secrets
[2021-03-12T03:23:12.863Z] Masking supported pattern matches of $VAULT_ADDR or $VAULT_ROLE_ID or $VAULT_SECRET_ID
[2021-03-12T03:23:14.989Z] + chmod 755 generate-build-data.sh
[2021-03-12T03:23:14.989Z] + ./generate-build-data.sh https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-dotnet/apm-agent-dotnet-mbp/PR-1169/ https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-dotnet/apm-agent-dotnet-mbp/PR-1169/runs/8 FAILURE 3772886
[2021-03-12T03:23:14.989Z] INFO: curl https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-dotnet/apm-agent-dotnet-mbp/PR-1169/runs/8/steps/?limit=10000 -o steps-info.json
[2021-03-12T03:23:18.139Z] INFO: curl https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-dotnet/apm-agent-dotnet-mbp/PR-1169/runs/8/tests/?status=FAILED -o tests-errors.json

@russcam russcam added bug Something isn't working v1.8.0 labels Feb 11, 2021
@russcam
Copy link
Contributor

russcam commented Feb 15, 2021

@gregkalapos did you want to rebase this against master, to pick up the startup hook tests merged in #1167?

"Elastic.Apm.GrpcClient", "Elastic.Apm.Elasticsearch"
};

private readonly string _asssemblyDir;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private readonly string _asssemblyDir;
private readonly string _assemblyDir;

}
catch (Exception e)
{
_logger.WriteLine($"{nameof(AgentLoadContext)} Failed loading {assemblyName.Name}, exception: {e}");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
_logger.WriteLine($"{nameof(AgentLoadContext)} Failed loading {assemblyName.Name}, exception: {e}");
_logger.WriteLine($"{nameof(AgentLoadContext)} Failed loading {assemblyName}, exception: {e}");

AssemblyName overrides ToString() to return the FullName, so we could use assemblyName here

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
Copy link
Contributor

Choose a reason for hiding this comment

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

does this need to be bumped to netcoreapp3.1, or should it stay at netcoreapp2.2? In other places, we've been dropping netcoreapp2.2 since it is EOL'ed, so I'm not against doing so here too, though there would be some housekeeping to do so, such as, removing mentions of netcoreapp2.2 / ASP,NET Core 2.2 in the startup hooks docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally I used an API which was only present in 3.1, but it turned out to be not needed. I can revert this. So, given there is no change needed here, I'd say let's keep it as it is. The next push will change it back to 2.2..

AssemblyLoadContext.Default.Resolving += (context, assemblyName) =>
{
if (AgentLoadContext.AgentDependencyLibsToLoad.Contains(assemblyName.Name)
|| AgentLoadContext.AgentLibsToLoad.Contains(assemblyName.Name))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we make both AgentDependencyLibsToLoad and AgentLibsToLoad to be HashSet<string> for this op?

{
if (AppDomain.CurrentDomain.GetAssemblies().Any(n => n.FullName.Equals(assemblyName, StringComparison.Ordinal)))
{
Logger.WriteLine($"{assemblyName} is alrady loaded - we don't try to load it");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Logger.WriteLine($"{assemblyName} is alrady loaded - we don't try to load it");
Logger.WriteLine($"{assemblyName} is already loaded");

@gregkalapos
Copy link
Contributor Author

This is still work in progress. I'm still working on some cases where the fix does not help.

@russcam russcam added v1.9.0 and removed v1.8.0 labels Feb 16, 2021
@gregkalapos
Copy link
Contributor Author

I gave up on this - loading the agent into a separate AssemblyLoadContext has issues with diagnostic source, since it depends on a static instance.

I opened #1227 to solve the Newtonsoft.Json issue by using assembly-rewriter instead of relying on AssemblyLoadContext.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-dotnet bug Something isn't working v1.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants