Skip to content

Commit

Permalink
Merge pull request #11 from nlnwa/cw_changes
Browse files Browse the repository at this point in the history
Fixed writing of record with no collection
  • Loading branch information
johnerikhalse authored Feb 18, 2019
2 parents 4b506a1 + d501c72 commit 4de91e8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 1 addition & 4 deletions plugin/archivingcache/archivingcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ func (a *ArchivingCache) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *
key := r.Question[0].String()
server := metrics.WithServer(ctx)
miss := false
collectionRef := getCollectionRef(r)

v, _, shared := a.g.Do(key, func() (interface{}, error) {
collectionRef := getCollectionRef(r)
rec := NewRecorder(a, key, server, a.Connection, r.Question[0].Name, a.UpstreamIP, collectionRef)
if entry, err := a.cache.Get(key); err == nil {
log.Debugf("Found request in cache: %v = %v", key, entry)
Expand All @@ -82,9 +82,6 @@ func (a *ArchivingCache) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *
}
} else {
log.Debugf("No request found in cache for: %v", key)
if collectionRef == nil {
log.Debugf("Collection ref missing in request '%v'. Response will not be stored", key)
}
a.forward.ServeDNS(ctx, rec, r)
miss = true
}
Expand Down
5 changes: 5 additions & 0 deletions plugin/archivingcache/archivingcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,15 @@ func TestConcurrent(t *testing.T) {
q := m.On(r.MockAnything()).Return(map[string]interface{}{"foo": "bar"}, nil)

ctx := context.TODO()
c := &resolve.COLLECTION{CollectionRef: &configV1.ConfigRef{Kind:configV1.Kind_collection, Id:"foo"}}
req1 := new(dns.Msg)
req1.SetQuestion("example.org.", dns.TypeA)
req1.SetEdns0(4096, false)
req1.Extra = append(req1.Extra, c)
req2 := new(dns.Msg)
req2.SetQuestion("example2.org.", dns.TypeA)
req2.SetEdns0(4096, false)
req2.Extra = append(req2.Extra, c)

// Call our plugin directly several times in parallel, and check the result.
it := 20
Expand Down
8 changes: 6 additions & 2 deletions plugin/archivingcache/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ func (rec *Recorder) WriteMsg(res *dns.Msg) error {
res.Answer = []dns.RR{record}
// Get the fetch duration in ns, round and convert to ms
rec.FetchDurationMs = (time.Now().UTC().Sub(rec.FetchStart).Nanoseconds() + 500000) / 1000000
reply := rec.writeContentwriter(record.String())
rec.writeCrawlLog(reply.GetMeta().GetRecordMeta()[0])
if rec.collectionRef == nil {
log.Debugf("Collection ref missing in request '%v'. Response will not be stored", rec.key)
} else {
reply := rec.writeContentwriter(record.String())
rec.writeCrawlLog(reply.GetMeta().GetRecordMeta()[0])
}
}

return nil
Expand Down

0 comments on commit 4de91e8

Please sign in to comment.