Code Duplication increased from 6.6% to 32% in days via new PR

We’re seeing some very odd behaviour within SonarCloud where code duplication is increasing for every PR submitted for review.
In one PR that had a single character change in a single line of code, SonarCloud is reporting 32% code duplication on new lines of code. This is very confusing to the developers.

Template for a good new topic, formatted with Markdown:

  • ALM used: GitHub
  • CI system used: Jenkins (Linux Foundation - EdgeX Foundry)
  • Scanner command used when applicable: Unknown
  • Languages of the repository: Go
  • Only if the SonarCloud project is public: EdgeX SonarCloud PR 1781
  • PR Request: http://PR #1817
  • Error observed:
  • Steps to reproduce: submit a new pr with go module
  • Potential workaround: Create new SonarCloud Quality Gate that removes Duplicated Lines (%) and set that QG as Default.

Correction on the link to the measurement in SonarCloud:
https://sonarcloud.io/dashboard?id=edgexfoundry_edgex-go&pullRequest=1817

Hi,
When this happens, could you send us the logs from the scanner, preferably with debug enabled?

It does look like the scanner is incorrectly collecting information about what was changed in the P/R from git.
The likely cause of these kind of issues is a problem with the git clone. It needs to not be a shallow clone and have up-to-date references to the base and master branches (‘tsconn23:issue_1816’ and ‘master’ in this case).

Thank you for your response @dmeneses. I checked the the Linux Foundation Release Engineers and since this is configured through SonarCloud against just the repo, I guess there’s no scans initiated on the LF infrastructure within Jenkins. I’m not sure how we’d enable verbose logging from SonarCloud. Is there an option to do that so I can work with LFRE?

Hi @jamesrgregg,

It looks like we have a bug when scanning forked PR with Autoscan. We’re using the base branch of the forked repo instead of the base repo to compute new code.
That means for the PR your linked, new code is computed by comparing tsconn23:issue_1816 to tsconn23:master instead of edgexfoundry:master.

You can watch this ticket to track progress on this bug: SCCOMM-8.

Best,

Thank you for the update and classification of this bug @benoit