Which procedure to debug Pull Request Decoration in Gitlab?

Hi Community,

I cannot get to work PR Decoration on my self hosted sonarqube + gitlab, it’s very frustrating because no error at all, but no decoration.

We are using :
Gitlab: 13.1.0
Sonarqube: 8.5.0-developer
maven sonar scanner: 3.7.0.1746

  • In the admin part of sonar the gitlab alm seems well configured
  • The sonar technical account in gitlab have the role developer for the project.
  • we launch the scanner like this :
mvn -B org.jacoco:jacoco-maven-plugin:0.8.5:report org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar '-Dsonar.projectVersion=37' '-Dsonar.pullrequest.key=4910' '-Dsonar.pullrequest.branch=feat2' '-Dsonar.pullrequest.base=master'
  • The scanner logs seems ok
...
[INFO] Analysis report generated in 209ms, dir size=165 KB
[INFO] Analysis report compressed in 40ms, zip size=28 KB
[INFO] Analysis report uploaded in 26ms
[INFO] ANALYSIS SUCCESSFUL, you can browse http://mycompany/sonar/dashboard?id=test.bpc.groupId%3ABPC_SES_TEST2&pullRequest=4910
[INFO] Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
[INFO] More about the report processing at http://mycompany/sonar/api/ce/task?id=AXUIq2sUC-EP9SeL-ey9
[INFO] Analysis total time: 12.961 s
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 17.417 s
[INFO] Finished at: 2020-10-08T14:44:13Z
[INFO] ------------------------------------------------------------------------
  • The report is available on Sonar.
  • The compute engine logs seems fine as well :
2020.10.08 14:27:58 INFO  ce[AXUInIO3C-EP9SeL-ey4][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Pull Request decoration | status=SUCCESS | time=6ms
2020.10.08 14:27:58 INFO  ce[AXUInIO3C-EP9SeL-ey4][o.s.c.t.CeWorkerImpl] Executed task | project=test.bpc.groupId:BPC_SES_TEST2 | type=REPORT | pullRequest=4910 | id=AXUInIO3C-EP9SeL-ey4 | submitter=admin | status=SUCCESS | time=708ms
  • Strangely, In the gitlab logs I don’t see anything regarding this merge request update. Nginx access log, etc …
  • I saw this issue SONAR-13290 and I try the workaround without any effect.

So How can I move forward ? where i can find more detailed logs ?

Thx in advance

François

EDIT: Gitlab is configured in Sonar without TLS, plain HTTP and Sonar is already able to request our Jenkins server for webhook purpose. Our Jenkins and our Gitlab are behind the same reverse proxy: http://company/jenkins/ and http://company/gitlab/. The access from sonar work with a proxy configuration at JVM level.

Welcome to the community forum!

First of all, please double-check your settings at project level (alm selection + GL project id). Then, you can turn on debug logs on SonarQube, and try again an MR analysis. In ce.log, you should get more insight about what is happening, with the detail of URLs that are called.

The expected calls to GitLab are:

  • GET %s/projects/%s/merge_requests/%s/notes (retrieve notes on the MR)
  • GET %s/user (retrieve the token authenticated user)
  • optionally some delete on existing MR decoration with DELETE %s/projects/%s/merge_requests/%s/notes/%s
  • POST %s/projects/%s/merge_requests/%s/notes?body=%s add a new comment on the MR

Make sure that you can see those, and then try to find in your proxy & GitLab if you have trace of them, and eventually where you lose track.

If the decoration appears successful, it means that SQ received 200 HTTP code, with valid payload, from theses call.

Hi Pierre,

Thank you very much for you answer.
You catch the main problem, the configuration at project level had gone …

Sadly, I think I have others problems:

  • I configured the project with the project id, i used the number.
  • I configured certificates authorities at jvm + system because it complains about it (the first time).
  • I relaunch the test.
  • I don’t have the requests, you were talking about but a single one.

From my proxy log :

09/Oct/2020:15:31:51.342     23 xxx.xxx.xxx.xxx TCP_MISS/302 230 1230 GET http://mycompany/gitlab//projects/196 - HIER_DIRECT/xxx.xxx.xxx.xxx text/html

So for the proxy, SQ is not following the redirection and the result of this request is a classic html message :

<html><body>You are being <a href="https://mycompany/gitlab/123456/SES_TEST2">redirected</a>.</body></html>

In the above url, 123456 is my account in gitlab, so SES_TEST2 is a personal project.

The double slash doesnt seems to be a problem. I succeded to remove it, by changing the global alm configuration.

And here the logs, which seems to say the same.

2020.10.09 15:32:29 DEBUG ce[AXUN_fSbzDLlK-DbozDo][o.s.s.w.WebHooksImpl] Sent webhook 'Jenkins webhook' | url=http://mycompany/jenkins/sonarqube-webhook/ | time=13ms 
| status=200
2020.10.09 15:32:29 INFO  ce[AXUN_fSbzDLlK-DbozDo][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Webhooks | globalWebhooks=1 | projectWebhooks=0 | status=SUCCESS | time=26ms
2020.10.09 15:32:29 DEBUG ce[AXUN_fSbzDLlK-DbozDo][GitlabPrHttpClient] get project url : [https://mycompany/gitlab/projects/196]
2020.10.09 15:32:29 ERROR ce[AXUN_fSbzDLlK-DbozDo][c.s.C.D.D.B] An exception was thrown during Merge Request decoration : java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRIN
G at line 1 column 1 path $
2020.10.09 15:32:29 ERROR ce[AXUN_fSbzDLlK-DbozDo][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Execution of task class com.sonarsource.C.D.c failed
java.lang.IllegalStateException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
at com.sonarsource.C.D.D.G.A(Unknown Source)
at com.sonarsource.C.D.D.B.A(Unknown Source)
at com.sonarsource.C.D.D.B.A(Unknown Source)
at com.sonarsource.C.D.c.A(Unknown Source)
at java.base/java.util.Optional.ifPresent(Optional.java:183)
at com.sonarsource.C.D.c.B(Unknown Source)
at com.sonarsource.C.D.c.A(Unknown Source)
at org.sonar.ce.async.SynchronousAsyncExecution.addToQueue(SynchronousAsyncExecution.java:27)
at com.sonarsource.C.D.c.A(Unknown Source)
at java.base/java.util.Optional.ifPresent(Optional.java:183)
at com.sonarsource.C.D.c.finished(Unknown Source)
at org.sonar.ce.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor.executeTask(PostProjectAnalysisTasksExecutor.java:118)
at org.sonar.ce.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor.finished(PostProjectAnalysisTasksExecutor.java:109)
at org.sonar.ce.task.step.ComputationStepExecutor.executeListener(ComputationStepExecutor.java:91)
at org.sonar.ce.task.step.ComputationStepExecutor.execute(ComputationStepExecutor.java:63)
at org.sonar.ce.task.projectanalysis.taskprocessor.ReportTaskProcessor.process(ReportTaskProcessor.java:81)
at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.executeTask(CeWorkerImpl.java:235)
at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.run(CeWorkerImpl.java:217)
at org.sonar.ce.taskprocessor.CeWorkerImpl.findAndProcessTask(CeWorkerImpl.java:162)
at org.sonar.ce.taskprocessor.CeWorkerImpl$TrackRunningState.get(CeWorkerImpl.java:137)
at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:89)
at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:53)
at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:125)
at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:69)
at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:78)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:226)
at com.google.gson.Gson.fromJson(Gson.java:932)
at com.google.gson.Gson.fromJson(Gson.java:897)
at com.google.gson.Gson.fromJson(Gson.java:846)
at com.google.gson.Gson.fromJson(Gson.java:817)
at com.sonarsource.C.D.D.F.A(Unknown Source)
... 31 common frames omitted
Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:386)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:215)
... 36 common frames omitted
2020.10.09 15:32:29 INFO  ce[AXUN_fSbzDLlK-DbozDo][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Pull Request decoration | status=FAILED | time=275ms
2020.10.09 15:32:29 INFO  ce[AXUN_fSbzDLlK-DbozDo][o.s.c.t.CeWorkerImpl] Executed task | project=test.bpc.test:BPC_SES_TEST2 | type=REPORT | pullRequest=4910 | id=AXUN_fSbzDLlK-DbozDo | su
bmitter=admin | status=SUCCESS | time=1264ms

Hi, yes indeed SQ does not follow redirect HTTP code.

In this case, this is not the most important because even the final url is not the good one …

https://mycompany/gitlab/123456/SES_TEST2

The final url above also returns html content.