Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

Commit

Permalink
provide better error when parsing fails
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcz committed Dec 27, 2021
1 parent 08da0a2 commit f32db76
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,26 @@ func setReplicationValue(entries []*ldap.Entry, q *query) {
// not every entry will have this attribute
continue
}
fields := log.Fields{
"filter": q.searchFilter,
"attr": q.searchAttr,
"value": val,
}
valueBuffer := strings.Split(val, "#")
gt, err := time.Parse("20060102150405.999999Z", valueBuffer[0])
if err != nil {
log.WithError(err).WithField("attr", q.searchAttr).Warn("unexpected replication value")
log.WithFields(fields).WithError(err).Warn("unexpected gt value")
continue
}
count, err := strconv.ParseFloat(valueBuffer[1], 64)
if err != nil {
log.WithError(err).WithField("attr", q.searchAttr).Warn("unexpected replication value")
log.WithFields(fields).WithError(err).Warn("unexpected count value")
continue
}
sid := valueBuffer[2]
mod, err := strconv.ParseFloat(valueBuffer[3], 64)
if err != nil {
log.WithError(err).WithField("attr", q.searchAttr).Warn("unexpected replication value")
log.WithFields(fields).WithError(err).Warn("unexpected mod value")
continue
}
q.metric.WithLabelValues(sid, "gt").Set(float64(gt.Unix()))
Expand Down

0 comments on commit f32db76

Please sign in to comment.