forked from brimdata/super
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.go
64 lines (54 loc) · 1.49 KB
/
core.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package zqd
import (
"net/http"
"sync/atomic"
"github.com/brimsec/zq/zqd/zeek"
"go.uber.org/zap"
)
type Config struct {
Root string
// ZeekLauncher is the interface for launching zeek processes.
ZeekLauncher zeek.Launcher
// SortLimit specifies the limit of logs in posted pcap to sort. Its
// existence is only as a hook for testing. Eventually zqd will sort an
// unlimited amount of logs and this can be taken out.
SortLimit int
Logger *zap.Logger
}
type VersionMessage struct {
Zqd string `json:"boomd"` //XXX boomd -> zqd
Zq string `json:"zq"`
}
// This struct filled in by main from linker setting version strings.
var Version VersionMessage
type Core struct {
Root string
ZeekLauncher zeek.Launcher
// SortLimit specifies the limit of logs in posted pcap to sort. Its
// existence is only as a hook for testing. Eventually zqd will sort an
// unlimited amount of logs and this can be taken out.
SortLimit int
taskCount int64
logger *zap.Logger
}
func NewCore(conf Config) *Core {
logger := conf.Logger
if logger == nil {
logger = zap.NewNop()
}
return &Core{
Root: conf.Root,
ZeekLauncher: conf.ZeekLauncher,
SortLimit: conf.SortLimit,
logger: logger,
}
}
func (c *Core) HasZeek() bool {
return c.ZeekLauncher != nil
}
func (c *Core) requestLogger(r *http.Request) *zap.Logger {
return c.logger.With(zap.String("request_id", getRequestID(r.Context())))
}
func (c *Core) getTaskID() int64 {
return atomic.AddInt64(&c.taskCount, 1)
}