Skip to content

Commit 4f64876

Browse files
authored
agentdrain: remove duplicate NewClusterCreated field from AnomalyReport (#30938)
1 parent 6145596 commit 4f64876

5 files changed

Lines changed: 9 additions & 30 deletions

File tree

pkg/agentdrain/README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,11 @@ Describes anomalies detected for a log line.
8888

8989
```go
9090
type AnomalyReport struct {
91-
IsNewTemplate bool // Line created a new cluster
92-
LowSimilarity bool // Best match score was below SimThreshold
93-
RareCluster bool // Matched cluster has been seen ≤ RareClusterThreshold times
94-
NewClusterCreated bool // This event produced a brand-new cluster
95-
AnomalyScore float64 // Weighted composite score in [0, 1]
96-
Reason string // Human-readable anomaly description
91+
IsNewTemplate bool // Line produced a brand-new log cluster
92+
LowSimilarity bool // Best match score was below SimThreshold
93+
RareCluster bool // Matched cluster has been seen ≤ RareClusterThreshold times
94+
AnomalyScore float64 // Weighted composite score in [0, 1]
95+
Reason string // Human-readable anomaly description
9796
}
9897
```
9998

pkg/agentdrain/anomaly.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ func NewAnomalyDetector(simThreshold float64, rareClusterThreshold int) (*Anomal
3636
// - cluster is the cluster that was matched or created.
3737
func (d *AnomalyDetector) Analyze(result *MatchResult, isNew bool, cluster *Cluster) *AnomalyReport {
3838
report := &AnomalyReport{
39-
IsNewTemplate: isNew,
40-
NewClusterCreated: isNew,
39+
IsNewTemplate: isNew,
4140
// LowSimilarity is mutually exclusive with IsNewTemplate: brand-new templates are
4241
// already classified as anomalies, so we only evaluate similarity for existing ones.
4342
LowSimilarity: !isNew && result.Similarity < d.threshold,

pkg/agentdrain/anomaly_test.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ func TestAnomalyDetector_Analyze(t *testing.T) {
1818
isNew bool
1919
cluster *Cluster
2020
wantIsNewTemplate bool
21-
wantNewCluster bool
2221
wantLowSimilarity bool
2322
wantRareCluster bool
2423
wantScore float64
2524
wantReason string
2625
}{
2726
{
28-
// isNew=true → both IsNewTemplate and NewClusterCreated; size=1 ≤ rareThreshold=2 → RareCluster.
27+
// isNew=true → IsNewTemplate; size=1 ≤ rareThreshold=2 → RareCluster.
2928
// score = (1.0 + 0.3) / 2.0 = 0.65
3029
name: "new template creates cluster and is also rare",
3130
simThreshold: 0.4,
@@ -34,7 +33,6 @@ func TestAnomalyDetector_Analyze(t *testing.T) {
3433
isNew: true,
3534
cluster: &Cluster{ID: 1, Template: []string{"stage=plan"}, Size: 1},
3635
wantIsNewTemplate: true,
37-
wantNewCluster: true,
3836
wantLowSimilarity: false,
3937
wantRareCluster: true,
4038
wantScore: 0.65,
@@ -50,7 +48,6 @@ func TestAnomalyDetector_Analyze(t *testing.T) {
5048
isNew: false,
5149
cluster: &Cluster{ID: 1, Template: []string{"a", "b", "c"}, Size: 5},
5250
wantIsNewTemplate: false,
53-
wantNewCluster: false,
5451
wantLowSimilarity: true,
5552
wantRareCluster: false,
5653
wantScore: 0.35,
@@ -66,7 +63,6 @@ func TestAnomalyDetector_Analyze(t *testing.T) {
6663
isNew: false,
6764
cluster: &Cluster{ID: 1, Template: []string{"a"}, Size: 1},
6865
wantIsNewTemplate: false,
69-
wantNewCluster: false,
7066
wantLowSimilarity: false,
7167
wantRareCluster: true,
7268
wantScore: 0.15,
@@ -81,7 +77,6 @@ func TestAnomalyDetector_Analyze(t *testing.T) {
8177
isNew: false,
8278
cluster: &Cluster{ID: 1, Template: []string{"a", "b"}, Size: 100},
8379
wantIsNewTemplate: false,
84-
wantNewCluster: false,
8580
wantLowSimilarity: false,
8681
wantRareCluster: false,
8782
wantScore: 0.0,
@@ -96,7 +91,6 @@ func TestAnomalyDetector_Analyze(t *testing.T) {
9691
isNew: false,
9792
cluster: &Cluster{ID: 1, Template: []string{"a"}, Size: 5},
9893
wantIsNewTemplate: false,
99-
wantNewCluster: false,
10094
wantLowSimilarity: false,
10195
wantRareCluster: false,
10296
wantScore: 0.0,
@@ -112,7 +106,6 @@ func TestAnomalyDetector_Analyze(t *testing.T) {
112106
isNew: false,
113107
cluster: &Cluster{ID: 1, Template: []string{"a"}, Size: 5},
114108
wantIsNewTemplate: false,
115-
wantNewCluster: false,
116109
wantLowSimilarity: true,
117110
wantRareCluster: false,
118111
wantScore: 0.35,
@@ -128,7 +121,6 @@ func TestAnomalyDetector_Analyze(t *testing.T) {
128121
isNew: false,
129122
cluster: &Cluster{ID: 1, Template: []string{"a"}, Size: 1},
130123
wantIsNewTemplate: false,
131-
wantNewCluster: false,
132124
wantLowSimilarity: true,
133125
wantRareCluster: true,
134126
wantScore: 0.5,
@@ -143,7 +135,6 @@ func TestAnomalyDetector_Analyze(t *testing.T) {
143135
isNew: false,
144136
cluster: nil,
145137
wantIsNewTemplate: false,
146-
wantNewCluster: false,
147138
wantLowSimilarity: false,
148139
wantRareCluster: false,
149140
wantScore: 0.0,
@@ -159,7 +150,6 @@ func TestAnomalyDetector_Analyze(t *testing.T) {
159150
isNew: true,
160151
cluster: &Cluster{ID: 1, Template: []string{"a"}, Size: 5},
161152
wantIsNewTemplate: true,
162-
wantNewCluster: true,
163153
wantLowSimilarity: false,
164154
wantRareCluster: true,
165155
wantScore: 0.65,
@@ -177,7 +167,6 @@ func TestAnomalyDetector_Analyze(t *testing.T) {
177167

178168
require.NotNil(t, report, "Analyze should always return a non-nil report")
179169
assert.Equal(t, tt.wantIsNewTemplate, report.IsNewTemplate, "IsNewTemplate mismatch")
180-
assert.Equal(t, tt.wantNewCluster, report.NewClusterCreated, "NewClusterCreated mismatch")
181170
assert.Equal(t, tt.wantLowSimilarity, report.LowSimilarity, "LowSimilarity mismatch")
182171
assert.Equal(t, tt.wantRareCluster, report.RareCluster, "RareCluster mismatch")
183172
assert.InDelta(t, tt.wantScore, report.AnomalyScore, 1e-9, "AnomalyScore mismatch")
@@ -342,28 +331,24 @@ func TestAnalyzeEvent(t *testing.T) {
342331
name string
343332
event AgentEvent
344333
wantIsNew bool
345-
wantNewCluster bool
346334
errorDescription string
347335
}{
348336
{
349337
name: "first occurrence is flagged as new template",
350338
event: evtPlan,
351339
wantIsNew: true,
352-
wantNewCluster: true,
353340
errorDescription: "first event",
354341
},
355342
{
356343
name: "second identical occurrence is not flagged as new",
357344
event: evtPlan,
358345
wantIsNew: false,
359-
wantNewCluster: false,
360346
errorDescription: "second identical event",
361347
},
362348
{
363349
name: "distinct event creates its own new template",
364350
event: evtFinish,
365351
wantIsNew: true,
366-
wantNewCluster: true,
367352
errorDescription: "distinct event",
368353
},
369354
}
@@ -375,7 +360,6 @@ func TestAnalyzeEvent(t *testing.T) {
375360
require.NotNil(t, result, "AnalyzeEvent should return a non-nil result")
376361
require.NotNil(t, report, "AnalyzeEvent should return a non-nil report")
377362
assert.Equal(t, tt.wantIsNew, report.IsNewTemplate, "IsNewTemplate mismatch")
378-
assert.Equal(t, tt.wantNewCluster, report.NewClusterCreated, "NewClusterCreated mismatch")
379363
})
380364
}
381365
}

pkg/agentdrain/spec_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ func TestSpec_Types_MatchResult(t *testing.T) {
425425
}
426426

427427
// TestSpec_Types_AnomalyReport validates the documented AnomalyReport type structure.
428-
// Spec: IsNewTemplate, LowSimilarity, RareCluster, NewClusterCreated, AnomalyScore in [0,1], Reason.
428+
// Spec: IsNewTemplate, LowSimilarity, RareCluster, AnomalyScore in [0,1], Reason.
429429
func TestSpec_Types_AnomalyReport(t *testing.T) {
430430
cfg := agentdrain.DefaultConfig()
431431
miner, err := agentdrain.NewMiner(cfg)
@@ -439,7 +439,6 @@ func TestSpec_Types_AnomalyReport(t *testing.T) {
439439
_ = report.IsNewTemplate
440440
_ = report.LowSimilarity
441441
_ = report.RareCluster
442-
_ = report.NewClusterCreated
443442
_ = report.Reason
444443
assert.GreaterOrEqual(t, report.AnomalyScore, 0.0, "AnomalyReport.AnomalyScore should be in documented range [0, 1]")
445444
assert.LessOrEqual(t, report.AnomalyScore, 1.0, "AnomalyReport.AnomalyScore should be in documented range [0, 1]")

pkg/agentdrain/types.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,12 @@ type MatchResult struct {
5656

5757
// AnomalyReport describes anomalies detected for a log line.
5858
type AnomalyReport struct {
59-
// IsNewTemplate is true when the log line created a new cluster.
59+
// IsNewTemplate is true when the log line produced a brand-new log cluster.
6060
IsNewTemplate bool
6161
// LowSimilarity is true when the best match score was below the configured threshold.
6262
LowSimilarity bool
6363
// RareCluster is true when the matched cluster has been seen fewer times than the rare threshold.
6464
RareCluster bool
65-
// NewClusterCreated is true when this event produced a brand-new cluster.
66-
NewClusterCreated bool
6765
// AnomalyScore is a weighted composite score in the range [0, 1].
6866
AnomalyScore float64
6967
// Reason is a human-readable description of all anomalies that were detected.

0 commit comments

Comments
 (0)