add: [grok] ingest from file

nifi
Jean-Louis Huynen 2020-03-10 16:31:53 +01:00
parent 9a4d57ee0a
commit aef4b518c0
No known key found for this signature in database
GPG Key ID: 64799157F4BD6B93
2 changed files with 26 additions and 26 deletions

View File

@ -15,6 +15,7 @@ type (
// Flush recomputes statisitcs and recompile output
Compiler interface {
Set(*sync.WaitGroup, *redis.Conn, *redis.Conn, io.Reader, int, *sync.WaitGroup)
SetReader(io.Reader)
Pull() error
Flush() error
Compile() error
@ -54,3 +55,8 @@ func (s *CompilerStruct) Set(wg *sync.WaitGroup, rconn0 *redis.Conn, rconn1 *red
s.compiling = false
s.compilegr = compilegr
}
// SetReader Changes compiler's input
func (s *CompilerStruct) SetReader(reader io.Reader) {
s.reader = reader
}

46
main.go
View File

@ -192,34 +192,28 @@ func main() {
if err != nil {
log.Fatal(err)
}
// TODO
// compile()
log.Println("Exit")
os.Exit(0)
}
// TODO update that -- deprecated
} else if *fromfile != "" {
f, err = os.Open(*fromfile)
if err != nil {
log.Fatalf("Error opening seed file: %v", err)
}
defer f.Close()
// scanner := bufio.NewScanner(f)
// for scanner.Scan() {
// logline := scanner.Bytes()
// for _, v := range torun {
// go v.Pull()
// if err != nil {
// log.Fatal(err)
// }
// }
// }
} else {
// Launching Pull routines
for _, v := range torun {
// we add pulling routines to a waitgroup,
// they can immediately die when exiting.
pullgr.Add(1)
go v.Pull()
}
// Launching Pull routines
for _, v := range torun {
// If we read from a file, we set the reader to os.open
if *fromfile != "" {
f, err = os.Open(*fromfile)
if err != nil {
log.Fatalf("Error opening seed file: %v", err)
}
defer f.Close()
v.SetReader(f)
}
// we add pulling routines to a waitgroup,
// they can immediately die when exiting.
pullgr.Add(1)
go v.Pull()
}
pullgr.Wait()