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

[Maven Extension] Maven daemon build fails on second run #164

Closed
delanym opened this issue Jan 4, 2022 · 16 comments
Closed

[Maven Extension] Maven daemon build fails on second run #164

delanym opened this issue Jan 4, 2022 · 16 comments
Labels

Comments

@delanym
Copy link

delanym commented Jan 4, 2022

Reproduce as in #160 but use mvnd instead of mvn
https://github.com/apache/maven-mvnd/releases/tag/0.7.1

mvnd validate -Dotel.traces.exporter=otlp -Dotel.exporter.otlp.endpoint=http://10.1.1.1:4317 -Dmaven.ext.class.path=/tmp/opentelemetry-maven-extension-1.10.0-SNAPSHOT.jar -T3

The first run is successful, but the second fails with:

[INFO] Processing build on daemon e432b3dc
[INFO] Scanning for projects...
[ERROR] Internal error: java.lang.IllegalStateException: Root span already defined RecordEventsReadableSpan{traceId=ab428d41352f1a99385654f781e68ffc, spanId=fe206e623f88a74d, parentSpanContext=ImmutableSpanContext{traceId=00000000000000000000000000000000, spanId=0000000000000000, traceFlags=00, traceState=ArrayBasedTraceState{entries=[]}, remote=false, valid=false}, name=Build: org.apache.maven:maven:4.0.0-alpha-1-SNAPSHOT, kind=SERVER, attributes=AttributesMap{data={maven.project.version=4.0.0-alpha-1-SNAPSHOT, maven.project.groupId=org.apache.maven, maven.project.artifactId=maven}, capacity=128, totalAddedValues=3}, status=ImmutableStatusData{statusCode=UNSET, description=}, totalRecordedEvents=0, totalRecordedLinks=0, startEpochNanos=1641289758683000000, endEpochNanos=1641289762712689563} -> [Help 1]
org.apache.maven.InternalErrorException: Internal error: java.lang.IllegalStateException: Root span already defined RecordEventsReadableSpan{traceId=ab428d41352f1a99385654f781e68ffc, spanId=fe206e623f88a74d, parentSpanContext=ImmutableSpanContext{traceId=00000000000000000000000000000000, spanId=0000000000000000, traceFlags=00, traceState=ArrayBasedTraceState{entries=[]}, remote=false, valid=false}, name=Build: org.apache.maven:maven:4.0.0-alpha-1-SNAPSHOT, kind=SERVER, attributes=AttributesMap{data={maven.project.version=4.0.0-alpha-1-SNAPSHOT, maven.project.groupId=org.apache.maven, maven.project.artifactId=maven}, capacity=128, totalAddedValues=3}, status=ImmutableStatusData{statusCode=UNSET, description=}, totalRecordedEvents=0, totalRecordedLinks=0, startEpochNanos=1641289758683000000, endEpochNanos=1641289762712689563}
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:120)
        at org.apache.maven.cli.DaemonMavenCli.execute(DaemonMavenCli.java:825)
        at org.apache.maven.cli.DaemonMavenCli.doMain(DaemonMavenCli.java:244)
        at org.apache.maven.cli.DaemonMavenCli.main(DaemonMavenCli.java:222)
        at org.mvndaemon.mvnd.daemon.Server.handle(Server.java:573)
        at org.mvndaemon.mvnd.daemon.Server.client(Server.java:262)
        at org.mvndaemon.mvnd.daemon.Server.accept(Server.java:230)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: Root span already defined RecordEventsReadableSpan{traceId=ab428d41352f1a99385654f781e68ffc, spanId=fe206e623f88a74d, parentSpanContext=ImmutableSpanContext{traceId=00000000000000000000000000000000, spanId=0000000000000000, traceFlags=00, traceState=ArrayBasedTraceState{entries=[]}, remote=false, valid=false}, name=Build: org.apache.maven:maven:4.0.0-alpha-1-SNAPSHOT, kind=SERVER, attributes=AttributesMap{data={maven.project.version=4.0.0-alpha-1-SNAPSHOT, maven.project.groupId=org.apache.maven, maven.project.artifactId=maven}, capacity=128, totalAddedValues=3}, status=ImmutableStatusData{statusCode=UNSET, description=}, totalRecordedEvents=0, totalRecordedLinks=0, startEpochNanos=1641289758683000000, endEpochNanos=1641289762712689563}
        at io.opentelemetry.maven.SpanRegistry.setRootSpan(SpanRegistry.java:39)
        at io.opentelemetry.maven.OtelExecutionListener.sessionStarted(OtelExecutionListener.java:139)
        at io.opentelemetry.maven.ChainedExecutionListener.sessionStarted(ChainedExecutionListener.java:36)
        at org.apache.maven.lifecycle.internal.DefaultExecutionEventCatapult.fire(DefaultExecutionEventCatapult.java:61)
        at org.apache.maven.lifecycle.internal.DefaultExecutionEventCatapult.fire(DefaultExecutionEventCatapult.java:42)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:74)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
        ... 7 common frames omitted

Kill the daemon with mvnd --stop and try again and it works.

@delanym delanym added the type: bug Something isn't working label Jan 4, 2022
@gnodet
Copy link

gnodet commented Jan 4, 2022

mvnd caches the plugin realms, so the SpanRegistry is reused across maven sessions.
It may work if you annotate your bean with @SessionScoped or if you fix your component logic.
Another possibility is to force mvnd to discard the realm for the plugin using the mvnd plugin eviction pattern: https://github.com/apache/maven-mvnd/blob/09cb99fd48d7b8b0de09ffb8656b77a1648b4e95/common/src/main/java/org/mvndaemon/mvnd/common/Environment.java#L253-L265

@cyrille-leclerc
Copy link
Member

@delanym
Copy link
Author

delanym commented Jan 5, 2022

@cyrille-leclerc the traces look unusual, but i'm quite new to this. Did you check them? There are spans for some module plugin executions appearing as their own root spans in Jaeger

@cyrille-leclerc
Copy link
Member

@delanym can you please attach a screenshot and indicate how I can reproduce locally? Did you use https://github.com/apache/maven as a test? what was your command line?

@delanym
Copy link
Author

delanym commented Jan 5, 2022

Build with mvnd install .... Then make trivial change like below and build again. You should get a trace like pic

diff --git a/maven-compat/src/main/java/org/apache/maven/repository/VersionNotFoundException.java b/maven-compat/src/main/java/org/apache/maven/repository/VersionNotFoundException.java
index 77b1af127..b70eb2312 100644
--- a/maven-compat/src/main/java/org/apache/maven/repository/VersionNotFoundException.java
+++ b/maven-compat/src/main/java/org/apache/maven/repository/VersionNotFoundException.java
@@ -56,7 +56,7 @@ public VersionNotFoundException( String projectId, Dependency dependency, File p
 
     private static String formatLocationInPom( Dependency dependency )
     {
-        return "Dependency: " + ArtifactUtils.versionlessKey( dependency.getGroupId(), dependency.getArtifactId() );
+        return "dependency: " + ArtifactUtils.versionlessKey( dependency.getGroupId(), dependency.getArtifactId() );
     }
 
     public Dependency getDependency()

image

@cyrille-leclerc
Copy link
Member

@delanym while the build is not finished, it's a known limitation that the root span is missing. Once the build is finished, the root span should be visible.
Could your screenshot have been taken while the build was not finished?

The reason of this missing root span while the build is not finished is that spans are exported by the OpenTelemetry SDK after they are finished and the root span finishes at the end of the build.

Here is the view I get in Jaeger of "mvnd validate" on https//github.com/apache/maven after the build has completed. This view looks correct to me.

image

@delanym
Copy link
Author

delanym commented Jan 6, 2022

Yes that was the case. It looks good then.

@delanym delanym closed this as completed Jan 6, 2022
@delanym delanym reopened this Jan 19, 2022
@delanym
Copy link
Author

delanym commented Jan 19, 2022

@cyrille-leclerc it seems on v1.10.0-alpha its no longer sending a trace

@cyrille-leclerc
Copy link
Member

@delanym strange, it works on my environment with 1.1.10-alpha as you can see the mvnd -X logs: https://gist.github.com/cyrille-leclerc/9cad0babb808b52e6782c82fd13e8063

Could you have forgotten to export OTEL_TRACES_EXPORTER="otlp" in addition to export OTEL_EXPORTER_OTLP_ENDPOINT="..."?

@delanym
Copy link
Author

delanym commented Jan 19, 2022

I had to restart the daemon: mvnd --stop. I shouldn't have to do that though. Gnodet says here about persisting data across invocations. Does the extension do that? Or maybe the issue is with mvnd itself not updating properly from .mvn/extensions.xml

@cyrille-leclerc
Copy link
Member

Do you have a problem of failure or a problem of configuration of the second build being ignored?

@delanym
Copy link
Author

delanym commented Jan 31, 2022

Problem of configuration. Mvnd doesn't pick up the new version of the extension.

@gnodet
Copy link

gnodet commented Jan 31, 2022

Problem of configuration. Mvnd doesn't pick up the new version of the extension.

@delanym Could you try with a mvnd snapshot (you'll have to build it locally...) ? If it isn't fixed by, could you raise an issue on mvnd explaining the exact steps to reproduce the issue ? Please also report the output of mvnd --version.

@cyrille-leclerc
Copy link
Member

@delanym can you please verify this draft issue, I think I understand the cause of your problem:

@gnodet it's likely to be a problem in the extension, I'm investigation with @delanym ^^

@delanym
Copy link
Author

delanym commented Feb 3, 2022

@cyrille-leclerc mvnd is correctly starting another daemon when the extension changes. I do notice that the first time it does this the extension gives a warning:
[WARN] [stderr] javassist.NotFoundException: start(..) is not found in java.lang.ProcessBuilder

I'll look at #220 in the morning

@delanym delanym closed this as completed Feb 9, 2022
@cyrille-leclerc
Copy link
Member

Thanks @delanym for verifying. I suspect javassist.NotFoundException is an mvnd problem rather than an otel maven extension problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants