QL: Clean up structured logs module

Pushes it into an internal module and removes the abstract class.
This commit is contained in:
Taus
2023-02-22 11:07:48 +00:00
parent dffb12070e
commit 5304fe2bcb

View File

@@ -3,9 +3,8 @@ private import codeql_ql.ast.internal.TreeSitter
class Object extends JSON::Object {
JSON::Value getValue(string key) {
exists(JSON::Pair p |
p = this.getChild(_) and p.getKey().(JSON::String).getChild().getValue() = key
|
exists(JSON::Pair p | p = this.getChild(_) |
key = p.getKey().(JSON::String).getChild().getValue() and
result = p.getValue()
)
}
@@ -35,104 +34,106 @@ class Array extends JSON::Array {
Array getArray(int i) { result = this.getChild(i) }
}
abstract class LogEntry extends Object { }
module EvaluatorLog {
class Entry extends Object { }
class LogHeader extends LogEntry {
LogHeader() { this.getType() = "LOG_HEADER" }
class LogHeader extends Entry {
LogHeader() { this.getType() = "LOG_HEADER" }
string getCodeQLVersion() { result = this.getString("codeqlVersion") }
string getCodeQLVersion() { result = this.getString("codeqlVersion") }
string getLogVersion() { result = this.getString("logVersion") }
}
class QueryStarted extends LogEntry {
QueryStarted() { this.getType() = "QUERY_STARTED" }
string getQueryName() { result = this.getString("queryName") }
int getStage(int i) { result = this.getArray("stage").getNumber(i) }
}
class PredicateStarted extends LogEntry {
PredicateStarted() { this.getType() = "PREDICATE_STARTED" }
string getPredicateName() { result = this.getString("predicateName") }
string getPosition() { result = this.getString("position") }
string getPredicateType() { result = this.getString("predicateType") }
int getQueryCausingWork() { result = this.getNumber("queryCausingWork") }
string getRAHash() { result = this.getString("raHash") }
Object getRA() { result = this.getValue("ra") }
string getDependency(string key) { result = this.getObject("dependencies").getString(key) }
}
class PipelineStarted extends LogEntry {
PipelineStarted() { this.getType() = "PIPELINE_STARTED" }
int getPredicateStartEvent() { result = this.getNumber("predicateStartEvent") }
string getRAReference() { result = this.getString("raReference") }
}
class PipelineCompleted extends LogEntry {
PipelineCompleted() { this.getType() = "PIPELINE_COMPLETED" }
int getStartEvent() { result = this.getNumber("startEvent") }
string getRAReference() { result = this.getString("raReference") }
int getCount(int i) { result = this.getArray("counts").getNumber(i) }
int getDuplicationPercentage(int i) {
result = this.getArray("duplicationPercentages").getNumber(i)
string getLogVersion() { result = this.getString("logVersion") }
}
int getResultSize() { result = this.getNumber("resultSize") }
}
class QueryStarted extends Entry {
QueryStarted() { this.getType() = "QUERY_STARTED" }
class PredicateCompleted extends LogEntry {
PredicateCompleted() { this.getType() = "PREDICATE_COMPLETED" }
string getQueryName() { result = this.getString("queryName") }
int getStartEvent() { result = this.getNumber("startEvent") }
int getStage(int i) { result = this.getArray("stage").getNumber(i) }
}
int getResultSize() { result = this.getNumber("resultSize") }
}
class PredicateStarted extends Entry {
PredicateStarted() { this.getType() = "PREDICATE_STARTED" }
class QueryCompleted extends LogEntry {
QueryCompleted() { this.getType() = "QUERY_COMPLETED" }
string getPredicateName() { result = this.getString("predicateName") }
int getStartEvent() { result = this.getNumber("startEvent") }
string getPosition() { result = this.getString("position") }
string getTerminationType() { result = this.getString("terminationType") }
}
string getPredicateType() { result = this.getString("predicateType") }
class LogFooter extends LogEntry {
LogFooter() { this.getType() = "LOG_FOOTER" }
}
int getQueryCausingWork() { result = this.getNumber("queryCausingWork") }
class CacheLookup extends LogEntry {
CacheLookup() { this.getType() = "CACHE_LOOKUP" }
string getRAHash() { result = this.getString("raHash") }
int getRelationSize() { result = this.getNumber("relationSize") }
}
Object getRA() { result = this.getValue("ra") }
class SentinelEmpty extends LogEntry {
SentinelEmpty() { this.getType() = "SENTINEL_EMPTY" }
string getDependency(string key) { result = this.getObject("dependencies").getString(key) }
}
class PipelineStarted extends Entry {
PipelineStarted() { this.getType() = "PIPELINE_STARTED" }
int getPredicateStartEvent() { result = this.getNumber("predicateStartEvent") }
string getRAReference() { result = this.getString("raReference") }
}
class PipelineCompleted extends Entry {
PipelineCompleted() { this.getType() = "PIPELINE_COMPLETED" }
int getStartEvent() { result = this.getNumber("startEvent") }
string getRAReference() { result = this.getString("raReference") }
int getCount(int i) { result = this.getArray("counts").getNumber(i) }
int getDuplicationPercentage(int i) {
result = this.getArray("duplicationPercentages").getNumber(i)
}
int getResultSize() { result = this.getNumber("resultSize") }
}
class PredicateCompleted extends Entry {
PredicateCompleted() { this.getType() = "PREDICATE_COMPLETED" }
int getStartEvent() { result = this.getNumber("startEvent") }
int getResultSize() { result = this.getNumber("resultSize") }
}
class QueryCompleted extends Entry {
QueryCompleted() { this.getType() = "QUERY_COMPLETED" }
int getStartEvent() { result = this.getNumber("startEvent") }
string getTerminationType() { result = this.getString("terminationType") }
}
class LogFooter extends Entry {
LogFooter() { this.getType() = "LOG_FOOTER" }
}
class CacheLookup extends Entry {
CacheLookup() { this.getType() = "CACHE_LOOKUP" }
int getRelationSize() { result = this.getNumber("relationSize") }
}
class SentinelEmpty extends Entry {
SentinelEmpty() { this.getType() = "SENTINEL_EMPTY" }
}
}
// Stuff to test whether we've covered all event types
private File logFile() { result = any(LogHeader h).getLocation().getFile() }
private File logFile() { result = any(EvaluatorLog::LogHeader h).getLocation().getFile() }
private Object missing() {
result =
any(Object o |
o.getLocation().getFile() = logFile() and
not o instanceof LogEntry and
not o instanceof EvaluatorLog::Entry and
not exists(o.getParent().getParent()) // don't count nested objects
)
}