Repository navigation
refactor(logutil): standardize KLogTextParser and reconstruct full klog lines for control plane logs - #1162
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the KLogTextParser by removing the hasHeader option to unify parsing behavior, and introduces a FormatKLogString utility to reconstruct klog-formatted lines from structured log fields. GKE control plane extractors have been updated to reconstruct and parse logs using this new utility, and all test cases and parser configurations have been adapted accordingly. The review feedback highlights a critical issue in toKLogSeverityLetter where pointer addresses are compared directly instead of dereferencing them, which is fragile and can cause incorrect severity fallbacks.
|
/gcbrun |
|
/gcbrun |
|
sounds good. I saw you've started to work on MCP. If any issue arises, I'd love to work! I'm gonna keep an eye 👀 |
67c1218
Background & Problem
KLogTextParsertook ahasHeader boolflag so it could parse GKE control plane component logs, where Cloud Logging moves the klog header into structured fields (severity,timestamp,sourceLocation) and leaves only the message body injsonPayload.message. Supporting headerless input made the parser responsible for two formats.Fixes #846
Solution Approach
logutil.FormatKLogString: Builds a standard klog line ([IWEF]mmdd hh:mm:ss.uuuuuu threadid file:line] msg) from structured fields.ExtractK8sSchedulerComponentandK8sControllerManagerComponentExtractor.Extractrebuild the full line before parsing.KLogTextParser:hasHeaderis removed, along with the headerless parser entries ink8scontrolplane/parser.go. All call sites are updated.Differences from the signature proposed in the issue:
*pb.Severityinstead of a severity string. Callers map Cloud Logging severities with the existinggcpcommon.ExtractGCPSeverity, sologutilstays independent of Cloud Logging.time.Timeinstead of a timestamp string, matchingNodeReader.ReadTimestamp. The timestamp is converted to UTC.Fallbacks, so that logs with missing fields still parse instead of being dropped:
I, because klog has only four levels and the header regex accepts onlyIWEF.sourceLocation.fileis written asunknown, because the header requiresfile:line.sourceLocation.lineis read as a string and converted withstrconv.Atoi, because protojson serializesint64as a string andReadIntOrDefaultwould silently return0.