@@ -172,38 +172,41 @@ func setValue(entries []*ldap.Entry, q *query) {
172172 }
173173}
174174
175+ // parse value for replication and handle multiple values for contextCSN attribute
175176func setReplicationValue (entries []* ldap.Entry , q * query ) {
176177 for _ , entry := range entries {
177- val := entry .GetAttributeValue (q .searchAttr )
178- if val == "" {
179- // not every entry will have this attribute
180- continue
181- }
182- fields := log.Fields {
183- "filter" : q .searchFilter ,
184- "attr" : q .searchAttr ,
185- "value" : val ,
186- }
187- valueBuffer := strings .Split (val , "#" )
188- gt , err := time .Parse ("20060102150405.999999Z" , valueBuffer [0 ])
189- if err != nil {
190- log .WithFields (fields ).WithError (err ).Warn ("unexpected gt value" )
191- continue
192- }
193- count , err := strconv .ParseFloat (valueBuffer [1 ], 64 )
194- if err != nil {
195- log .WithFields (fields ).WithError (err ).Warn ("unexpected count value" )
196- continue
197- }
198- sid := valueBuffer [2 ]
199- mod , err := strconv .ParseFloat (valueBuffer [3 ], 64 )
200- if err != nil {
201- log .WithFields (fields ).WithError (err ).Warn ("unexpected mod value" )
202- continue
178+ attributeValues := entry .GetAttributeValues (q .searchAttr ) // with multiple node on replications, attribute can have multiple value
179+ for _ , context := range attributeValues {
180+ if context == "" {
181+ // not every entry will have this attribute
182+ continue
183+ }
184+ fields := log.Fields {
185+ "filter" : q .searchFilter ,
186+ "attr" : q .searchAttr ,
187+ "value" : context ,
188+ }
189+ valueBuffer := strings .Split (context , "#" )
190+ gt , err := time .Parse ("20060102150405.999999Z" , valueBuffer [0 ])
191+ if err != nil {
192+ log .WithFields (fields ).WithError (err ).Warn ("unexpected gt value" )
193+ continue
194+ }
195+ count , err := strconv .ParseFloat (valueBuffer [1 ], 64 )
196+ if err != nil {
197+ log .WithFields (fields ).WithError (err ).Warn ("unexpected count value" )
198+ continue
199+ }
200+ sid := valueBuffer [2 ]
201+ mod , err := strconv .ParseFloat (valueBuffer [3 ], 64 )
202+ if err != nil {
203+ log .WithFields (fields ).WithError (err ).Warn ("unexpected mod value" )
204+ continue
205+ }
206+ q .metric .WithLabelValues (sid , "gt" ).Set (float64 (gt .Unix ()))
207+ q .metric .WithLabelValues (sid , "count" ).Set (count )
208+ q .metric .WithLabelValues (sid , "mod" ).Set (mod )
203209 }
204- q .metric .WithLabelValues (sid , "gt" ).Set (float64 (gt .Unix ()))
205- q .metric .WithLabelValues (sid , "count" ).Set (count )
206- q .metric .WithLabelValues (sid , "mod" ).Set (mod )
207210 }
208211}
209212
0 commit comments