Skip to content

Commit d5eebc8

Browse files
committed
C#: Add a parameterized module for a telemetry result ordering predicate (will be needed to narrow the number of produced results).
1 parent f7cc46b commit d5eebc8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

csharp/ql/src/Telemetry/ExternalApi.qll

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,32 @@ class ExternalApi extends DotNet::Callable {
107107
/** Holds if this API is supported by existing CodeQL libraries, that is, it is either a recognized source or sink or has a flow summary. */
108108
predicate isSupported() { this.hasSummary() or this.isSource() or this.isSink() }
109109
}
110+
111+
/**
112+
* A limit for the number of results produced by a telemetry query.
113+
*/
114+
int resultLimit() { result = 1000 }
115+
116+
/**
117+
* A predicate signature for relevant usage counts of an External API `api`.
118+
*/
119+
signature predicate relevantUsagesSig(ExternalApi api, int usages);
120+
121+
/**
122+
* Given a predicate to count relevant API usages, this module provides a predicate
123+
* for restricting the number or returned results based on a certain limit.
124+
*/
125+
module Results<relevantUsagesSig/2 getRelevantUsages> {
126+
private int getOrder(ExternalApi api) {
127+
api =
128+
rank[result](ExternalApi a, int usages |
129+
getRelevantUsages(a, usages)
130+
|
131+
a order by usages desc, a.getInfo()
132+
)
133+
}
134+
135+
predicate restrict(ExternalApi api, int usages) {
136+
getRelevantUsages(api, usages) and getOrder(api) <= resultLimit()
137+
}
138+
}

0 commit comments

Comments
 (0)