Conversation
There was a problem hiding this comment.
Code Review
This pull request restructures the CLI command hierarchy by moving endpoint-related commands under a new endpoint parent command and introduces a GraphQL operation audit logging system. The audit system records executed queries and mutations to a local log file, which can be inspected using the new audit list command. Feedback focuses on improving the robustness and performance of the audit log parser, specifically by handling corrupted log lines gracefully and reducing memory allocations during scanning.
| if err := json.Unmarshal([]byte(line), &entry); err != nil { | ||
| return nil, fmt.Errorf("parse audit log line %d: %w", lineNumber, err) | ||
| } |
There was a problem hiding this comment.
A single malformed or corrupted line in the audit log will cause the entire audit list command to fail. It would be more robust to log a warning to stderr and continue parsing the remaining entries.
| if err := json.Unmarshal([]byte(line), &entry); err != nil { | |
| return nil, fmt.Errorf("parse audit log line %d: %w", lineNumber, err) | |
| } | |
| if err := json.Unmarshal(line, &entry); err != nil { | |
| fmt.Fprintf(os.Stderr, "warning: skipping corrupted audit log line %d: %v\n", lineNumber, err) | |
| continue | |
| } |
| for scanner.Scan() { | ||
| lineNumber++ | ||
|
|
||
| line := strings.TrimSpace(scanner.Text()) |
There was a problem hiding this comment.
Using scanner.Text() followed by strings.TrimSpace creates unnecessary string allocations. Using scanner.Bytes() and bytes.TrimSpace is more efficient as json.Unmarshal accepts a byte slice.
| line := strings.TrimSpace(scanner.Text()) | |
| line := bytes.TrimSpace(scanner.Bytes()) | |
| if len(line) == 0 { | |
| continue | |
| } |
No description provided.