Skip to content

Commit 41b9f16

Browse files
authored
Merge pull request #1375 from okorach:optional-expensive-extract
Make expensive issue count extract optional
2 parents 5ba2470 + 55d11b8 commit 41b9f16

File tree

7 files changed

+28
-6
lines changed

7 files changed

+28
-6
lines changed

migration/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ The user corresponding to the token must have sufficiently elevated permissions
4242
`ERROR` and above is always active.
4343
- `-c` or `--clientCert` : Allows to specify an optional client certificate file (as .pem file)
4444
- `--httpTimeout` : Sets the timeout for HTTP(S) requests to the SonarQube platform
45+
- `--skipIssues` : Skips the "expensive" issue count extract from the migration. This reduces by a factor of 2 to 3 the extract duration and the number of API calls
4546
- `--skipVersionCheck` : `sonar-migration` occasionnally checks on pypi.org if there is a new version of **sonar-migration** available, and output a warning log if that is the case. You can skip this check with this option.
4647
- `-l <logFile>` : Send logs to **<logFile>**, stdout by default
4748

@@ -107,6 +108,11 @@ When sonar-migration complete successfully they return exit code 0. En case of f
107108

108109
# What's New - Release notes
109110

111+
## Version 0.3
112+
113+
- Robustness: Handle `connectionError` errors in project extract threads
114+
- Added option `--skipIssues` to skip expensive issue count extraction task from the extract which may be necessary on large platforms extracts
115+
110116
## Version 0.2
111117

112118
- Added export of:

migration/migration.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ def __parse_args(desc):
7373
parser = options.add_thread_arg(parser, "migration export")
7474
parser = options.set_what(parser, what_list=_EVERYTHING, operation="export")
7575
parser = options.add_import_export_arg(parser, "migration")
76+
parser.add_argument(
77+
"--skipIssues",
78+
required=False,
79+
default=False,
80+
action="store_true",
81+
help="Skips the export of issues count which might be costly iin terms of API calls",
82+
)
7683
parser.add_argument(
7784
"--exportDefaults",
7885
required=False,
@@ -101,6 +108,7 @@ def __export_config(endpoint: platform.Platform, what: list[str], **kwargs) -> N
101108
"FULL_EXPORT": False,
102109
"MODE": "MIGRATION",
103110
"THREADS": kwargs[options.NBR_THREADS],
111+
"SKIP_ISSUES": kwargs["skipIssues"],
104112
}
105113
if "projects" in what and kwargs[options.KEYS]:
106114
non_existing_projects = [key for key in kwargs[options.KEYS] if not projects.exists(key, endpoint)]
@@ -140,7 +148,7 @@ def main() -> None:
140148
"""Main entry point for sonar-config"""
141149
start_time = utilities.start_clock()
142150
try:
143-
kwargs = utilities.convert_args(__parse_args("Extract SonarQube platform configuration"))
151+
kwargs = utilities.convert_args(__parse_args("Extract SonarQube to SonarCloud migration data"))
144152
endpoint = platform.Platform(**kwargs)
145153
endpoint.verify_connection()
146154
endpoint.set_user_agent(f"sonar-migration {version.MIGRATION_TOOL_VERSION}")

migration/what-is-new.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Next version yet unreleased
1+
# Version 0.3
2+
3+
- Robustness: Handle `connectionError` errors in project extract threads
4+
- Added option `--skipIssues` to skip expensive issue count extraction task from the extract which may be necessary on large platforms extracts
5+
26

37
# Version 0.2
48

sonar/branches.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def export(self, export_settings: types.ConfigSettings) -> types.ObjectJsonRepr:
231231
if export_settings.get("FULL_EXPORT", True):
232232
data.update({"name": self.name, "project": self.concerned_object.key})
233233
if export_settings.get("MODE", "") == "MIGRATION":
234-
data.update(self.migration_export())
234+
data.update(self.migration_export(export_settings))
235235
data = util.remove_nones(data)
236236
return None if len(data) == 0 else data
237237

sonar/components.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def get_hotspots(self, filters: types.ApiParams = None) -> dict[str, object]:
167167
params.update(filters)
168168
return search(endpoint=self.endpoint, filters=params)
169169

170-
def migration_export(self) -> dict[str, any]:
170+
def migration_export(self, export_settings: types.ConfigSettings) -> dict[str, any]:
171171
from sonar.issues import count as issue_count
172172
from sonar.hotspots import count as hotspot_count
173173

@@ -178,6 +178,10 @@ def migration_export(self) -> dict[str, any]:
178178
loc_distrib = {m.split("=")[0]: int(m.split("=")[1]) for m in lang_distrib.split(";")}
179179
loc_distrib["total"] = self.loc()
180180
json_data["ncloc"] = loc_distrib
181+
if export_settings["SKIP_ISSUES"]:
182+
log.debug("Issues count extract skipped for %s`", str(self))
183+
return json_data
184+
181185
tpissues = self.count_third_party_issues()
182186
inst_issues = self.count_instantiated_rules_issues()
183187
params = self.search_params()

sonar/projects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ def export(self, export_settings: types.ConfigSettings, settings_list: dict[str,
977977
json_data = util.filter_export(json_data, _IMPORTABLE_PROPERTIES, export_settings.get("FULL_EXPORT", False))
978978

979979
if export_settings.get("MODE", "") == "MIGRATION":
980-
json_data.update(self.migration_export())
980+
json_data.update(self.migration_export(export_settings))
981981
json_data["detectedCi"] = self.ci()
982982
json_data["revision"] = self.revision()
983983
last_task = self.last_task()

sonar/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@
2525
"""
2626

2727
PACKAGE_VERSION = "3.5"
28-
MIGRATION_TOOL_VERSION = "0.2"
28+
MIGRATION_TOOL_VERSION = "0.3"

0 commit comments

Comments
 (0)