SonarCloud not leveraging cached data

  • GitHub

  • Circle CI

  • vue, javascript, php

We are seeing slow SonarCloud times. It takes 10 minutes every single time and very rarely is using the cached layer. The layer is always restored:

Found a cache from build 249003 at v1-sonarcloud-scanner-4.7.0.2747
Size: 470 MiB
Cached paths:
  * /tmp/cache/scanner

Downloading cache archive...
Validating cache...

Unarchiving cache...

Seems like the cached files are not being used. We are seeing this sometimes:

 The PHP analyzer was able to leverage cached data from previous analyses for 0 out of 2605 files. These files were not parsed.

And sometimes it works and we see this and job runs in only 1 minute:

Starting PHP rules
INFO: 2605 source files to be analyzed
INFO: 2605/2605 source files have been analyzed
INFO: The PHP analyzer was able to leverage cached data from previous analyses for 2602 out of 2605 files. These files were not parsed.
INFO: Sensor PHP sensor [php] (done) | time=7506ms

The problem is that in both runs the cache layer restored was one and the same and we don’t see a difference. How can we troubleshoot this?

We’d like more of our SonarCloud CircleCI jobs to run in 1 minute.

Hi @vkulov,

I was just taking a look at the information you have provided. Can you send me information about what parameters you are sending to sonar-scanner? Also if you have a copy of the full log that would be useful.

Separately im reaching out to our teams to see if we have an issue related to caching in this case. I will come back to you if we find an issue here.

Hi @shane.findley ,

This is how our job looks like:

orbs:
  sonarcloud: sonarsource/sonarcloud@1.1.1

.....

  # SonarCloud scan
  sonar_cloud:
    docker:
      - image: cimg/node:18.16.1
    resource_class: xlarge
    working_directory: /home/circleci/project
    steps:
      - attach_workspace:
          at: /home/circleci
      - restore_cache:
          key: coverage-{{ .Environment.CIRCLE_SHA1 }}
      - restore_cache:
          key: phpstan-{{ .Environment.CIRCLE_SHA1 }}
      - restore_cache:
          key: js-coverage-{{ .Environment.CIRCLE_SHA1 }}
      - sonarcloud/scan

Here’s the logs from a long run that took 10minutes
circle-sonar-10m.zip (18.3 KB)

@vkulov,

Thank you for the additional information.

Can I check if you have sensor cache enabled in the general settings for your project on the Sonarcloud UI? I can see from your logs that it is being used but it appears like the cache is being ignored in almost all cases.

Screenshot 2023-07-03 at 15.21.39

INFO: Sensor cache enabled
INFO: Load sensor cache
INFO: Load sensor cache (19 MB) | time=2721ms

FYI I am currently trying to isolate where the issue might be occuring, I will update again once we have a more clear idea. I’ll keep you updated with the progress.

image

I see it as enabled though we haven’t explicitly configured it in our sonar-project.properties file

Hey @vkulov,

You mentioned that sometimes the cache is used and sometimes not. The cache is only used during a PR analysis, not when the main branch is being analyzed. When does this behavior occur?

Best,
Nils