From 9cf3b3028b1317d670a9af23d831704b80c1d350 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 7 May 2026 20:07:43 +0000 Subject: [PATCH 1/2] Initial plan From cdaeac7fe3c8fd1ce3f8d54ab54281a58bd40e7f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 7 May 2026 20:14:48 +0000 Subject: [PATCH 2/2] =?UTF-8?q?refactor(agentdrain):=20rename=20match?= =?UTF-8?q?=E2=86=92findBestMatchingCluster=20and=20firstKey=E2=86=92compu?= =?UTF-8?q?teTreeBucketKey?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agent-Logs-Url: https://github.com/github/gh-aw/sessions/05ac3666-2e05-4f02-8869-cffcf42dd364 Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com> --- pkg/agentdrain/miner.go | 14 +++++++------- pkg/agentdrain/tree.go | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/agentdrain/miner.go b/pkg/agentdrain/miner.go index 710dc27b375..6983678facb 100644 --- a/pkg/agentdrain/miner.go +++ b/pkg/agentdrain/miner.go @@ -48,7 +48,7 @@ func (m *Miner) Train(line string) (*MatchResult, error) { m.mu.Lock() defer m.mu.Unlock() - result, _ := m.match(tokens) + result, _ := m.findBestMatchingCluster(tokens) if result != nil { // Merge and update existing cluster. c, _ := m.store.get(result.ClusterID) @@ -73,10 +73,10 @@ func (m *Miner) Train(line string) (*MatchResult, error) { }, nil } -// match is the internal (non-locking) lookup. Must be called with mu held. -func (m *Miner) match(tokens []string) (*MatchResult, bool) { +// findBestMatchingCluster is the internal (non-locking) lookup. Must be called with mu held. +func (m *Miner) findBestMatchingCluster(tokens []string) (*MatchResult, bool) { candidates := m.tree.search(tokens, m.cfg.Depth, m.cfg.ParamToken) - minerLog.Printf("match: searching %d candidate cluster(s) for %d token(s)", len(candidates), len(tokens)) + minerLog.Printf("findBestMatchingCluster: searching %d candidate cluster(s) for %d token(s)", len(candidates), len(tokens)) bestSim := -1.0 var best *Cluster for _, id := range candidates { @@ -91,11 +91,11 @@ func (m *Miner) match(tokens []string) (*MatchResult, bool) { } } if best == nil || bestSim < m.cfg.SimThreshold { - minerLog.Printf("match: no cluster matched (best_sim=%.2f, threshold=%.2f)", bestSim, m.cfg.SimThreshold) + minerLog.Printf("findBestMatchingCluster: no cluster matched (best_sim=%.2f, threshold=%.2f)", bestSim, m.cfg.SimThreshold) return nil, false } params := extractParams(tokens, best.Template, m.cfg.ParamToken) - minerLog.Printf("match: matched cluster id=%d, similarity=%.2f, params=%d", best.ID, bestSim, len(params)) + minerLog.Printf("findBestMatchingCluster: matched cluster id=%d, similarity=%.2f, params=%d", best.ID, bestSim, len(params)) return &MatchResult{ ClusterID: best.ID, Template: strings.Join(best.Template, " "), @@ -135,7 +135,7 @@ func (m *Miner) AnalyzeEvent(evt AgentEvent) (*MatchResult, *AnomalyReport, erro } m.mu.RLock() - inferResult, _ := m.match(tokens) + inferResult, _ := m.findBestMatchingCluster(tokens) m.mu.RUnlock() isNew := inferResult == nil diff --git a/pkg/agentdrain/tree.go b/pkg/agentdrain/tree.go index f16bf58d446..53e053b041a 100644 --- a/pkg/agentdrain/tree.go +++ b/pkg/agentdrain/tree.go @@ -35,7 +35,7 @@ func (t *parseTree) addCluster(tokens []string, clusterID int, depth int, maxChi if t.root[n] == nil { t.root[n] = make(map[string]*treeNode) } - key := t.firstKey(tokens, depth, paramToken) + key := t.computeTreeBucketKey(tokens, depth, paramToken) leaf := t.root[n][key] if leaf == nil { leaf = newTreeNode() @@ -53,7 +53,7 @@ func (t *parseTree) search(tokens []string, depth int, paramToken string) []int treeLog.Printf("Search: no clusters for token_count=%d", n) return nil } - key := t.firstKey(tokens, depth, paramToken) + key := t.computeTreeBucketKey(tokens, depth, paramToken) leaf, ok := byCount[key] if !ok { // Also try the wildcard bucket. @@ -69,9 +69,9 @@ func (t *parseTree) search(tokens []string, depth int, paramToken string) []int return out } -// firstKey returns the routing key derived from the first meaningful token. +// computeTreeBucketKey returns the routing key derived from the first meaningful token. // When depth == 1, all lines with the same length share a single bucket. -func (t *parseTree) firstKey(tokens []string, depth int, paramToken string) string { +func (t *parseTree) computeTreeBucketKey(tokens []string, depth int, paramToken string) string { if depth <= 1 || len(tokens) == 0 { return "*" }