Skip to content

Commit 49c2f97

Browse files
authored
Merge pull request #19180 from geoffw0/lessnoise
Rust: Reduce CI noise from the SummaryStats query
2 parents 006cb02 + 6597454 commit 49c2f97

File tree

11 files changed

+117
-113
lines changed

11 files changed

+117
-113
lines changed
-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
| Elements extracted | 67 |
2-
| Elements unextracted | 0 |
31
| Extraction errors | 0 |
42
| Extraction warnings | 1 |
53
| Files extracted - total | 5 |
@@ -15,11 +13,3 @@
1513
| Macro calls - resolved | 2 |
1614
| Macro calls - total | 2 |
1715
| Macro calls - unresolved | 0 |
18-
| Taint edges - number of edges | 1691 |
19-
| Taint reach - nodes tainted | 0 |
20-
| Taint reach - per million nodes | 0 |
21-
| Taint sinks - cryptographic operations | 0 |
22-
| Taint sinks - query sinks | 1 |
23-
| Taint sources - active | 0 |
24-
| Taint sources - disabled | 0 |
25-
| Taint sources - sensitive data | 0 |
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
queries/summary/SummaryStats.ql
1+
queries/summary/SummaryStatsReduced.ql
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
| Elements extracted | 90 |
2-
| Elements unextracted | 0 |
31
| Extraction errors | 0 |
42
| Extraction warnings | 0 |
53
| Files extracted - total | 4 |
@@ -15,11 +13,3 @@
1513
| Macro calls - resolved | 2 |
1614
| Macro calls - total | 2 |
1715
| Macro calls - unresolved | 0 |
18-
| Taint edges - number of edges | 1691 |
19-
| Taint reach - nodes tainted | 0 |
20-
| Taint reach - per million nodes | 0 |
21-
| Taint sinks - cryptographic operations | 0 |
22-
| Taint sinks - query sinks | 1 |
23-
| Taint sources - active | 0 |
24-
| Taint sources - disabled | 0 |
25-
| Taint sources - sensitive data | 0 |
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
queries/summary/SummaryStats.ql
1+
queries/summary/SummaryStatsReduced.ql
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
| Elements extracted | 90 |
2-
| Elements unextracted | 0 |
31
| Extraction errors | 0 |
42
| Extraction warnings | 0 |
53
| Files extracted - total | 4 |
@@ -15,11 +13,3 @@
1513
| Macro calls - resolved | 2 |
1614
| Macro calls - total | 2 |
1715
| Macro calls - unresolved | 0 |
18-
| Taint edges - number of edges | 1691 |
19-
| Taint reach - nodes tainted | 0 |
20-
| Taint reach - per million nodes | 0 |
21-
| Taint sinks - cryptographic operations | 0 |
22-
| Taint sinks - query sinks | 1 |
23-
| Taint sources - active | 0 |
24-
| Taint sources - disabled | 0 |
25-
| Taint sources - sensitive data | 0 |

Diff for: rust/ql/src/queries/summary/Stats.qll

+92
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ private import codeql.rust.internal.PathResolutionConsistency as PathResolutionC
1111
private import codeql.rust.controlflow.internal.CfgConsistency as CfgConsistency
1212
private import codeql.rust.dataflow.internal.DataFlowConsistency as DataFlowConsistency
1313
private import codeql.rust.Concepts
14+
private import codeql.rust.Diagnostics
15+
private import codeql.rust.security.SensitiveData
16+
private import TaintReach
1417
// import all query extensions files, so that all extensions of `QuerySink` are found
1518
private import codeql.rust.security.CleartextLoggingExtensions
1619
private import codeql.rust.security.SqlInjectionExtensions
@@ -72,3 +75,92 @@ int getTaintEdgesCount() {
7275
* Gets a count of the total number of query sinks in the database.
7376
*/
7477
int getQuerySinksCount() { result = count(QuerySink s) }
78+
79+
class CrateElement extends Element {
80+
CrateElement() {
81+
this instanceof Crate or
82+
this instanceof NamedCrate or
83+
this.(AstNode).getParentNode*() = any(Crate c).getModule()
84+
}
85+
}
86+
87+
/**
88+
* Gets summary statistics about individual elements in the database.
89+
*/
90+
predicate elementStats(string key, int value) {
91+
key = "Elements extracted" and
92+
value = count(Element e | not e instanceof Unextracted and not e instanceof CrateElement)
93+
or
94+
key = "Elements unextracted" and value = count(Unextracted e)
95+
}
96+
97+
/**
98+
* Gets summary statistics about extraction.
99+
*/
100+
predicate extractionStats(string key, int value) {
101+
key = "Extraction errors" and value = count(ExtractionError e)
102+
or
103+
key = "Extraction warnings" and value = count(ExtractionWarning w)
104+
or
105+
key = "Files extracted - total" and value = count(ExtractedFile f | exists(f.getRelativePath()))
106+
or
107+
key = "Files extracted - with errors" and
108+
value =
109+
count(ExtractedFile f |
110+
exists(f.getRelativePath()) and not f instanceof SuccessfullyExtractedFile
111+
)
112+
or
113+
key = "Files extracted - without errors" and
114+
value = count(SuccessfullyExtractedFile f | exists(f.getRelativePath()))
115+
or
116+
key = "Files extracted - without errors %" and
117+
value =
118+
(count(SuccessfullyExtractedFile f | exists(f.getRelativePath())) * 100) /
119+
count(ExtractedFile f | exists(f.getRelativePath()))
120+
or
121+
key = "Lines of code extracted" and value = getLinesOfCode()
122+
or
123+
key = "Lines of user code extracted" and value = getLinesOfUserCode()
124+
or
125+
key = "Macro calls - total" and value = count(MacroCall mc)
126+
or
127+
key = "Macro calls - resolved" and value = count(MacroCall mc | mc.hasExpanded())
128+
or
129+
key = "Macro calls - unresolved" and value = count(MacroCall mc | not mc.hasExpanded())
130+
}
131+
132+
/**
133+
* Gets summary statistics about inconsistencies.
134+
*/
135+
predicate inconsistencyStats(string key, int value) {
136+
key = "Inconsistencies - AST" and value = getTotalAstInconsistencies()
137+
or
138+
key = "Inconsistencies - Path resolution" and value = getTotalPathResolutionInconsistencies()
139+
or
140+
key = "Inconsistencies - CFG" and value = getTotalCfgInconsistencies()
141+
or
142+
key = "Inconsistencies - data flow" and value = getTotalDataFlowInconsistencies()
143+
}
144+
145+
/**
146+
* Gets summary statistics about taint.
147+
*/
148+
predicate taintStats(string key, int value) {
149+
key = "Taint sources - active" and value = count(ActiveThreatModelSource s)
150+
or
151+
key = "Taint sources - disabled" and
152+
value = count(ThreatModelSource s | not s instanceof ActiveThreatModelSource)
153+
or
154+
key = "Taint sources - sensitive data" and value = count(SensitiveData d)
155+
or
156+
key = "Taint edges - number of edges" and value = getTaintEdgesCount()
157+
or
158+
key = "Taint reach - nodes tainted" and value = getTaintedNodesCount()
159+
or
160+
key = "Taint reach - per million nodes" and value = getTaintReach().floor()
161+
or
162+
key = "Taint sinks - query sinks" and value = getQuerySinksCount()
163+
or
164+
key = "Taint sinks - cryptographic operations" and
165+
value = count(Cryptography::CryptographicOperation o)
166+
}

Diff for: rust/ql/src/queries/summary/SummaryStats.ql

+4-70
Original file line numberDiff line numberDiff line change
@@ -7,81 +7,15 @@
77
*/
88

99
import rust
10-
import codeql.rust.Concepts
11-
import codeql.rust.security.SensitiveData
12-
import codeql.rust.security.WeakSensitiveDataHashingExtensions
13-
import codeql.rust.Diagnostics
1410
import Stats
15-
import TaintReach
16-
17-
class CrateElement extends Element {
18-
CrateElement() {
19-
this instanceof Crate or
20-
this instanceof NamedCrate or
21-
this.(AstNode).getParentNode*() = any(Crate c).getModule()
22-
}
23-
}
2411

2512
from string key, int value
2613
where
27-
key = "Elements extracted" and
28-
value = count(Element e | not e instanceof Unextracted and not e instanceof CrateElement)
29-
or
30-
key = "Elements unextracted" and value = count(Unextracted e)
31-
or
32-
key = "Extraction errors" and value = count(ExtractionError e)
33-
or
34-
key = "Extraction warnings" and value = count(ExtractionWarning w)
35-
or
36-
key = "Files extracted - total" and value = count(ExtractedFile f | exists(f.getRelativePath()))
37-
or
38-
key = "Files extracted - with errors" and
39-
value =
40-
count(ExtractedFile f |
41-
exists(f.getRelativePath()) and not f instanceof SuccessfullyExtractedFile
42-
)
43-
or
44-
key = "Files extracted - without errors" and
45-
value = count(SuccessfullyExtractedFile f | exists(f.getRelativePath()))
46-
or
47-
key = "Files extracted - without errors %" and
48-
value =
49-
(count(SuccessfullyExtractedFile f | exists(f.getRelativePath())) * 100) /
50-
count(ExtractedFile f | exists(f.getRelativePath()))
51-
or
52-
key = "Lines of code extracted" and value = getLinesOfCode()
53-
or
54-
key = "Lines of user code extracted" and value = getLinesOfUserCode()
55-
or
56-
key = "Inconsistencies - AST" and value = getTotalAstInconsistencies()
57-
or
58-
key = "Inconsistencies - Path resolution" and value = getTotalPathResolutionInconsistencies()
59-
or
60-
key = "Inconsistencies - CFG" and value = getTotalCfgInconsistencies()
61-
or
62-
key = "Inconsistencies - data flow" and value = getTotalDataFlowInconsistencies()
63-
or
64-
key = "Macro calls - total" and value = count(MacroCall mc)
65-
or
66-
key = "Macro calls - resolved" and value = count(MacroCall mc | mc.hasExpanded())
67-
or
68-
key = "Macro calls - unresolved" and value = count(MacroCall mc | not mc.hasExpanded())
69-
or
70-
key = "Taint sources - active" and value = count(ActiveThreatModelSource s)
71-
or
72-
key = "Taint sources - disabled" and
73-
value = count(ThreatModelSource s | not s instanceof ActiveThreatModelSource)
74-
or
75-
key = "Taint sources - sensitive data" and value = count(SensitiveData d)
76-
or
77-
key = "Taint edges - number of edges" and value = getTaintEdgesCount()
78-
or
79-
key = "Taint reach - nodes tainted" and value = getTaintedNodesCount()
14+
elementStats(key, value)
8015
or
81-
key = "Taint reach - per million nodes" and value = getTaintReach().floor()
16+
extractionStats(key, value)
8217
or
83-
key = "Taint sinks - query sinks" and value = getQuerySinksCount()
18+
inconsistencyStats(key, value)
8419
or
85-
key = "Taint sinks - cryptographic operations" and
86-
value = count(Cryptography::CryptographicOperation o)
20+
taintStats(key, value)
8721
select key, value order by key

Diff for: rust/ql/src/queries/summary/SummaryStatsReduced.ql

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @name Summary Statistics Reduced
3+
* @description A table of summary statistics about a database, with data that
4+
* has been found to be noisy on tests removed.
5+
* @kind metric
6+
* @id rust/summary/reduced-summary-statistics
7+
* @tags summary
8+
*/
9+
10+
import rust
11+
import Stats
12+
13+
from string key, int value
14+
where
15+
extractionStats(key, value)
16+
or
17+
inconsistencyStats(key, value)
18+
select key, value order by key

Diff for: rust/ql/test/query-tests/diagnostics/SummaryStats.qlref

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
| Elements extracted | 406 |
2-
| Elements unextracted | 0 |
31
| Extraction errors | 0 |
42
| Extraction warnings | 7 |
53
| Files extracted - total | 7 |
@@ -15,11 +13,3 @@
1513
| Macro calls - resolved | 8 |
1614
| Macro calls - total | 9 |
1715
| Macro calls - unresolved | 1 |
18-
| Taint edges - number of edges | 1691 |
19-
| Taint reach - nodes tainted | 0 |
20-
| Taint reach - per million nodes | 0 |
21-
| Taint sinks - cryptographic operations | 0 |
22-
| Taint sinks - query sinks | 3 |
23-
| Taint sources - active | 0 |
24-
| Taint sources - disabled | 0 |
25-
| Taint sources - sensitive data | 0 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
queries/summary/SummaryStatsReduced.ql

0 commit comments

Comments
 (0)