Skip to content

Commit 97610d2

Browse files
committed
Java: Add query for counting sink model instances
Also adds a more sensible ordering to the existing queries.
1 parent b7e4bd2 commit 97610d2

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

java/ql/src/Telemetry/AutomodelAlertSinkUtil.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class SinkModel extends TSinkModel {
7878
}
7979

8080
/** An expression that may correspond to a sink model. */
81-
private class PotentialSinkModelExpr extends Expr {
81+
class PotentialSinkModelExpr extends Expr {
8282
/**
8383
* Holds if this expression has the given signature. The signature should contain enough
8484
* information to determine a corresponding sink model, if one exists.

java/ql/src/Telemetry/AutomodelAlertSinks.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ from int alertCount, SinkModel s
1313
where sinkModelTally(alertCount, s) and s.getProvenance() = "ai-generated"
1414
select alertCount, s.getPackage() as package, s.getType() as type, s.getSubtypes() as subtypes,
1515
s.getName() as name, s.getSignature() as signature, s.getInput() as input, s.getExt() as ext,
16-
s.getKind() as kind, s.getProvenance() as provenance
16+
s.getKind() as kind, s.getProvenance() as provenance order by alertCount desc

java/ql/src/Telemetry/AutomodelAlertSinksPerQuery.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ where
1616
select queryId, alertCount, s.getPackage() as package, s.getType() as type,
1717
s.getSubtypes() as subtypes, s.getName() as name, s.getSignature() as signature,
1818
s.getInput() as input, s.getExt() as ext, s.getKind() as kind, s.getProvenance() as provenance
19+
order by queryId, alertCount desc
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @name Number of instances of each sink model
3+
* @description Counts the number of instances of `ai-generated` sink models.
4+
* @kind table
5+
* @id java/ml/metrics-count-instances-per-sink-model
6+
* @tags internal automodel metrics
7+
*/
8+
9+
private import java
10+
private import AutomodelAlertSinkUtil
11+
12+
from int instanceCount, SinkModel s
13+
where
14+
instanceCount = strictcount(PotentialSinkModelExpr p | p.getSinkModel() = s) and
15+
s.getProvenance() = "ai-generated"
16+
select instanceCount, s.getPackage() as package, s.getType() as type, s.getSubtypes() as subtypes,
17+
s.getName() as name, s.getSignature() as signature, s.getInput() as input, s.getExt() as ext,
18+
s.getKind() as kind, s.getProvenance() as provenance order by instanceCount desc

0 commit comments

Comments
 (0)