5959 initMutex = & sync.Mutex {}
6060)
6161
62- // NewCollector is the constructor for the Collector plugin.
62+ // New is the constructor for the Collector plugin.
6363func New (conf * config.Config ) (* Collector , error ) {
6464 initMutex .Lock ()
6565
@@ -194,7 +194,7 @@ func (oc *Collector) Subscriptions() []string {
194194}
195195
196196// Process receivers and log warning for sub-optimal configurations
197- func (oc * Collector ) processReceivers (ctx context.Context , receivers [] config.OtlpReceiver ) {
197+ func (oc * Collector ) processReceivers (ctx context.Context , receivers map [ string ] * config.OtlpReceiver ) {
198198 for _ , receiver := range receivers {
199199 if receiver .OtlpTLSConfig == nil {
200200 slog .WarnContext (ctx , "OTel receiver is configured without TLS. Connections are unencrypted." )
@@ -317,12 +317,13 @@ func (oc *Collector) updateResourceProcessor(resourceUpdateContext *v1.Resource)
317317 resourceProcessorUpdated := false
318318
319319 if oc .config .Collector .Processors .Resource == nil {
320- oc .config .Collector .Processors .Resource = & config.Resource {
320+ oc .config .Collector .Processors .Resource = make (map [string ]* config.Resource )
321+ oc .config .Collector .Processors .Resource ["default" ] = & config.Resource {
321322 Attributes : make ([]config.ResourceAttribute , 0 ),
322323 }
323324 }
324325
325- if oc .config .Collector .Processors .Resource != nil &&
326+ if oc .config .Collector .Processors .Resource [ "default" ] != nil &&
326327 resourceUpdateContext .GetResourceId () != "" {
327328 resourceProcessorUpdated = oc .updateResourceAttributes (
328329 []config.ResourceAttribute {
@@ -431,7 +432,7 @@ func (oc *Collector) checkForNewReceivers(ctx context.Context, nginxConfigContex
431432 }
432433
433434 if oc .config .IsFeatureEnabled (pkgConfig .FeatureLogsNap ) {
434- tcplogReceiversFound := oc .updateTcplogReceivers (nginxConfigContext )
435+ tcplogReceiversFound := oc .updateNginxAppProtectTcplogReceivers (nginxConfigContext )
435436 if tcplogReceiversFound {
436437 reloadCollector = true
437438 }
@@ -541,49 +542,51 @@ func (oc *Collector) updateExistingNginxOSSReceiver(
541542 return nginxReceiverFound , reloadCollector
542543}
543544
544- func (oc * Collector ) updateTcplogReceivers (nginxConfigContext * model.NginxConfigContext ) bool {
545+ func (oc * Collector ) updateNginxAppProtectTcplogReceivers (nginxConfigContext * model.NginxConfigContext ) bool {
545546 newTcplogReceiverAdded := false
547+
548+ if oc .config .Collector .Receivers .TcplogReceivers == nil {
549+ oc .config .Collector .Receivers .TcplogReceivers = make (map [string ]* config.TcplogReceiver )
550+ }
551+
546552 if nginxConfigContext .NAPSysLogServers != nil {
547553 napLoop:
548554 for _ , napSysLogServer := range nginxConfigContext .NAPSysLogServers {
549555 if oc .doesTcplogReceiverAlreadyExist (napSysLogServer ) {
550556 continue napLoop
551557 }
552558
553- oc .config .Collector .Receivers .TcplogReceivers = append (
554- oc .config .Collector .Receivers .TcplogReceivers ,
555- config.TcplogReceiver {
556- ListenAddress : napSysLogServer ,
557- Operators : []config.Operator {
558- {
559- Type : "add" ,
560- Fields : map [string ]string {
561- "field" : "body" ,
562- "value" : timestampConversionExpression ,
563- },
559+ oc .config .Collector .Receivers .TcplogReceivers ["nginx_app_protect" ] = & config.TcplogReceiver {
560+ ListenAddress : napSysLogServer ,
561+ Operators : []config.Operator {
562+ {
563+ Type : "add" ,
564+ Fields : map [string ]string {
565+ "field" : "body" ,
566+ "value" : timestampConversionExpression ,
564567 },
565- {
566- Type : "syslog_parser" ,
567- Fields : map [ string ] string {
568- "protocol" : "rfc3164" ,
569- } ,
568+ },
569+ {
570+ Type : "syslog_parser" ,
571+ Fields : map [ string ] string {
572+ "protocol" : "rfc3164" ,
570573 },
571- {
572- Type : "remove" ,
573- Fields : map [ string ] string {
574- "field" : "attributes.message" ,
575- } ,
574+ },
575+ {
576+ Type : "remove" ,
577+ Fields : map [ string ] string {
578+ "field" : "attributes.message" ,
576579 },
577- {
578- Type : "add" ,
579- Fields : map [ string ] string {
580- "field" : "resource[ \" instance.id \" ]" ,
581- "value " : nginxConfigContext . InstanceID ,
582- } ,
580+ },
581+ {
582+ Type : "add" ,
583+ Fields : map [ string ] string {
584+ "field " : "resource[ \" instance.id \" ]" ,
585+ "value" : nginxConfigContext . InstanceID ,
583586 },
584587 },
585588 },
586- )
589+ }
587590
588591 newTcplogReceiverAdded = true
589592 }
@@ -597,23 +600,13 @@ func (oc *Collector) updateTcplogReceivers(nginxConfigContext *model.NginxConfig
597600func (oc * Collector ) areNapReceiversDeleted (nginxConfigContext * model.NginxConfigContext ) bool {
598601 listenAddressesToBeDeleted := oc .configDeletedNapReceivers (nginxConfigContext )
599602 if len (listenAddressesToBeDeleted ) != 0 {
600- oc .deleteNapReceivers ( listenAddressesToBeDeleted )
603+ delete ( oc .config . Collector . Receivers . TcplogReceivers , "nginx_app_protect" )
601604 return true
602605 }
603606
604607 return false
605608}
606609
607- func (oc * Collector ) deleteNapReceivers (listenAddressesToBeDeleted map [string ]bool ) {
608- filteredReceivers := (oc .config .Collector .Receivers .TcplogReceivers )[:0 ]
609- for _ , receiver := range oc .config .Collector .Receivers .TcplogReceivers {
610- if ! listenAddressesToBeDeleted [receiver .ListenAddress ] {
611- filteredReceivers = append (filteredReceivers , receiver )
612- }
613- }
614- oc .config .Collector .Receivers .TcplogReceivers = filteredReceivers
615- }
616-
617610func (oc * Collector ) configDeletedNapReceivers (nginxConfigContext * model.NginxConfigContext ) map [string ]bool {
618611 elements := make (map [string ]bool )
619612
@@ -651,16 +644,16 @@ func (oc *Collector) updateResourceAttributes(
651644) (actionUpdated bool ) {
652645 actionUpdated = false
653646
654- if oc .config .Collector .Processors .Resource .Attributes != nil {
647+ if oc .config .Collector .Processors .Resource [ "default" ] .Attributes != nil {
655648 OUTER:
656649 for _ , toAdd := range attributesToAdd {
657- for _ , action := range oc .config .Collector .Processors .Resource .Attributes {
650+ for _ , action := range oc .config .Collector .Processors .Resource [ "default" ] .Attributes {
658651 if action .Key == toAdd .Key {
659652 continue OUTER
660653 }
661654 }
662- oc .config .Collector .Processors .Resource .Attributes = append (
663- oc .config .Collector .Processors .Resource .Attributes ,
655+ oc .config .Collector .Processors .Resource [ "default" ] .Attributes = append (
656+ oc .config .Collector .Processors .Resource [ "default" ] .Attributes ,
664657 toAdd ,
665658 )
666659 actionUpdated = true
0 commit comments