Skip to content

Commit

Permalink
optimize allocations on source check spam
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryRomanov committed Dec 24, 2024
1 parent 61b2602 commit 3b8ac5b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pipeline/antispam/antispammer.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func NewAntispammer(o *Options) *Antispammer {
return a
}

func (a *Antispammer) IsSpam(id any, name string, isNewSource bool, event []byte, timeEvent time.Time) bool {
func (a *Antispammer) IsSpam(id string, name string, isNewSource bool, event []byte, timeEvent time.Time) bool {
if a.threshold <= 0 {
return false
}
Expand Down
6 changes: 3 additions & 3 deletions pipeline/antispam/antispammer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestAntispam(t *testing.T) {
startTime := time.Now()
checkSpam := func(i int) bool {
eventTime := startTime.Add(time.Duration(i) * maintenanceInterval / 2)
return antispamer.IsSpam(1, "test", false, []byte(`{}`), eventTime)
return antispamer.IsSpam("1", "test", false, []byte(`{}`), eventTime)
}

for i := 1; i < threshold; i++ {
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestAntispamAfterRestart(t *testing.T) {
startTime := time.Now()
checkSpam := func(i int) bool {
eventTime := startTime.Add(time.Duration(i) * maintenanceInterval)
return antispamer.IsSpam(1, "test", false, []byte(`{}`), eventTime)
return antispamer.IsSpam("1", "test", false, []byte(`{}`), eventTime)
}

for i := 1; i < threshold; i++ {
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestAntispamExceptions(t *testing.T) {
antispamer.exceptions.Prepare()

checkSpam := func(source, event string, wantMetric map[string]float64) {
antispamer.IsSpam(1, source, true, []byte(event), now)
antispamer.IsSpam("1", source, true, []byte(event), now)
for k, v := range wantMetric {
r.Equal(v, testutil.ToFloat64(antispamer.exceptionMetric.WithLabelValues(k)))
}
Expand Down
6 changes: 3 additions & 3 deletions pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,10 @@ func (p *Pipeline) In(sourceID SourceID, sourceName string, offsets Offsets, byt
return EventSeqIDError
}

var checkSourceID any
var checkSourceID string
var checkSourceName string
if p.settings.SourceNameMetaField == "" {
checkSourceID = uint64(sourceID)
checkSourceID = strconv.FormatUint(uint64(sourceID), 10)
checkSourceName = sourceName
} else {
if val, ok := meta[p.settings.SourceNameMetaField]; ok {
Expand All @@ -479,7 +479,7 @@ func (p *Pipeline) In(sourceID SourceID, sourceName string, offsets Offsets, byt
isNewSource = false
} else {
p.Error(fmt.Sprintf("source_name_meta_field %q does not exists in meta", p.settings.SourceNameMetaField))
checkSourceID = uint64(sourceID)
checkSourceID = strconv.FormatUint(uint64(sourceID), 10)
checkSourceName = sourceName
}
}
Expand Down

0 comments on commit 3b8ac5b

Please sign in to comment.