Skip to content

Commit

Permalink
Replicate Domain to Root when empty (#22)
Browse files Browse the repository at this point in the history
Some entries received from the API do not have a Root field, if the
Domain field itself is a root domain. This can cause some problems or
special-case handling in dashboards and data pipelines. This patch
replicates the `Domain` to `Root` when `Root` is not set.

Fixes #20

Co-authored-by: Raymond Douglas <[email protected]>
  • Loading branch information
jfroy and raylas authored Oct 2, 2023
1 parent 978255c commit a126ea1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/api/domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ func (c Client) CollectDomains() (*DomainsMetrics, error) {
}

for _, domain := range domainsResponse.Domains {
// Some entries appear not to have a root, in which case replicate the domain.
// https://github.com/raylas/nextdns-exporter/issues/20
if len(domain.Root) == 0 {
domain.Root = domain.Domain
}
domain := DomainMetric{
Domain: domain.Domain,
Root: domain.Root,
Expand Down
1 change: 1 addition & 0 deletions internal/api/domains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestCollectDomains(t *testing.T) {
},
{
Domain: "app-measurement.com",
Root: "app-measurement.com",
Queries: 3922,
},
{
Expand Down

0 comments on commit a126ea1

Please sign in to comment.