Skip to content

Commit 838ac11

Browse files
authored
Merge pull request #1381 from okorach:trim-background-task-data
Trim-background-task-data
2 parents e455cb2 + 8b55106 commit 838ac11

File tree

5 files changed

+65
-13
lines changed

5 files changed

+65
-13
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[flake8]
22
# E501 = Line too long
3-
ignore = E501,E401,W503,E128,C901,W504,E302,E265,E741,W291,W292,W293,W391,F401,E226,F841,F821,F541,D400,D401,E800,D102,D105,D107,I900,F632,E261
3+
ignore = E501,E401,W503,E128,C901,W504,E302,E265,E741,W291,W292,W293,W391,F401,E226,F841,F821,F541,D400,D401,E800,D102,D105,D107,I900,F632,E261,E731
44
max-line-length = 150
55
#exclude = tests/*
66
#max-complexity = 10

migration/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ When sonar-migration complete successfully they return exit code 0. En case of f
116116
- Support of incremental dump of projects extracts
117117
- Display of HTTP requests duration in DEBUG logs
118118
- Fixes in documentation
119+
- Trimmed background task data to keep only what is need (to reduce memory and output JSON size)
119120

120121
## Version 0.2
121122

migration/what-is-new.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Support of incremental dump of projects extracts
77
- Display of HTTP requests duration in DEBUG logs
88
- Fixes in documentation
9+
- Trimmed background task data to keep only what is need (to reduce memory and output JSON size)
910

1011
# Version 0.2
1112

pylintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ disable=raw-checker-failed,
8686
W0611,
8787
W0238,
8888
R0911,
89-
C0325
89+
C0325,
90+
W1309
9091

9192

9293
# Enable the message, report, category or checker with the given id(s). You can

sonar/projects.py

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,46 @@
8080
"webhooks",
8181
)
8282

83+
_UNNEEDED_CONTEXT_DATA = (
84+
"sonar.announcement.message",
85+
"sonar.auth.github.allowUsersToSignUp",
86+
"sonar.auth.github.apiUrl",
87+
"sonar.auth.github.appId",
88+
"sonar.auth.github.enabled",
89+
"sonar.auth.github.groupsSync",
90+
"sonar.auth.github.organizations",
91+
"sonar.auth.github.webUrl",
92+
"sonar.builtInQualityProfiles.disableNotificationOnUpdate",
93+
"sonar.core.id",
94+
"sonar.core.serverBaseURL",
95+
"sonar.core.startTime",
96+
"sonar.dbcleaner.branchesToKeepWhenInactive",
97+
"sonar.forceAuthentication",
98+
"sonar.host.url",
99+
"sonar.java.jdkHome",
100+
"sonar.links.ci",
101+
"sonar.links.homepage",
102+
"sonar.links.issue",
103+
"sonar.links.scm",
104+
"sonar.links.scm_dev",
105+
"sonar.plugins.risk.consent",
106+
)
107+
108+
_UNNEEDED_TASK_DATA = (
109+
"analysisId",
110+
"componentId",
111+
"hasScannerContext",
112+
"id",
113+
"warningCount",
114+
"componentQualifier",
115+
"nodeName",
116+
"componentName",
117+
"componentKey",
118+
"submittedAt",
119+
"executedAt",
120+
"type",
121+
)
122+
83123

84124
class Project(components.Component):
85125
"""
@@ -954,9 +994,9 @@ def export(self, export_settings: types.ConfigSettings, settings_list: dict[str,
954994
:rtype: dict
955995
"""
956996
log.info("Exporting %s", str(self))
997+
json_data = self._json.copy()
998+
json_data.update({"key": self.key, "name": self.name})
957999
try:
958-
json_data = self._json.copy()
959-
json_data.update({"key": self.key, "name": self.name})
9601000
json_data["binding"] = self.__export_get_binding()
9611001
nc = self.new_code()
9621002
if nc != "":
@@ -983,10 +1023,16 @@ def export(self, export_settings: types.ConfigSettings, settings_list: dict[str,
9831023
last_task = self.last_task()
9841024
json_data["backgroundTasks"] = {}
9851025
if last_task:
1026+
ctxt = last_task.scanner_context()
1027+
if ctxt:
1028+
ctxt = {k: v for k, v in ctxt.items() if k not in _UNNEEDED_CONTEXT_DATA}
1029+
t_hist = []
1030+
for t in self.task_history():
1031+
t_hist.append({k: v for k, v in t._json.items() if k not in _UNNEEDED_TASK_DATA})
9861032
json_data["backgroundTasks"] = {
987-
"lastTaskScannerContext": last_task.scanner_context(),
988-
"lastTaskWarnings": last_task.warnings(),
989-
"taskHistory": [t._json for t in self.task_history()],
1033+
"lastTaskScannerContext": ctxt,
1034+
# "lastTaskWarnings": last_task.warnings(),
1035+
"taskHistory": t_hist,
9901036
}
9911037

9921038
settings_dict = settings.get_bulk(endpoint=self.endpoint, component=self, settings_list=settings_list, include_not_set=False)
@@ -997,14 +1043,17 @@ def export(self, export_settings: types.ConfigSettings, settings_list: dict[str,
9971043
json_data.update(s.to_json())
9981044
except HTTPError as e:
9991045
if e.response.status_code == HTTPStatus.FORBIDDEN:
1000-
log.critical("Insufficient privileges to access %s, export of this project skipped", str(self))
1001-
json_data = {"error": "Insufficient permissions while extracting project"}
1046+
log.critical("Insufficient privileges to access %s, export of this project interrupted", str(self))
1047+
json_data["error"] = "Insufficient permissions while exporting project, export interrupted"
10021048
else:
1003-
log.critical("HTTP error %s while exporting %s, export of this project skipped", str(e), str(self))
1004-
json_data = {"error": f"HTTP error {str(e)} while extracting project"}
1049+
log.critical("HTTP error %s while exporting %s, export of this project interrupted", str(e), str(self))
1050+
json_data["error"] = f"HTTP error {str(e)} while extracting project"
10051051
except ConnectionError as e:
1006-
log.critical("Connecting error %s while extracting %s, extract of this project skipped", str(self), str(e))
1007-
json_data = {"error": f"Connection error {str(e)} while extracting prooject"}
1052+
log.critical("Connecting error %s while exporting %s, export of this project interrupted", str(self), str(e))
1053+
json_data["error"] = f"Connection error {str(e)} while extracting project, export interrupted"
1054+
except Exception as e:
1055+
log.critical("Connecting error %s while exporting %s, export of this project interrupted", str(self), str(e))
1056+
json_data["error"] = f"Exception {str(e)} while exporting project, export interrupted"
10081057
log.info("Exporting %s done", str(self))
10091058
return util.remove_nones(json_data)
10101059

0 commit comments

Comments
 (0)