feat: integrate Drain3-style log template mining into audit report and logs#24328
feat: integrate Drain3-style log template mining into audit report and logs#24328
Conversation
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/850383e4-6ce1-4a3d-aa07-dae32343caa6 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/850383e4-6ce1-4a3d-aa07-dae32343caa6 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/850383e4-6ce1-4a3d-aa07-dae32343caa6 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
add a flag "--train" to the "logs" command that runs the drain3 pre training to build the weights file which should be embedded to the compiler as default |
|
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/621cd144-30cc-44cd-9e7c-37361cee1b70 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…return train error Agent-Logs-Url: https://github.com/github/gh-aw/sessions/621cd144-30cc-44cd-9e7c-37361cee1b70 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Done in commit
How it works:
Embedding as default: The |
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/1361e355-3eb5-4c65-9f64-ee483320bd65 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/1361e355-3eb5-4c65-9f64-ee483320bd65 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Done in commit Drain3 multi-run pattern analysis is now part of What was added:
Markdown output example: ## Agent Event Pattern Analysis (Drain3)
### ℹ Log template patterns mined
**Category:** execution | **Severity:** info
Drain3 analysis identified 4 distinct event templates across 3 pipeline stages from 12 events.
_Evidence:_ `error=1 plan=1 tool_call=2` |
|
@copilot don't mention drain3 in report (internal detail) |
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/89ebe149-2934-400a-a97e-a8f73ee6bbe4 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Done in commit |
Summary
Implements a production-oriented Drain3-style log template mining module and integrates it into the
gh aw audit,gh aw audit report, andgh aw logsobservability pipeline. Includes a--trainflag on thelogscommand to build and embed default weights.What this PR does
New package:
pkg/agentdrainA standalone, zero-dependency Go package implementing online Drain3-style log template mining, specifically designed for agent session observability:
types.goConfig,MaskRule,Cluster,MatchResult,AnomalyReport,AgentEventconfig.goDefaultConfig()with sensible defaults and built-in masking rulesmask.goMasker(UUID, session ID, number, URL, timestamp, quoted-string),FlattenEvent,Tokenizetree.gocluster.goclusterStore,computeSimilarity,mergeTemplateminer.goMiner:Train/Match/TrainEvent/AnalyzeEventanomaly.goAnomalyDetector— weighted anomaly score (new=1.0, low-sim=0.7, rare=0.3)pretrain.goPreTrainTemplate/PreTrainTemplates/PreTrainTemplateCountspersist.goSaveJSON/LoadJSON/LoadMinerJSONcoordinator.goCoordinator(plan, tool_call, tool_result, retry, error, finish) +StageSequence+SaveWeightsJSON/LoadWeightsJSONdefaults.godata/default_weights.json;LoadDefaultWeights()preloads embedded templatesminer_test.goanomaly_test.goNew:
pkg/cli/drain3_integration.goIntegration layer connecting
pkg/agentdrainto the existing audit pipeline. Coordinators callLoadDefaultWeights()on startup so trained templates are available immediately:buildDrain3Insights(processedRun, metrics, toolUsage)— converts a single run's structured data intoAgentEvents, mines templates, and returnsObservabilityInsights covering cluster summary, anomaly report, and stage sequence evidence.buildDrain3InsightsMultiRun(processedRuns)— same for cross-run analysis with a shared coordinator, detecting patterns across ≤50 runs.buildDrain3InsightsFromCrossRunInputs(inputs)— convertscrossRunInputentries toProcessedRuns and delegates tobuildDrain3InsightsMultiRun, used by theaudit reportsubcommand.New:
pkg/cli/drain3_train.goTrainDrain3Weights(processedRuns, outputDir, verbose)trains a Drain3 coordinator across all processed runs and writesdrain3_weights.jsonto the output directory. The file can be committed topkg/agentdrain/data/default_weights.jsonand rebuilt to embed it as the binary default.Modified:
pkg/cli/logs_command.go—--trainflagWhen
--trainis set,DownloadWorkflowLogsrunsTrainDrain3Weightsafter processing all runs and returns an error if training fails.Modified:
pkg/cli/audit_report.goAppends Drain3 insights to
ObservabilityInsightsinbuildAuditData():Modified:
pkg/cli/logs_report.goAppends Drain3 multi-run insights to
ObservabilityinBuildLogsData():Modified:
pkg/cli/audit_cross_run.go—gh aw audit reportintegrationCrossRunAuditReportnow includes adrain3_insightsfield ([]ObservabilityInsight). Phase 7 ofbuildCrossRunAuditReportcallsbuildDrain3InsightsFromCrossRunInputsto mine event templates across all runs in the report. Both markdown and pretty renderers include an "Agent Event Pattern Analysis (Drain3)" section with severity icons (🔴/🟠/🟡/ℹ), category labels, summaries, and evidence strings.New:
cmd/agentdrain-demo/main.goRunnable demo that shows the full pipeline: coordinator setup → pretraining → event ingestion → cluster/template/param/anomaly output → snapshot save/reload → post-restore inference.
Embedding default weights workflow
gh aw logs --train -c 100 cp .github/aw/logs/drain3_weights.json pkg/agentdrain/data/default_weights.json make build # re-embeds the trained weights into the binaryAfter this, all future
gh aw auditandgh aw logsruns preload those templates into the Drain3 coordinator before processing new events, giving better anomaly detection from the first observation.Testing
pkg/agentdrain/— all passpkg/cli/drain3_integration_test.go— all passpkg/cli/drain3_train_test.go— all pass (including--trainflag presence, JSON structure, stage key assertions)pkg/cli/audit_cross_run_test.go— all pass (field-mapping assertions, insight field validation, markdown rendering)make lint— 0 issuesmake test-unit— all pre-existing failures are unrelated (require live GitHub API access)Design decisions
sync.RWMutexthroughout;MatchusesRLock,Trainuses fullLock--trainreturns error — since the user explicitly requested training, failures are surfaced rather than silently warned