@@ -25,7 +25,7 @@ import (
2525
2626const (
2727 DefaultAntispamThreshold = 0
28- DefaultAntispamField = ""
28+ DefaultSourceNameMetaField = ""
2929 DefaultDecoder = "auto"
3030 DefaultIsStrict = false
3131 DefaultStreamField = "stream"
@@ -51,17 +51,17 @@ type finalizeFn = func(event *Event, notifyInput bool, backEvent bool)
5151
5252type InputPluginController interface {
5353 In (sourceID SourceID , sourceName string , offset int64 , data []byte , isNewSource bool , meta metadata.MetaData ) uint64
54- UseSpread () // don't use stream field and spread all events across all processors
55- DisableStreams () // don't use stream field
56- SuggestDecoder (t decoder.Type ) // set decoder type if pipeline uses "auto" value for decoder
57- IncReadOps () // inc read ops for metric
58- IncMaxEventSizeExceeded () // inc max event size exceeded counter
54+ UseSpread () // don't use stream field and spread all events across all processors
55+ DisableStreams () // don't use stream field
56+ SuggestDecoder (t decoder.Type ) // set decoder type if pipeline uses "auto" value for decoder
57+ IncReadOps () // inc read ops for metric
58+ IncMaxEventSizeExceeded (lvs ... string ) // inc max event size exceeded counter
5959}
6060
6161type ActionPluginController interface {
6262 Propagate (event * Event ) // throw held event back to pipeline
6363 Spawn (parent * Event , nodes []* insaneJSON.Node )
64- IncMaxEventSizeExceeded () // inc max event size exceeded counter
64+ IncMaxEventSizeExceeded (lvs ... string ) // inc max event size exceeded counter
6565}
6666
6767type OutputPluginController interface {
@@ -130,7 +130,7 @@ type Pipeline struct {
130130 outputEventSizeMetric prometheus.Counter
131131 readOpsEventsSizeMetric prometheus.Counter
132132 wrongEventCRIFormatMetric prometheus.Counter
133- maxEventSizeExceededMetric prometheus.Counter
133+ maxEventSizeExceededMetric * prometheus.CounterVec
134134 eventPoolLatency prometheus.Observer
135135
136136 countEventPanicsRecoveredMetric prometheus.Counter
@@ -144,8 +144,8 @@ type Settings struct {
144144 MaintenanceInterval time.Duration
145145 EventTimeout time.Duration
146146 AntispamThreshold int
147- AntispamField string
148147 AntispamExceptions antispam.Exceptions
148+ SourceNameMetaField string
149149 AvgEventSize int
150150 MaxEventSize int
151151 CutOffEventByLimit bool
@@ -183,7 +183,6 @@ func New(name string, settings *Settings, registry *prometheus.Registry) *Pipeli
183183 antispamer : antispam .NewAntispammer (& antispam.Options {
184184 MaintenanceInterval : settings .MaintenanceInterval ,
185185 Threshold : settings .AntispamThreshold ,
186- Field : settings .AntispamField ,
187186 UnbanIterations : antispamUnbanIterations ,
188187 Logger : lg .Named ("antispam" ),
189188 MetricsController : metricCtl ,
@@ -242,8 +241,8 @@ func (p *Pipeline) IncReadOps() {
242241 p .readOps .Inc ()
243242}
244243
245- func (p * Pipeline ) IncMaxEventSizeExceeded () {
246- p .maxEventSizeExceededMetric .Inc ()
244+ func (p * Pipeline ) IncMaxEventSizeExceeded (lvs ... string ) {
245+ p .maxEventSizeExceededMetric .WithLabelValues ( lvs ... ). Inc ()
247246}
248247
249248func (p * Pipeline ) IncCountEventPanicsRecovered () {
@@ -260,7 +259,7 @@ func (p *Pipeline) registerMetrics() {
260259 p .outputEventSizeMetric = m .RegisterCounter ("output_events_size" , "Size of events on pipeline output" )
261260 p .readOpsEventsSizeMetric = m .RegisterCounter ("read_ops_count" , "Read OPS count" )
262261 p .wrongEventCRIFormatMetric = m .RegisterCounter ("wrong_event_cri_format" , "Wrong event CRI format counter" )
263- p .maxEventSizeExceededMetric = m .RegisterCounter ("max_event_size_exceeded" , "Max event size exceeded counter" )
262+ p .maxEventSizeExceededMetric = m .RegisterCounterVec ("max_event_size_exceeded" , "Max event size exceeded counter" , "source_name " )
264263 p .countEventPanicsRecoveredMetric = m .RegisterCounter ("count_event_panics_recovered" , "Count of processor.countEvent panics recovered" )
265264 p .eventPoolLatency = m .RegisterHistogram ("event_pool_latency_seconds" ,
266265 "How long we are wait an event from the pool" , metric .SecondsBucketsDetailedNano )
@@ -389,7 +388,7 @@ func (p *Pipeline) GetOutput() OutputPlugin {
389388func (p * Pipeline ) In (sourceID SourceID , sourceName string , offset int64 , bytes []byte , isNewSource bool , meta metadata.MetaData ) (seqID uint64 ) {
390389 // don't process mud.
391390 var ok bool
392- bytes , ok = p .checkInputBytes (bytes )
391+ bytes , ok = p .checkInputBytes (bytes , sourceName , meta )
393392 if ! ok {
394393 return EventSeqIDError
395394 }
@@ -432,16 +431,16 @@ func (p *Pipeline) In(sourceID SourceID, sourceName string, offset int64, bytes
432431 if ! row .IsPartial && p .settings .AntispamThreshold > 0 {
433432 var checkSourceID any
434433 var checkSourceName string
435- if p .settings .AntispamField == "" {
434+ if p .settings .SourceNameMetaField == "" {
436435 checkSourceID = uint64 (sourceID )
437436 checkSourceName = sourceName
438437 } else {
439- if val , ok := meta [p .settings .AntispamField ]; ok {
438+ if val , ok := meta [p .settings .SourceNameMetaField ]; ok {
440439 checkSourceID = val
441440 checkSourceName = val
442441 isNewSource = false
443442 } else {
444- p .Error (fmt .Sprintf ("antispam_field %s does not exists in meta" , p .settings .AntispamField ))
443+ p .Error (fmt .Sprintf ("source_name_meta_field %q does not exists in meta" , p .settings .SourceNameMetaField ))
445444 checkSourceID = uint64 (sourceID )
446445 checkSourceName = sourceName
447446 }
@@ -534,15 +533,20 @@ func (p *Pipeline) In(sourceID SourceID, sourceName string, offset int64, bytes
534533 return p .streamEvent (event )
535534}
536535
537- func (p * Pipeline ) checkInputBytes (bytes []byte ) ([]byte , bool ) {
536+ func (p * Pipeline ) checkInputBytes (bytes []byte , sourceName string , meta metadata. MetaData ) ([]byte , bool ) {
538537 length := len (bytes )
539538
540539 if length == 0 || (bytes [0 ] == '\n' && length == 1 ) {
541540 return bytes , false
542541 }
543542
544543 if p .settings .MaxEventSize != 0 && length > p .settings .MaxEventSize {
545- p .IncMaxEventSizeExceeded ()
544+ source := sourceName
545+ if val , ok := meta [p .settings .SourceNameMetaField ]; ok {
546+ source = val
547+ }
548+ p .IncMaxEventSizeExceeded (source )
549+
546550 if ! p .settings .CutOffEventByLimit {
547551 return bytes , false
548552 }
0 commit comments