报告超出 Sonar 服务器的最大上传大小

Report exceeds maximum upload size of Sonar server

自从升级到Sonarqube 6.0后,我的一个项目一直无法进行分析。

本项目通过maven插件进行声纳分析,失败并出现以下错误:

Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.7.1:sonar (default-cli) on project rating-parent: Error 500 on http://sonar.example.com/api/ce/submit?projectKey=com.example.rating-parent&projectName=Rating%20System&projectBranch=develop

检查服务器上的 sonar.log(通过 AJP 位于 Apache 2.4 服务器后面)揭示了这个堆栈跟踪:

2016.08.12 10:50:14 ERROR web[o.s.s.w.WebServiceEngine] Fail to process request http://sonar.example.com/api/ce/submit?projectKey=com.example.rating:rating-parent&projectName=Rating%20System&projectBranch=develop
java.lang.IllegalStateException: Can't read file part
    at org.sonar.server.ws.ServletRequest.readPart(ServletRequest.java:93) ~[sonar-server-6.0.jar:na]
    at org.sonar.server.ws.ServletRequest.readInputStreamParam(ServletRequest.java:76) ~[sonar-server-6.0.jar:na]
    at org.sonar.api.server.ws.internal.ValidatingRequest.paramAsInputStream(ValidatingRequest.java:74) ~[sonar-plugin-api-6.0.jar:na]
    at org.sonar.server.ce.ws.SubmitAction.handle(SubmitAction.java:84) ~[sonar-server-6.0.jar:na]
    at org.sonar.server.ws.WebServiceEngine.execute(WebServiceEngine.java:109) ~[sonar-server-6.0.jar:na]
    at org.sonar.server.ws.WebServiceFilter.doFilter(WebServiceFilter.java:74) [sonar-server-6.0.jar:na]
    at org.sonar.server.platform.MasterServletFilter$GodFilterChain.doFilter(MasterServletFilter.java:125) [sonar-server-6.0.jar:na]
    at org.sonar.server.platform.MasterServletFilter.doFilter(MasterServletFilter.java:94) [sonar-server-6.0.jar:na]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.sonar.server.user.UserSessionFilter.doFilter(UserSessionFilter.java:56) [sonar-server-6.0.jar:na]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.sonar.server.platform.RoutesFilter.doFilter(RoutesFilter.java:55) [sonar-server-6.0.jar:na]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.sonar.server.platform.ProfilingFilter.doFilter(ProfilingFilter.java:84) [sonar-server-6.0.jar:na]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) [tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) [tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.0.32.jar:8.0.32]
    at ch.qos.logback.access.tomcat.LogbackValve.invoke(LogbackValve.java:191) [logback-access-1.1.3.jar:na]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522) [tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.apache.coyote.ajp.AbstractAjpProcessor.process(AbstractAjpProcessor.java:868) [tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672) [tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) [tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) [tomcat-embed-core-8.0.32.jar:8.0.32]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_91]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_91]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.32.jar:8.0.32]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91]
Caused by: java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (3736099) exceeds the configured maximum (2097152)
    at org.apache.catalina.connector.Request.parseParts(Request.java:2846) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.apache.catalina.connector.Request.parseParameters(Request.java:3151) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.apache.catalina.connector.Request.getParameter(Request.java:1108) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:380) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.sonar.server.ws.ServletRequest.readParam(ServletRequest.java:71) ~[sonar-server-6.0.jar:na]
    at org.sonar.api.server.ws.internal.ValidatingRequest.readParamOrDefaultValue(ValidatingRequest.java:134) ~[sonar-plugin-api-6.0.jar:na]
    at org.sonar.api.server.ws.internal.ValidatingRequest.param(ValidatingRequest.java:86) ~[sonar-plugin-api-6.0.jar:na]
    at org.sonar.api.server.ws.internal.ValidatingRequest.param(ValidatingRequest.java:68) ~[sonar-plugin-api-6.0.jar:na]
    at org.sonar.api.server.ws.Request.mandatoryParam(Request.java:63) ~[sonar-plugin-api-6.0.jar:na]
    at org.sonar.server.ce.ws.SubmitAction.handle(SubmitAction.java:81) ~[sonar-server-6.0.jar:na]
    ... 30 common frames omitted
Caused by: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (3736099) exceeds the configured maximum (2097152)
    at org.apache.tomcat.util.http.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:811) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.apache.tomcat.util.http.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:256) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:280) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
    at org.apache.catalina.connector.Request.parseParts(Request.java:2776) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
    ... 39 common frames omitted

我从中了解到,错误是由于提交给 Sonarqube 服务器的分析报告的大小(大约 3.7 MB)大于嵌入式 Tomcat服务器的上传限制约为 2 MB。

target/sonar/batch-report 中文件的累计大小确实约为 3.7 MB,所以我猜堆栈跟踪是正确的。

我也尝试了我们的一个较小的项目(报告总计约 1,3M)并且它没有问题。

无论我是从我们的 Jenkins 服务器 运行 还是从命令行在本地调用 Maven (3.3.9) 都没有关系。

假设没有办法减小报告大小(3.7 MB 是例外吗?),我可能可以通过增加 Tomcat 的最大上传大小来解决这个问题。我知道如何在常规 Tomcat 安装中执行此操作,但我不知道如何为 Sonarqube 的嵌入式 Tomcat 服务器执行此操作。

这是使用 AJP 连接器时的问题,将在 6.1 中修复:https://jira.sonarsource.com/browse/SONAR-7977