mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Merge pull request #11251 from igfoo/igfoo/total
Kotlin: Add total number of diagnostics to telemetry
This commit is contained in:
@@ -138,6 +138,10 @@ open class LoggerBase(val logCounter: LogCounter) {
|
|||||||
fullMsgBuilder.append(suffix)
|
fullMsgBuilder.append(suffix)
|
||||||
|
|
||||||
val fullMsg = fullMsgBuilder.toString()
|
val fullMsg = fullMsgBuilder.toString()
|
||||||
|
emitDiagnostic(tw, severity, diagnosticLocStr, msg, fullMsg, locationString, mkLocationId)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun emitDiagnostic(tw: TrapWriter, severity: Severity, diagnosticLocStr: String, msg: String, fullMsg: String, locationString: String? = null, mkLocationId: () -> Label<DbLocation> = { tw.unknownLocation }) {
|
||||||
val locStr = if (locationString == null) "" else "At " + locationString + ": "
|
val locStr = if (locationString == null) "" else "At " + locationString + ": "
|
||||||
val kind = if (severity <= Severity.WarnHigh) "WARN" else "ERROR"
|
val kind = if (severity <= Severity.WarnHigh) "WARN" else "ERROR"
|
||||||
val logMessage = LogMessage(kind, "Diagnostic($diagnosticLocStr): $locStr$fullMsg")
|
val logMessage = LogMessage(kind, "Diagnostic($diagnosticLocStr): $locStr$fullMsg")
|
||||||
@@ -190,9 +194,10 @@ open class LoggerBase(val logCounter: LogCounter) {
|
|||||||
// We don't know if this location relates to an error
|
// We don't know if this location relates to an error
|
||||||
// or a warning, so we just declare hitting the limit
|
// or a warning, so we just declare hitting the limit
|
||||||
// to be an error regardless.
|
// to be an error regardless.
|
||||||
val logMessage = LogMessage("ERROR", "Total of $count diagnostics from $caller.")
|
val message = "Total of $count diagnostics (reached limit of ${logCounter.diagnosticLimit}) from $caller."
|
||||||
tw.writeComment(logMessage.toText())
|
if (verbosity >= 1) {
|
||||||
logStream.write(logMessage.toJsonLine())
|
emitDiagnostic(tw, Severity.Error, "Limit", message, message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,29 @@ predicate extractorDiagnostics(string key, int value) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Just counting the diagnostics doesn't give the full picture, as
|
||||||
|
* CODEQL_EXTRACTOR_KOTLIN_DIAGNOSTIC_LIMIT means that some diagnostics
|
||||||
|
* will be suppressed. In that case, we need to look for the
|
||||||
|
* suppression message, uncount those that did get emitted, uncount the
|
||||||
|
* suppression message itself, and then add on the full count.
|
||||||
|
*/
|
||||||
|
|
||||||
|
predicate extractorTotalDiagnostics(string key, int value) {
|
||||||
|
exists(string extractor, string limitRegex |
|
||||||
|
limitRegex = "Total of ([0-9]+) diagnostics \\(reached limit of ([0-9]+)\\).*" and
|
||||||
|
key = "Total number of diagnostics from " + extractor and
|
||||||
|
value =
|
||||||
|
strictcount(Diagnostic d | d.getGeneratedBy() = extractor) +
|
||||||
|
sum(Diagnostic d |
|
||||||
|
d.getGeneratedBy() = extractor
|
||||||
|
|
|
||||||
|
d.getMessage().regexpCapture(limitRegex, 1).toInt() -
|
||||||
|
d.getMessage().regexpCapture(limitRegex, 2).toInt() - 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
from string key, int value
|
from string key, int value
|
||||||
where
|
where
|
||||||
compilationInfo(key, value) or
|
compilationInfo(key, value) or
|
||||||
@@ -69,5 +92,6 @@ where
|
|||||||
numberOfLinesOfCode(key, value) or
|
numberOfLinesOfCode(key, value) or
|
||||||
totalNumberOfLinesByExtension(key, value) or
|
totalNumberOfLinesByExtension(key, value) or
|
||||||
numberOfLinesOfCodeByExtension(key, value) or
|
numberOfLinesOfCodeByExtension(key, value) or
|
||||||
extractorDiagnostics(key, value)
|
extractorDiagnostics(key, value) or
|
||||||
|
extractorTotalDiagnostics(key, value)
|
||||||
select key, value
|
select key, value
|
||||||
|
|||||||
Reference in New Issue
Block a user