apache / hertzbeat

Apache HertzBeat(incubating) is a real-time monitoring system with agentless, performance cluster, prometheus-compatible, custom monitoring and status page building capabilities.
https://hertzbeat.apache.org/
Apache License 2.0
5.79k stars 1.01k forks source link

[Task] <upgrade springboot3 and build native image > #1200

Open tomsun28 opened 1 year ago

tomsun28 commented 1 year ago

Description

We want to compile and build hertzbeat Java code into binary files (native executables) without jvm runtime.

https://www.graalvm.org/downloads/ https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-with-GraalVM

Task List

zqr10159 commented 1 year ago

@tomsun28 麻烦看一下springboot3分支,sureness报错,这个我不太懂,另:h2会报错,使用mysql新数据库无问题 jwt

1203

hertzbeat commented 1 year ago

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@tomsun28 Please take a look at the springboot3 branch, sureness reports an error, I don’t understand this, and another: h2 will report an error, there is no problem using the new mysql database jwt

tomsun28 commented 1 year ago

have fixed sureness h2 bug todo build native images

leo-934 commented 1 year ago

have fixed sureness h2 bug todo build native images

I would like to try this part.

leo-934 commented 1 year ago
➜  hertzbeat git:(springboot3) ✗ native-image -jar manager/target/hertzbeat.jar
========================================================================================================================
GraalVM Native Image: Generating 'hertzbeat' (executable)...
========================================================================================================================
[1/7] Initializing...                                                                                   (12.0s @ 0.11GB)
 Version info: 'GraalVM 22.3.3 Java 17 CE'
 Java version info: '17.0.8+7-jvmci-22.3-b22'
 C compiler: cc (apple, x86_64, 14.0.3)
 Garbage collector: Serial GC
[2/7] Performing analysis...  [******]                                                                  (31.0s @ 0.50GB)
   3,572 (77.05%) of  4,636 classes reachable
   4,481 (52.67%) of  8,507 fields reachable
  16,055 (45.95%) of 34,942 methods reachable
     159 classes,     0 fields, and   537 methods registered for reflection
      59 classes,    60 fields, and    52 methods registered for JNI access
       4 native libraries: -framework Foundation, dl, pthread, z
[3/7] Building universe...                                                                               (2.9s @ 1.08GB)

Warning: Reflection method java.lang.Class.forName invoked at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:46)
Warning: Reflection method java.lang.Class.getDeclaredMethod invoked at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:47)
Warning: Reflection method java.lang.Class.getDeclaredConstructor invoked at org.springframework.boot.loader.jar.Handler.getFallbackHandler(Handler.java:200)
Warning: Aborting stand-alone image build due to reflection use without configuration.
Warning: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
------------------------------------------------------------------------------------------------------------------------
                        0.5s (1.1% of total time) in 17 GCs | Peak RSS: 2.10GB | CPU load: 2.52
========================================================================================================================
Failed generating 'hertzbeat' after 46.5s.
Generating fallback image...

errors due to reflections use without configuration.

leo-934 commented 1 year ago

java -agentlib:native-image-agent=config-output-dir=path -jar pathofjar 这条命令可以生成一些反射的配置文件,帮助graalvm和native-image解决反射的问题,但是我没有成功,native-image命令显示找不到。

hertzbeat commented 1 year ago

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


java -agentlib:native-image-agent=config-output-dir=path -jar pathofjar This command can generate some reflection configuration files to help graalvm and native-image solve reflection problems, but I did not succeed. The native-image command showed that it could not be found.

leo-934 commented 1 year ago

如果直接放在jar包里,是可以找到的,但是native-image还是有一些classpath的报错,比如他显示无法找到netty之类的依赖包。

➜  hertzbeat git:(springboot3) ✗ native-image -jar manager/target/hertzbeat.jar
========================================================================================================================
GraalVM Native Image: Generating 'hertzbeat' (executable)...
========================================================================================================================
Warning: Could not resolve [Lio.netty.resolver.dns.macos.DnsResolver; for reflection configuration. Reason: java.lang.ClassNotFoundException: io.netty.resolver.dns.macos.DnsResolver.
Warning: Could not resolve io.netty.channel.ChannelException for reflection configuration. Reason: java.lang.ClassNotFoundException: io.netty.channel.ChannelException.
Warning: Could not resolve io.netty.channel.DefaultFileRegion for reflection configuration. Reason: java.lang.ClassNotFoundException: io.netty.channel.DefaultFileRegion.
Warning: Could not resolve io.netty.channel.kqueue.BsdSocket for reflection configuration. Reason: java.lang.ClassNotFoundException: io.netty.channel.kqueue.BsdSocket.
Warning: Could not resolve io.netty.channel.kqueue.KQueueEventArray for reflection configuration. Reason: java.lang.ClassNotFoundException: io.netty.channel.kqueue.KQueueEventArray.
Warning: Could not resolve io.netty.channel.kqueue.KQueueStaticallyReferencedJniMethods for reflection configuration. Reason: java.lang.ClassNotFoundException: io.netty.channel.kqueue.KQueueStaticallyReferencedJniMethods.
Warning: Could not resolve io.netty.channel.kqueue.Native for reflection configuration. Reason: java.lang.ClassNotFoundException: io.netty.channel.kqueue.Native.
Warning: Could not resolve io.netty.channel.unix.Buffer for reflection configuration. Reason: java.lang.ClassNotFoundException: io.netty.channel.unix.Buffer.
Warning: Could not resolve io.netty.channel.unix.DatagramSocketAddress for reflection configuration. Reason: java.lang.ClassNotFoundException: io.netty.channel.unix.DatagramSocketAddress.
Warning: Could not resolve io.netty.channel.unix.DomainDatagramSocketAddress for reflection configuration. Reason: java.lang.ClassNotFoundException: io.netty.channel.unix.DomainDatagramSocketAddress.
Warning: Could not resolve io.netty.channel.unix.ErrorsStaticallyReferencedJniMethods for reflection configuration. Reason: java.lang.ClassNotFoundException: io.netty.channel.unix.ErrorsStaticallyReferencedJniMethods.
Warning: Could not resolve io.netty.channel.unix.FileDescriptor for reflection configuration. Reason: java.lang.ClassNotFoundException: io.netty.channel.unix.FileDescriptor.
Warning: Could not resolve io.netty.channel.unix.LimitsStaticallyReferencedJniMethods for reflection configuration. Reason: java.lang.ClassNotFoundException: io.netty.channel.unix.LimitsStaticallyReferencedJniMethods.
tomsun28 commented 1 year ago
Error: Classes that should be initialized at run time got initialized during image building:
 io.netty.util.AbstractReferenceCounted the class was requested to be initialized at run time (from 'META-INF/native-image/io.netty/netty-common/native-image.properties' in 'file:///Users/tom/.m2/repository/io/netty/netty-common/4.1.100.Final/netty-common-4.1.100.Final.jar' with 'io.netty.util.AbstractReferenceCounted'). To see why io.netty.util.AbstractReferenceCounted got initialized use --trace-class-initialization=io.netty.util.AbstractReferenceCounted
io.netty.buffer.UnpooledDirectByteBuf the class was requested to be initialized at run time (subtype of io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.netty.buffer.UnpooledDirectByteBuf got initialized use --trace-class-initialization=io.netty.buffer.UnpooledDirectByteBuf
io.grpc.netty.shaded.io.netty.util.internal.logging.Log4J2Logger the class was requested to be initialized at run time (from 'META-INF/native-image/io.grpc.netty.shaded.io.netty/codec-http/native-image.properties' in 'file:///Users/tom/.m2/repository/io/grpc/grpc-netty-shaded/1.49.1/grpc-netty-shaded-1.49.1.jar' with 'io.grpc.netty.shaded.io.netty' and from 'META-INF/native-image/io.grpc.netty.shaded.io.netty/codec-http2/native-image.properties' in 'file:///Users/tom/.m2/repository/io/grpc/grpc-netty-shaded/1.49.1/grpc-netty-shaded-1.49.1.jar' with 'io.grpc.netty.shaded.io.netty'). To see why io.grpc.netty.shaded.io.netty.util.internal.logging.Log4J2Logger got initialized use --trace-class-initialization=io.grpc.netty.shaded.io.netty.util.internal.logging.Log4J2Logger
org.apache.logging.log4j.util.Constants was unintentionally initialized at build time. To see why org.apache.logging.log4j.util.Constants got initialized use --trace-class-initialization=org.apache.logging.log4j.util.Constants
------------------------------------------------------------------------------------------------------------------------
io.netty.buffer.ByteBufAllocator the class was requested to be initialized at run time (from 'META-INF/native-image/io.netty/netty-buffer/native-image.properties' in 'file:///Users/tom/.m2/repository/io/netty/netty-buffer/4.1.100.Final/netty-buffer-4.1.100.Final.jar' with 'io.netty.buffer.ByteBufAllocator'). To see why io.netty.buffer.ByteBufAllocator got initialized use --trace-class-initialization=io.netty.buffer.ByteBufAllocator
io.netty.buffer.PooledUnsafeDirectByteBuf the class was requested to be initialized at run time (subtype of io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.netty.buffer.PooledUnsafeDirectByteBuf got initialized use --trace-class-initialization=io.netty.buffer.PooledUnsafeDirectByteBuf
org.apache.logging.log4j.simple.SimpleLogger was unintentionally initialized at build time. To see why org.apache.logging.log4j.simple.SimpleLogger got initialized use --trace-class-initialization=org.apache.logging.log4j.simple.SimpleLogger
io.netty.buffer.AbstractReferenceCountedByteBuf the class was requested to be initialized at run time (from 'META-INF/native-image/io.netty/netty-buffer/native-image.properties' in 'file:///Users/tom/.m2/repository/io/netty/netty-buffer/4.1.100.Final/netty-buffer-4.1.100.Final.jar' with 'io.netty.buffer.AbstractReferenceCountedByteBuf'). To see why io.netty.buffer.AbstractReferenceCountedByteBuf got initialized use --trace-class-initialization=io.netty.buffer.AbstractReferenceCountedByteBuf
org.apache.logging.slf4j.SLF4JLoggerContextFactory was unintentionally initialized at build time. To see why org.apache.logging.slf4j.SLF4JLoggerContextFactory got initialized use --trace-class-initialization=org.apache.logging.slf4j.SLF4JLoggerContextFactory
io.netty.buffer.ByteBufUtil the class was requested to be initialized at run time (from 'META-INF/native-image/io.netty/netty-buffer/native-image.properties' in 'file:///Users/tom/.m2/repository/io/netty/netty-buffer/4.1.100.Final/netty-buffer-4.1.100.Final.jar' with 'io.netty.buffer.ByteBufUtil'). To see why io.netty.buffer.ByteBufUtil got initialized use --trace-class-initialization=io.netty.buffer.ByteBufUtil
io.netty.buffer.UnpooledHeapByteBuf the class was requested to be initialized at run time (subtype of io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.netty.buffer.UnpooledHeapByteBuf got initialized use --trace-class-initialization=io.netty.buffer.UnpooledHeapByteBuf
org.apache.logging.log4j.util.ProviderUtil was unintentionally initialized at build time. To see why org.apache.logging.log4j.util.ProviderUtil got initialized use --trace-class-initialization=org.apache.logging.log4j.util.ProviderUtil
org.apache.logging.log4j.spi.AbstractLogger was unintentionally initialized at build time. To see why org.apache.logging.log4j.spi.AbstractLogger got initialized use --trace-class-initialization=org.apache.logging.log4j.spi.AbstractLogger
org.apache.logging.log4j.util.PropertiesUtil was unintentionally initialized at build time. To see why org.apache.logging.log4j.util.PropertiesUtil got initialized use --trace-class-initialization=org.apache.logging.log4j.util.PropertiesUtil
io.netty.buffer.AbstractPooledDerivedByteBuf the class was requested to be initialized at run time (subtype of io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.netty.buffer.AbstractPooledDerivedByteBuf got initialized use --trace-class-initialization=io.netty.buffer.AbstractPooledDerivedByteBuf
io.netty.buffer.UnpooledUnsafeDirectByteBuf the class was requested to be initialized at run time (subtype of io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.netty.buffer.UnpooledUnsafeDirectByteBuf got initialized use --trace-class-initialization=io.netty.buffer.UnpooledUnsafeDirectByteBuf
io.netty.buffer.PooledByteBufAllocator the class was requested to be initialized at run time (from 'META-INF/native-image/io.netty/netty-buffer/native-image.properties' in 'file:///Users/tom/.m2/repository/io/netty/netty-buffer/4.1.100.Final/netty-buffer-4.1.100.Final.jar' with 'io.netty.buffer.PooledByteBufAllocator'). To see why io.netty.buffer.PooledByteBufAllocator got initialized use --trace-class-initialization=io.netty.buffer.PooledByteBufAllocator
io.netty.handler.ssl.PemPrivateKey the class was requested to be initialized at run time (subtype of io.netty.util.AbstractReferenceCounted). To see why io.netty.handler.ssl.PemPrivateKey got initialized use --trace-class-initialization=io.netty.handler.ssl.PemPrivateKey
io.netty.channel.DefaultFileRegion the class was requested to be initialized at run time (subtype of io.netty.util.AbstractReferenceCounted). To see why io.netty.channel.DefaultFileRegion got initialized use --trace-class-initialization=io.netty.channel.DefaultFileRegion
io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeDirectByteBuf the class was requested to be initialized at run time (subtype of io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeDirectByteBuf got initialized use --trace-class-initialization=io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeDirectByteBuf
org.apache.logging.log4j.spi.StandardLevel was unintentionally initialized at build time. To see why org.apache.logging.log4j.spi.StandardLevel got initialized use --trace-class-initialization=org.apache.logging.log4j.spi.StandardLevel
org.apache.logging.log4j.util.Strings was unintentionally initialized at build time. To see why org.apache.logging.log4j.util.Strings got initialized use --trace-class-initialization=org.apache.logging.log4j.util.Strings
org.apache.logging.log4j.spi.Provider was unintentionally initialized at build time. To see why org.apache.logging.log4j.spi.Provider got initialized use --trace-class-initialization=org.apache.logging.log4j.spi.Provider
io.netty.buffer.PooledSlicedByteBuf the class was requested to be initialized at run time (subtype of io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.netty.buffer.PooledSlicedByteBuf got initialized use --trace-class-initialization=io.netty.buffer.PooledSlicedByteBuf
io.netty.handler.ssl.PemValue the class was requested to be initialized at run time (subtype of io.netty.util.AbstractReferenceCounted). To see why io.netty.handler.ssl.PemValue got initialized use --trace-class-initialization=io.netty.handler.ssl.PemValue
org.apache.logging.log4j.status.StatusLogger was unintentionally initialized at build time. To see why org.apache.logging.log4j.status.StatusLogger got initialized use --trace-class-initialization=org.apache.logging.log4j.status.StatusLogger
io.netty.util.internal.logging.Log4J2Logger the class was requested to be initialized at run time (from 'META-INF/native-image/io.netty/netty-codec-http/native-image.properties' in 'file:///Users/tom/.m2/repository/io/netty/netty-codec-http/4.1.100.Final/netty-codec-http-4.1.100.Final.jar' with 'io.netty' and from 'META-INF/native-image/io.netty/netty-codec-http2/native-image.properties' in 'file:///Users/tom/.m2/repository/io/netty/netty-codec-http2/4.1.100.Final/netty-codec-http2-4.1.100.Final.jar' with 'io.netty'). To see why io.netty.util.internal.logging.Log4J2Logger got initialized use --trace-class-initialization=io.netty.util.internal.logging.Log4J2Logger
org.apache.logging.log4j.util.OsgiServiceLocator was unintentionally initialized at build time. To see why org.apache.logging.log4j.util.OsgiServiceLocator got initialized use --trace-class-initialization=org.apache.logging.log4j.util.OsgiServiceLocator
org.apache.logging.log4j.Level was unintentionally initialized at build time. To see why org.apache.logging.log4j.Level got initialized use --trace-class-initialization=org.apache.logging.log4j.Level
org.apache.logging.log4j.util.LoaderUtil was unintentionally initialized at build time. To see why org.apache.logging.log4j.util.LoaderUtil got initialized use --trace-class-initialization=org.apache.logging.log4j.util.LoaderUtil
org.slf4j.LoggerFactory was unintentionally initialized at build time. To see why org.slf4j.LoggerFactory got initialized use --trace-class-initialization=org.slf4j.LoggerFactory
io.netty.buffer.PooledByteBuf the class was requested to be initialized at run time (subtype of io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.netty.buffer.PooledByteBuf got initialized use --trace-class-initialization=io.netty.buffer.PooledByteBuf
org.apache.logging.log4j.util.PropertySource$Util was unintentionally initialized at build time. To see why org.apache.logging.log4j.util.PropertySource$Util got initialized use --trace-class-initialization=org.apache.logging.log4j.util.PropertySource$Util
org.apache.logging.log4j.spi.ExtendedLoggerWrapper was unintentionally initialized at build time. To see why org.apache.logging.log4j.spi.ExtendedLoggerWrapper got initialized use --trace-class-initialization=org.apache.logging.log4j.spi.ExtendedLoggerWrapper
To see how the classes got initialized, use --trace-class-initialization=io.netty.util.AbstractReferenceCounted,io.netty.buffer.UnpooledDirectByteBuf,io.grpc.netty.shaded.io.netty.util.internal.logging.Log4J2Logger,org.apache.logging.log4j.util.Constants,io.netty.buffer.ByteBufAllocator,io.netty.buffer.PooledUnsafeDirectByteBuf,org.apache.logging.log4j.simple.SimpleLogger,io.netty.buffer.AbstractReferenceCountedByteBuf,org.apache.logging.slf4j.SLF4JLoggerContextFactory,io.netty.buffer.ByteBufUtil,io.netty.buffer.UnpooledHeapByteBuf,org.apache.logging.log4j.util.ProviderUtil,org.apache.logging.log4j.spi.AbstractLogger,org.apache.logging.log4j.util.PropertiesUtil,io.netty.buffer.AbstractPooledDerivedByteBuf,io.netty.buffer.UnpooledUnsafeDirectByteBuf,io.netty.buffer.PooledByteBufAllocator,io.netty.handler.ssl.PemPrivateKey,io.netty.channel.DefaultFileRegion,io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeDirectByteBuf,org.apache.logging.log4j.spi.StandardLevel,org.apache.logging.log4j.util.Strings,org.apache.logging.log4j.spi.Provider,io.netty.buffer.PooledSlicedByteBuf,io.netty.handler.ssl.PemValue,org.apache.logging.log4j.status.StatusLogger,io.netty.util.internal.logging.Log4J2Logger,org.apache.logging.log4j.util.OsgiServiceLocator,org.apache.logging.log4j.Level,org.apache.logging.log4j.util.LoaderUtil,org.slf4j.LoggerFactory,io.netty.buffer.PooledByteBuf,org.apache.logging.log4j.util.PropertySource$Util,org.apache.logging.log4j.spi.ExtendedLoggerWrapper
Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
                        5.9s (14.9% of total time) in 85 GCs | Peak RSS: 2.30GB | CPU load: 5.15
========================================================================================================================
Finished generating 'hertzbeat-manager' in 38.8s.