Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle non integer values for zone serial #97

Merged
merged 3 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bind/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ type Counter struct {
// Counter represents a single zone counter value.
type ZoneCounter struct {
Name string
Serial uint64
Serial string
}

// Gauge represents a single gauge value.
Expand Down
2 changes: 1 addition & 1 deletion bind/v2/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type View struct {
type Zone struct {
Name string `xml:"name"`
Rdataclass string `xml:"rdataclass"`
Serial uint64 `xml:"serial"`
Serial string `xml:"serial"`
}

type Counter struct {
Expand Down
2 changes: 1 addition & 1 deletion bind/v3/v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ type Counter struct {
type ZoneCounter struct {
Name string `xml:"name,attr"`
Rdataclass string `xml:"rdataclass,attr"`
Serial uint64 `xml:"serial"`
Serial string `xml:"serial"`
}

// Client implements bind.Client and can be used to query a BIND v3 API.
Expand Down
12 changes: 9 additions & 3 deletions bind_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,15 @@ func (c *viewCollector) Collect(ch chan<- prometheus.Metric) {

for _, v := range c.stats.ZoneViews {
for _, z := range v.ZoneData {
ch <- prometheus.MustNewConstMetric(
zoneSerial, prometheus.CounterValue, float64(z.Serial), v.Name, z.Name,
)
if suint, err := strconv.ParseUint(z.Serial, 10, 64); err == nil {
ch <- prometheus.MustNewConstMetric(
zoneSerial, prometheus.CounterValue, float64(suint), v.Name, z.Name,
)
} else {
ch <- prometheus.MustNewConstMetric(
zoneSerial, prometheus.CounterValue, float64(0), v.Name, z.Name,
)
}
SuperQ marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
1 change: 1 addition & 0 deletions bind_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var (
`bind_resolver_query_duration_seconds_bucket{view="_default",le="1.6"} 188409`,
`bind_resolver_query_duration_seconds_bucket{view="_default",le="+Inf"} 227755`,
`bind_zone_serial{view="_default",zone_name="TEST_ZONE"} 123`,
`bind_zone_serial{view="_default",zone_name="FAULT_TEST_ZONE"} 0`,
}
taskStats = []string{
`bind_tasks_running 8`,
Expand Down
5 changes: 5 additions & 0 deletions fixtures/v2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
<rdataclass>IN</rdataclass>
<serial>123</serial>
</zone>
<zone>
<name>FAULT_TEST_ZONE</name>
<rdataclass>IN</rdataclass>
<serial>-</serial>
</zone>
<zone>
<name>0.in-addr.arpa/IN</name>
<rdataclass>IN</rdataclass>
Expand Down
4 changes: 4 additions & 0 deletions fixtures/v3/zones
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<type>builtin</type>
<serial>123</serial>
</zone>
<zone name="FAULT_TEST_ZONE" rdataclass="IN">
<type>builtin</type>
<serial>-</serial>
</zone>
</zones>
</view>
</views>
Expand Down