all: imp code
This commit is contained in:
parent
8d88d79930
commit
cbb993f7ae
|
@ -533,7 +533,7 @@ func closeDNSServer() {
|
|||
|
||||
if Context.queryLog != nil {
|
||||
// TODO(s.chzhen): Pass context.
|
||||
Context.queryLog.Close(context.TODO())
|
||||
Context.queryLog.Shutdown(context.TODO())
|
||||
}
|
||||
|
||||
log.Debug("all dns modules are closed")
|
||||
|
|
|
@ -682,7 +682,7 @@ func (l *queryLog) resultDecHandler(
|
|||
dec *json.Decoder,
|
||||
ent *logEntry,
|
||||
) (found bool) {
|
||||
notFound := false
|
||||
found = true
|
||||
switch name {
|
||||
case "ReverseHosts":
|
||||
l.decodeResultReverseHosts(ctx, dec, ent)
|
||||
|
@ -693,10 +693,10 @@ func (l *queryLog) resultDecHandler(
|
|||
case "DNSRewriteResult":
|
||||
l.decodeResultDNSRewriteResult(ctx, dec, ent)
|
||||
default:
|
||||
notFound = true
|
||||
found = false
|
||||
}
|
||||
|
||||
return !notFound
|
||||
return found
|
||||
}
|
||||
|
||||
// decodeLogEntry decodes string str to logEntry ent.
|
||||
|
|
|
@ -84,14 +84,15 @@ func (l *queryLog) handleQueryLog(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
var entries []*logEntry
|
||||
var oldest time.Time
|
||||
ctx := r.Context()
|
||||
func() {
|
||||
l.confMu.RLock()
|
||||
defer l.confMu.RUnlock()
|
||||
|
||||
entries, oldest = l.search(r.Context(), params)
|
||||
entries, oldest = l.search(ctx, params)
|
||||
}()
|
||||
|
||||
resp := l.entriesToJSON(r.Context(), entries, oldest, l.anonymizer.Load())
|
||||
resp := l.entriesToJSON(ctx, entries, oldest, l.anonymizer.Load())
|
||||
|
||||
aghhttp.WriteJSONResponseOK(w, r, resp)
|
||||
}
|
||||
|
|
|
@ -82,6 +82,10 @@ func NewClientProto(s string) (cp ClientProto, err error) {
|
|||
}
|
||||
}
|
||||
|
||||
// type check
|
||||
var _ QueryLog = (*queryLog)(nil)
|
||||
|
||||
// Start implements the [QueryLog] interface for *queryLog.
|
||||
func (l *queryLog) Start(ctx context.Context) {
|
||||
if l.conf.HTTPRegister != nil {
|
||||
l.initWeb()
|
||||
|
@ -90,7 +94,8 @@ func (l *queryLog) Start(ctx context.Context) {
|
|||
go l.periodicRotate(ctx)
|
||||
}
|
||||
|
||||
func (l *queryLog) Close(ctx context.Context) {
|
||||
// Shutdown implements the [QueryLog] interface for *queryLog.
|
||||
func (l *queryLog) Shutdown(ctx context.Context) {
|
||||
l.confMu.RLock()
|
||||
defer l.confMu.RUnlock()
|
||||
|
||||
|
@ -129,6 +134,7 @@ func validateIvl(ivl time.Duration) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
// WriteDiskConfig implements the [QueryLog] interface for *queryLog.
|
||||
func (l *queryLog) WriteDiskConfig(c *Config) {
|
||||
l.confMu.RLock()
|
||||
defer l.confMu.RUnlock()
|
||||
|
|
|
@ -17,17 +17,18 @@ import (
|
|||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
// QueryLog - main interface
|
||||
// QueryLog is the query log interface for use by other packages.
|
||||
type QueryLog interface {
|
||||
// Start starts the query log.
|
||||
Start(ctx context.Context)
|
||||
|
||||
// Close query log object
|
||||
Close(ctx context.Context)
|
||||
// Shutdown stops the query log.
|
||||
Shutdown(ctx context.Context)
|
||||
|
||||
// Add a log entry
|
||||
// Add adds a log entry.
|
||||
Add(params *AddParams)
|
||||
|
||||
// WriteDiskConfig - write configuration
|
||||
// WriteDiskConfig writes the query log configuration to c.
|
||||
WriteDiskConfig(c *Config)
|
||||
|
||||
// ShouldLog returns true if request for the host should be logged.
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
// buffer.
|
||||
func (l *queryLog) flushLogBuffer(ctx context.Context) (err error) {
|
||||
defer func() { err = errors.Annotate(err, "flushing log buffer: %w") }()
|
||||
|
||||
l.fileFlushLock.Lock()
|
||||
defer l.fileFlushLock.Unlock()
|
||||
|
||||
|
|
|
@ -346,7 +346,7 @@ func (l *queryLog) readNextEntry(
|
|||
l.logger.ErrorContext(
|
||||
ctx,
|
||||
"enriching file record at time",
|
||||
"at_time", e.Time,
|
||||
"at", e.Time,
|
||||
"client_ip", e.IP,
|
||||
"client_id", e.ClientID,
|
||||
slogutil.KeyError, err,
|
||||
|
|
|
@ -51,7 +51,7 @@ func TestQueryLog_Search_findClient(t *testing.T) {
|
|||
|
||||
ctx := testutil.ContextWithTimeout(t, testTimeout)
|
||||
t.Cleanup(func() {
|
||||
l.Close(ctx)
|
||||
l.Shutdown(ctx)
|
||||
})
|
||||
|
||||
q := &dns.Msg{
|
||||
|
|
Loading…
Reference in New Issue