Skip to content

Commit

Permalink
[fix] Checker Coverage statistics fixing
Browse files Browse the repository at this point in the history
It's a fix PR based on Ericsson#4210. Unnecessary comments were deleted. Minimal API changes and some style corrections were made. Some parts of the code are more readable now.

api packages

package-lock.json reset to master

package lock json fix hash
  • Loading branch information
cservakt authored and whisperity committed Apr 12, 2024
1 parent 531b7aa commit 7fd35c4
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 104 deletions.
Binary file modified web/api/js/codechecker-api-node/dist/codechecker-api-6.56.0.tgz
Binary file not shown.
Binary file modified web/api/py/codechecker_api/dist/codechecker_api.tar.gz
Binary file not shown.
Binary file not shown.
17 changes: 9 additions & 8 deletions web/api/report_server.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -396,16 +396,16 @@ struct CheckerCount {
}
typedef list<CheckerCount> CheckerCounts

struct CheckerInfo {
1: string checkerName, // Analyzer name of the checker.
struct CheckerStatusVerificationDetail {
1: string checkerName, // Checker name.
2: string analyzerName, // Analyzer name of the checker.
3: Severity severity, // Severity level of the checker.
4: list<i64> enabled, // Runs' names in which the checker enabled.
5: list<i64> disabled, // Runs' names in which the checker disabled.
4: list<i64> enabled, // Run ids in which the checker enabled.
5: list<i64> disabled, // Run ids in which the checker disabled.
6: i64 closed // Number of closed reports.
7: i64 outstanding // Number of outstanding reports.
}
typedef map<i64, CheckerInfo> CheckerInfos
typedef map<i64, CheckerStatusVerificationDetail> CheckerStatusVerificationDetails

struct CommentData {
1: i64 id,
Expand Down Expand Up @@ -867,9 +867,10 @@ service codeCheckerDBAccess {
// enabled and how many reports are opened or closed.
// If the run id list is empty the statistics
// will be counted for all of the runs.
CheckerInfos getCheckerInfo(1: list<i64> runIds,
2: ReportFilter reportFilter)
throws (1: codechecker_api_shared.RequestFailed requestError),
// PERMISSION: PRODUCT_VIEW
CheckerStatusVerificationDetails getCheckerStatusVerificationDetails(1: list<i64> runIds,
2: ReportFilter reportFilter)
throws (1: codechecker_api_shared.RequestFailed requestError),

// If the run id list is empty the metrics will be counted
// for all of the runs and in compare mode all of the runs
Expand Down
167 changes: 78 additions & 89 deletions web/server/codechecker_server/api/report_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@
from codechecker_api.codeCheckerDBAccess_v6.ttypes import \
AnalysisInfoFilter, AnalysisInfoChecker as API_AnalysisInfoChecker, \
BlameData, BlameInfo, BugPathPos, \
CheckerCount, Commit, CommitAuthor, CommentData, \
DiffType, \
CheckerCount, CheckerStatusVerificationDetail, Commit, CommitAuthor, \
CommentData, \
DetectionStatus, DiffType, \
Encoding, ExportData, \
Order, \
ReportData, ReportDetails, ReviewData, ReviewStatusRule, \
ReviewStatusRuleFilter, ReviewStatusRuleSortMode, \
ReviewStatusRuleSortType, RunData, RunFilter, RunHistoryData, \
RunReportCount, RunSortType, RunTagCount, \
SourceComponentData, SourceFileData, SortMode, SortType, \
ReviewStatus as API_ReviewStatus, DetectionStatus, CheckerInfo
ReviewStatus as API_ReviewStatus, \
SourceComponentData, SourceFileData, SortMode, SortType \

from codechecker_common import util
from codechecker_common.logger import get_logger
Expand All @@ -59,7 +60,6 @@
from ..database.database import conv, DBSession, escape_like
from ..database.run_db_model import \
AnalysisInfo, AnalysisInfoChecker as DB_AnalysisInfoChecker, \
AnalysisInfoChecker, \
AnalyzerStatistic, \
BugPathEvent, BugReportPoint, \
CleanupPlan, CleanupPlanReportHash, Checker, Comment, \
Expand Down Expand Up @@ -1284,6 +1284,55 @@ def get_rs_rule_query(
return q


def get_run_id_expression(session, report_filter):
if report_filter.isUnique:
if session.bind.dialect.name == "postgresql":
return func.string_agg(
cast(Run.id, sqlalchemy.String).distinct(),
','
).label("run_id")
else:
return func.group_concat(
Run.id.distinct()
).label("run_id")
else:
return Run.id.label("run_id")


def get_is_enabled_case(subquery):
detection_status_filters = subquery.c.detection_status.in_(list(
map(detection_status_str,
(DetectionStatus.OFF, DetectionStatus.UNAVAILABLE))
))

return case(
[(detection_status_filters, False)],
else_=True
)


def get_is_opened_case(subquery):
detection_statuses = (
DetectionStatus.NEW,
DetectionStatus.UNRESOLVED,
DetectionStatus.REOPENED
)
review_statuses = (
API_ReviewStatus.UNREVIEWED,
API_ReviewStatus.CONFIRMED
)
detection_and_review_status_filters = [
subquery.c.detection_status.in_(list(map(
detection_status_str, detection_statuses))),
subquery.c.review_status.in_(list(map(
review_status_str, review_statuses)))
]
return case(
[(and_(*detection_and_review_status_filters), True)],
else_=False
)


class ThriftRequestHandler:
"""
Connect to database and handle thrift client requests.
Expand Down Expand Up @@ -2865,8 +2914,9 @@ def getCheckerCounts(self, run_ids, report_filter, cmp_data, limit,

@exc_to_thrift_reqfail
@timeit
def getCheckerInfo(self, run_ids, report_filter):
def getCheckerStatusVerificationDetails(self, run_ids, report_filter):
self.__require_view()

with DBSession(self._Session) as session:
max_run_histories = session.query(
RunHistory.run_id,
Expand All @@ -2875,16 +2925,11 @@ def getCheckerInfo(self, run_ids, report_filter):
.filter(RunHistory.run_id.in_(run_ids) if run_ids else True) \
.group_by(RunHistory.run_id)

run_id_expression = get_run_id_expression(session, report_filter)

subquery = (
session.query(
(func.string_agg(
cast(Run.id, sqlalchemy.String).distinct(),
','
).label("run_id")
if session.bind.dialect.name == "postgresql"
else func.group_concat(Run.id.distinct()).label("run_id"))
if report_filter.isUnique
else Run.id.label("run_id"),
run_id_expression,
Checker.id.label("checker_id"),
Checker.checker_name,
Checker.analyzer_name,
Expand All @@ -2895,10 +2940,12 @@ def getCheckerInfo(self, run_ids, report_filter):
)
.join(RunHistory)
.join(AnalysisInfo, RunHistory.analysis_info)
.join(AnalysisInfoChecker, (
(AnalysisInfo.id == AnalysisInfoChecker.analysis_info_id)
& (AnalysisInfoChecker.enabled.is_(True))))
.join(Checker, AnalysisInfoChecker.checker_id == Checker.id)
.join(DB_AnalysisInfoChecker, (
(AnalysisInfo.id ==
DB_AnalysisInfoChecker.analysis_info_id)
& (DB_AnalysisInfoChecker.enabled.is_(True))))
.join(Checker,
DB_AnalysisInfoChecker.checker_id == Checker.id)
.outerjoin(Report, ((Checker.id == Report.checker_id)
& (Run.id == Report.run_id)))
.filter(RunHistory.id == max_run_histories.subquery()
Expand All @@ -2918,46 +2965,18 @@ def getCheckerInfo(self, run_ids, report_filter):

subquery = subquery.subquery()

is_enabled_case = get_is_enabled_case(subquery)
is_opened_case = get_is_opened_case(subquery)

query = (
session.query(
subquery.c.checker_id,
subquery.c.checker_name,
subquery.c.analyzer_name,
subquery.c.severity,
subquery.c.run_id,
case(
[
(
subquery.c.detection_status.in_(list(map(
detection_status_str,
(DetectionStatus.OFF,
DetectionStatus.UNAVAILABLE)
))),
False
)
],
else_=True
).label("isEnabled"),
case(
[
(
and_(
subquery.c.detection_status.in_(list(map(
detection_status_str,
(DetectionStatus.NEW,
DetectionStatus.UNRESOLVED,
DetectionStatus.REOPENED)
))),
subquery.c.review_status.in_(list(map(
review_status_str,
(API_ReviewStatus.UNREVIEWED,
API_ReviewStatus.CONFIRMED))))
),
True
)
],
else_=False
).label("isOpened"),
is_enabled_case.label("isEnabled"),
is_opened_case.label("isOpened"),
func.count(subquery.c.bug_id)
)
.group_by(
Expand All @@ -2966,39 +2985,8 @@ def getCheckerInfo(self, run_ids, report_filter):
subquery.c.analyzer_name,
subquery.c.severity,
subquery.c.run_id,
case(
[
(
subquery.c.detection_status.in_(list(map(
detection_status_str,
(DetectionStatus.OFF,
DetectionStatus.UNAVAILABLE)
))),
False
)
],
else_=True
),
case(
[
(
and_(
subquery.c.detection_status.in_(list(map(
detection_status_str,
(DetectionStatus.NEW,
DetectionStatus.UNRESOLVED,
DetectionStatus.REOPENED)
))),
subquery.c.review_status.in_(list(map(
review_status_str,
(API_ReviewStatus.UNREVIEWED,
API_ReviewStatus.CONFIRMED))))
),
True
)
],
else_=False
)
is_enabled_case,
is_opened_case
)
)

Expand All @@ -3013,21 +3001,22 @@ def getCheckerInfo(self, run_ids, report_filter):
is_opened, \
cnt \
in query.all():
checker_stat = checker_stats[checker_id] \
if checker_id in checker_stats \
else CheckerInfo(

checker_stat = checker_stats.get(
checker_id,
CheckerStatusVerificationDetail(
checkerName=checker_name,
analyzerName=analyzer_name,
enabled=[],
disabled=all_run_id,
severity=severity,
closed=0,
outstanding=0
)
))

if is_enabled:
for r in (run_ids.split(",")
if type(run_ids) is str
if isinstance(run_ids, str)
else [run_ids]):
run_id = int(r)
if run_id not in checker_stat.enabled:
Expand Down
4 changes: 2 additions & 2 deletions web/server/vue-cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export default {
})
];
this.toCSV(data, "codechecker_analysis_statistics.csv");
this.toCSV(data, "codechecker_checker_coverage_statistics.csv");
},
async getRunData() {
Expand Down Expand Up @@ -262,7 +262,9 @@ export default {
const filter = new ReportFilter(this.reportFilter);
this.checker_stat = await new Promise(resolve => {
ccService.getClient().getCheckerInfo(this.runIds, filter,
ccService.getClient().getCheckerStatusVerificationDetails(
this.runIds,
filter,
handleThriftError(res => {
resolve(res);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<v-card-title
class="headline primary white--text"
primary-title
style="text-transform: capitalize;"
>
{{ title }}

Expand Down Expand Up @@ -105,7 +104,8 @@ export default {
},
title() {
let title = `${this.type} Run List`;
let title = `${this.type.charAt(0).toUpperCase()
+ this.type.slice(1)} run list`;
if ( this.checkerName ) {
title += ` for the "${this.checkerName}" checker`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ccService, handleThriftError } from "@cc-api";
import {
ReportFilter,
ReviewStatus,
// AnalysisInfoFilter
} from "@cc/report-server-types";

const reviewStatusVariations = [
Expand Down

0 comments on commit 7fd35c4

Please sign in to comment.