Files
waf-platform/EdgeDNS/internal/accesslogs/dns_ingest_log.go

58 lines
1.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package accesslogs
import (
"encoding/json"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
// DNSIngestLog DNS 访问日志单行结构JSONEachRow.
type DNSIngestLog struct {
Timestamp int64 `json:"timestamp"`
RequestId string `json:"request_id"`
NodeId int64 `json:"node_id"`
ClusterId int64 `json:"cluster_id"`
DomainId int64 `json:"domain_id"`
RecordId int64 `json:"record_id"`
RemoteAddr string `json:"remote_addr"`
QuestionName string `json:"question_name"`
QuestionType string `json:"question_type"`
RecordName string `json:"record_name"`
RecordType string `json:"record_type"`
RecordValue string `json:"record_value"`
Networking string `json:"networking"`
IsRecursive bool `json:"is_recursive"`
Error string `json:"error"`
NSRouteCodes []string `json:"ns_route_codes,omitempty"`
ContentJSON string `json:"content_json,omitempty"`
}
// FromNSAccessLog 将 pb.NSAccessLog 转为 DNSIngestLog.
func FromNSAccessLog(log *pb.NSAccessLog, clusterId int64) *DNSIngestLog {
if log == nil {
return nil
}
contentBytes, _ := json.Marshal(log)
return &DNSIngestLog{
Timestamp: log.GetTimestamp(),
RequestId: log.GetRequestId(),
NodeId: log.GetNsNodeId(),
ClusterId: clusterId,
DomainId: log.GetNsDomainId(),
RecordId: log.GetNsRecordId(),
RemoteAddr: log.GetRemoteAddr(),
QuestionName: log.GetQuestionName(),
QuestionType: log.GetQuestionType(),
RecordName: log.GetRecordName(),
RecordType: log.GetRecordType(),
RecordValue: log.GetRecordValue(),
Networking: log.GetNetworking(),
IsRecursive: log.GetIsRecursive(),
Error: log.GetError(),
NSRouteCodes: log.GetNsRouteCodes(),
ContentJSON: string(contentBytes),
}
}