Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sonar.cxx.other.rules not reloaded on SonarQube restart #2557

Open
br-rhrbacek opened this issue Aug 16, 2023 · 11 comments
Open

sonar.cxx.other.rules not reloaded on SonarQube restart #2557

br-rhrbacek opened this issue Aug 16, 2023 · 11 comments
Labels
Milestone

Comments

@br-rhrbacek
Copy link

According to this wiki page, the sonar.cxx.other.rules should be reloaded after SonarQube is restarted, but they are not.

To Reproduce
Steps to reproduce the behavior:

  1. Go to Administration > Configuration > General Settings > CXX External Analyzers.
  2. Add new rules to sonar.cxx.other.rules.
  3. Click Save.
  4. Restart SonarQube.

Expected behavior
New rules should be visible in Rules tab in SonarQube.

Additional context
It seems that the rules are only registered during plugin installation, see this ticket: https://community.sonarsource.com/t/how-to-retrigger-define-functions-of-rulesdefinition-in-new-version-of-sonarqube/90314.

@guwirth
Copy link
Collaborator

guwirth commented Aug 16, 2023

Hi @br-rhrbacek,

which versions of the plugin and SonarQube are you using?

  • Are the rules you added still available / visible in Administration > Configuration > General Settings > CXX External Analyzers after server restart?
  • Are the rules valid XML?
  • Did you verify the LOG files?
  • Are the rules activated in the profile?

Regards,

@br-rhrbacek
Copy link
Author

Hi @guwirth,

We are using SonarQube 9.9.1.69595 and sonar-cxx V2.1.1. The rules are valid, and are visible in the Administration after the restart, but cannot be activated since they are not registered. We checked the LOG files and could not find the web[][o.s.s.r.RegisterRules] Register rules event there.

Recently, we upgraded from SonarQube 8.9 and as far as I can remember, it worked with this version.

Regards,

@guwirth
Copy link
Collaborator

guwirth commented Aug 17, 2023

Hi @br-rhrbacek,

we have it running.

The point I don’t understand is:

  • first step is to install a new version of SonarQube
  • then you have to install the plugin
  • after this step the first time the Administration > Configuration > General Settings > CXX External Analyzers is visible.
  • now you can add the rule descriptions and have to restart the server

I understand that you can’t add new rules? Are any other rules visible? Why I’m asking is because I see no difference between doing it the first time or later.

The whole mechanism is not very well supported by SonarSource. Means you have to ensure that XML is valid, there are no duplicated keys, … (see https://github.com/SonarOpenCommunity/sonar-cxx/wiki/sonar.cxx.other.rules#troubleshooting).

Regards,

@br-rhrbacek
Copy link
Author

Hi @guwirth,

We have been using the plugin with multiple custom rules and want to add some more. The point is that if we add them to sonar.cxx.other.rules, and restart SonarQube, we can't find them in Rules and can't activate them in the profile.

I think the root cause is that SonarQube does not trigger the registration of the rules on each restart, but only for the first time when installing the plugin. At least this is how I understand this thread: https://community.sonarsource.com/t/how-to-retrigger-define-functions-of-rulesdefinition-in-new-version-of-sonarqube/90314/3.

Regards,

@guwirth
Copy link
Collaborator

guwirth commented Aug 18, 2023

Hi @br-rhrbacek,

How did you add the rules the first time? For my understanding the first time you are starting the server with the plugin the sonar.cxx.other.rules are empty, right? Then you are adding the rules in the UI and restarting the server. What’s different adding later on additional rules?

  • Can you try it again with very simple rule XML (maybe only one rule, then later on adding a second one)? I still think it’s a rule problem.
  • What happens if you remove all rules (make fields in Ul empty, save, restart)? If reading is not working it should also be not possible to remove rules.

Regards,

@br-rhrbacek
Copy link
Author

Hi @guwirth,

I tried to remove some rules, restart the server, and there was no change as well. I'm unsure if I can remove all the rules since the profile would probably be affected, right? So I removed only the rules that are not used now, but after the restart, they were still available.

Regards,

@guwirth guwirth added bug and removed question labels Aug 21, 2023
@guwirth guwirth added this to the 2.1.1 milestone Aug 21, 2023
@guwirth
Copy link
Collaborator

guwirth commented Aug 21, 2023

Hi @br-rhrbacek,

tried it with a fresh installation and you are right. There seems to be a cache mechanism reloading the rules only if plugin changes are detected. Question is how they detect a "change"?

First start with a plugin:

2023.05.17 17:02:12 INFO  web[][o.s.s.p.DetectPluginChange] Detect plugin changes
2023.05.17 17:02:14 INFO  web[][o.s.s.s.GeneratePluginIndex] Generate scanner plugin index
2023.05.17 17:02:14 INFO  web[][o.s.s.s.RegisterMetrics] Register metrics
2023.05.17 17:02:14 INFO  web[][o.s.s.r.RegisterRules] Register rules
2023.05.17 17:02:19 INFO  web[][o.s.s.q.b.BuiltInQProfileRepositoryImpl] Load quality profiles
2023.05.17 17:02:19 INFO  web[][o.s.s.q.RegisterQualityProfiles] Register quality profiles
2023.05.17 17:02:20 INFO  web[][o.s.s.q.RegisterQualityProfiles] Update profile cxx/Sonar way
2023.05.17 17:02:20 INFO  web[][o.s.s.s.RegisterPermissionTemplates] Register permission templates
2023.05.17 17:02:20 INFO  web[][o.s.s.s.RenameDeprecatedPropertyKeys] Rename deprecated property keys
2023.05.17 17:02:20 INFO  web[][o.s.s.s.RegisterPlugins] Register plugins

All following starts without plugin change:

2023.08.21 14:07:35 INFO  web[][o.s.s.p.DetectPluginChange] Detect plugin changes
2023.08.21 14:07:36 INFO  web[][o.s.s.p.DetectPluginChange] No plugin change detected

Regards,

@br-rhrbacek
Copy link
Author

Hi @guwirth,

the only solution I have is to modify the hash value in DB (dbPlugin.getFileHash()) and restart SonarQube.

Regards,

@br-rhrbacek
Copy link
Author

Hi @guwirth,

I managed to register the new rules by modifying the file hash in DB (UPDATE plugins SET file_hash = '' WHERE kee = 'cxx';) and restarting SonarQube.

Since we do not update the rules often, it is an acceptable solution for us.

Regards,

@guwirth
Copy link
Collaborator

guwirth commented Aug 22, 2023

Hello @br-rhrbacek,

thanks for your feedback. Not sure if there is an API to do that from the plugin?

Yesterday I tried renaming the .JAR, touching the .JAR (update date) without success.
Other possibilities I had in mind were:

  • Removing the plugin, start the server, adding it again, start the server. Not sure if quality profiles and rules are still in DB after this?
  • unziping .JAR, modifying something to change the hash value and zip it again.

But all ugly :-(

Regards,

@guwirth guwirth pinned this issue Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants