fix: fix Nginx parser start without gourutine
Some checks failed
build / build (push) Failing after 2m54s
Some checks failed
build / build (push) Failing after 2m54s
This commit is contained in:
@@ -24,35 +24,33 @@ func NewNginxParser() *NginxParser {
|
|||||||
|
|
||||||
func (p *NginxParser) Parse(eventCh <-chan Event, resultCh chan<- *storage.LogEntry) {
|
func (p *NginxParser) Parse(eventCh <-chan Event, resultCh chan<- *storage.LogEntry) {
|
||||||
// Group 1: IP, Group 2: Timestamp, Group 3: Method, Group 4: Path, Group 5: Status
|
// Group 1: IP, Group 2: Timestamp, Group 3: Method, Group 4: Path, Group 5: Status
|
||||||
go func() {
|
for event := range eventCh {
|
||||||
for event := range eventCh {
|
matches := p.pattern.FindStringSubmatch(event.Data)
|
||||||
matches := p.pattern.FindStringSubmatch(event.Data)
|
if matches == nil {
|
||||||
if matches == nil {
|
continue
|
||||||
continue
|
|
||||||
}
|
|
||||||
path := matches[4]
|
|
||||||
status := matches[5]
|
|
||||||
method := matches[3]
|
|
||||||
|
|
||||||
resultCh <- &storage.LogEntry{
|
|
||||||
Service: "nginx",
|
|
||||||
IP: matches[1],
|
|
||||||
Path: path,
|
|
||||||
Status: status,
|
|
||||||
Method: method,
|
|
||||||
IsViewed: false,
|
|
||||||
}
|
|
||||||
p.logger.Info(
|
|
||||||
"Parsed nginx log entry",
|
|
||||||
"ip",
|
|
||||||
matches[1],
|
|
||||||
"path",
|
|
||||||
path,
|
|
||||||
"status",
|
|
||||||
status,
|
|
||||||
"method",
|
|
||||||
method,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}()
|
path := matches[4]
|
||||||
|
status := matches[5]
|
||||||
|
method := matches[3]
|
||||||
|
|
||||||
|
resultCh <- &storage.LogEntry{
|
||||||
|
Service: "nginx",
|
||||||
|
IP: matches[1],
|
||||||
|
Path: path,
|
||||||
|
Status: status,
|
||||||
|
Method: method,
|
||||||
|
IsViewed: false,
|
||||||
|
}
|
||||||
|
p.logger.Info(
|
||||||
|
"Parsed nginx log entry",
|
||||||
|
"ip",
|
||||||
|
matches[1],
|
||||||
|
"path",
|
||||||
|
path,
|
||||||
|
"status",
|
||||||
|
status,
|
||||||
|
"method",
|
||||||
|
method,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Write(db *DB, resultCh <-chan *LogEntry) {
|
func Write(db *DB, resultCh <-chan *LogEntry) {
|
||||||
|
db.logger.Info("Starting log writer")
|
||||||
const batchSize = 100
|
const batchSize = 100
|
||||||
const flushInterval = 1 * time.Second
|
const flushInterval = 1 * time.Second
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user