diff options
| author | Shulhan <ms@kilabit.info> | 2022-08-17 13:32:00 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-08-17 13:32:00 +0700 |
| commit | 05b4830d0fd5aaec157139d88beffa1cf0ce0615 (patch) | |
| tree | 1138313a4d8bc045f698c94da68a213a3025732c | |
| parent | 4e45545e0832d9d3a8c0311a87d82e81d3684cbe (diff) | |
| download | haminer-05b4830d0fd5aaec157139d88beffa1cf0ce0615.tar.xz | |
all: rename struct type Halog to HttpLog
Halog contains parsed HTTP log, so its make more readable if we rename
the type name.
| -rw-r--r-- | forwarder.go | 2 | ||||
| -rw-r--r-- | haminer.go | 24 | ||||
| -rw-r--r-- | http_log.go (renamed from halog.go) | 22 | ||||
| -rw-r--r-- | influxd_client.go | 6 |
4 files changed, 27 insertions, 27 deletions
diff --git a/forwarder.go b/forwarder.go index 79ab2bc..7c56d20 100644 --- a/forwarder.go +++ b/forwarder.go @@ -3,5 +3,5 @@ package haminer // Forwarder define an interface to forward parsed HAProxy log to storage // engine. type Forwarder interface { - Forwards(halogs []*Halog) + Forwards(halogs []*HttpLog) } @@ -19,7 +19,7 @@ type Haminer struct { cfg *Config udpConn *net.UDPConn chSignal chan os.Signal - chHalog chan *Halog + chHttpLog chan *HttpLog ff []Forwarder isRunning bool } @@ -32,10 +32,10 @@ func NewHaminer(cfg *Config) (h *Haminer) { } h = &Haminer{ - cfg: cfg, - chSignal: make(chan os.Signal, 1), - chHalog: make(chan *Halog, 30), - ff: make([]Forwarder, 0), + cfg: cfg, + chSignal: make(chan os.Signal, 1), + chHttpLog: make(chan *HttpLog, 30), + ff: make([]Forwarder, 0), } signal.Notify(h.chSignal, syscall.SIGHUP, syscall.SIGINT, @@ -84,7 +84,7 @@ func (h *Haminer) Start() (err error) { } // filter will return true if log is accepted; otherwise it will return false. -func (h *Haminer) filter(halog *Halog) bool { +func (h *Haminer) filter(halog *HttpLog) bool { if halog == nil { return false } @@ -108,7 +108,7 @@ func (h *Haminer) consume() { var ( packet = make([]byte, 4096) - halog *Halog + halog *HttpLog err error n int ok bool @@ -120,7 +120,7 @@ func (h *Haminer) consume() { continue } - halog = &Halog{} + halog = &HttpLog{} ok = halog.ParseUDPPacket(packet[:n], h.cfg.RequestHeaders) if !ok { @@ -132,11 +132,11 @@ func (h *Haminer) consume() { continue } - h.chHalog <- halog + h.chHttpLog <- halog } } -func (h *Haminer) preprocess(halog *Halog) { +func (h *Haminer) preprocess(halog *HttpLog) { halog.tagHTTPURL = halog.HTTPURL for _, retag := range h.cfg.retags { halog.tagHTTPURL = retag.preprocess("http_url", halog.tagHTTPURL) @@ -145,11 +145,11 @@ func (h *Haminer) preprocess(halog *Halog) { func (h *Haminer) produce() { ticker := time.NewTicker(h.cfg.ForwardInterval) - halogs := make([]*Halog, 0) + halogs := make([]*HttpLog, 0) for h.isRunning { select { - case halog := <-h.chHalog: + case halog := <-h.chHttpLog: h.preprocess(halog) halogs = append(halogs, halog) @@ -11,10 +11,10 @@ import ( "time" ) -// Halog contains the mapping of haproxy HTTP log format to Go struct. +// HttpLog contains the mapping of haproxy HTTP log format to Go struct. // // Reference: https://cbonte.github.io/haproxy-dconv/1.7/configuration.html#8.2.3 -type Halog struct { // nolint: maligned +type HttpLog struct { // nolint: maligned Timestamp time.Time ClientIP string @@ -121,7 +121,7 @@ func parseToInt64(in []byte, sep byte) (int64, bool) { return v, true } -func (halog *Halog) parseTimes(in []byte) (ok bool) { +func (halog *HttpLog) parseTimes(in []byte) (ok bool) { halog.TimeReq, ok = parseToInt32(in, '/') if !ok { return @@ -150,7 +150,7 @@ func (halog *Halog) parseTimes(in []byte) (ok bool) { return } -func (halog *Halog) parseConns(in []byte) (ok bool) { +func (halog *HttpLog) parseConns(in []byte) (ok bool) { halog.ConnActive, ok = parseToInt32(in, '/') if !ok { return @@ -179,7 +179,7 @@ func (halog *Halog) parseConns(in []byte) (ok bool) { return } -func (halog *Halog) parseQueue(in []byte) (ok bool) { +func (halog *HttpLog) parseQueue(in []byte) (ok bool) { halog.QueueServer, ok = parseToInt32(in, '/') if !ok { return @@ -193,7 +193,7 @@ func (halog *Halog) parseQueue(in []byte) (ok bool) { // parserRequestHeaders parse the request header values in log file. // The request headers start with '{' and end with '}'. // Each header is separated by '|'. -func (halog *Halog) parseRequestHeaders(in []byte, reqHeaders []string) (ok bool) { +func (halog *HttpLog) parseRequestHeaders(in []byte, reqHeaders []string) (ok bool) { if in[0] != '{' { // Skip if we did not find the beginning. return true @@ -222,7 +222,7 @@ func (halog *Halog) parseRequestHeaders(in []byte, reqHeaders []string) (ok bool return true } -func (halog *Halog) parseHTTP(in []byte) (ok bool) { +func (halog *HttpLog) parseHTTP(in []byte) (ok bool) { halog.HTTPMethod, ok = parseToString(in, ' ') if !ok { return @@ -243,10 +243,10 @@ func (halog *Halog) parseHTTP(in []byte) (ok bool) { return ok } -// Parse will parse one line of HAProxy log format into Halog. +// Parse will parse one line of HAProxy log format into HttpLog. // // nolint: gocyclo -func (halog *Halog) Parse(in []byte, reqHeaders []string) (ok bool) { +func (halog *HttpLog) Parse(in []byte, reqHeaders []string) (ok bool) { var err error // Remove prefix from systemd/rsyslog @@ -361,11 +361,11 @@ func (halog *Halog) Parse(in []byte, reqHeaders []string) (ok bool) { } // ParseUDPPacket will convert UDP packet (in bytes) to instance of -// Halog. +// HttpLog. // // It will return nil and false if UDP packet is nil, have zero length, or // cannot be parsed (rejected). -func (halog *Halog) ParseUDPPacket(packet []byte, reqHeaders []string) bool { +func (halog *HttpLog) ParseUDPPacket(packet []byte, reqHeaders []string) bool { if len(packet) == 0 { return false } diff --git a/influxd_client.go b/influxd_client.go index 639167e..e096624 100644 --- a/influxd_client.go +++ b/influxd_client.go @@ -86,7 +86,7 @@ func (cl *InfluxdClient) initConn() { // Forwards implement the Forwarder interface. It will write all logs to // Influxd. -func (cl *InfluxdClient) Forwards(halogs []*Halog) { +func (cl *InfluxdClient) Forwards(halogs []*HttpLog) { var ( logp = `Forwards` @@ -141,9 +141,9 @@ func (cl *InfluxdClient) Forwards(halogs []*Halog) { fmt.Printf(`%s: response: %d %s\n`, logp, httpRes.StatusCode, rspBody) } -func (cl *InfluxdClient) write(halogs []*Halog) (err error) { +func (cl *InfluxdClient) write(halogs []*HttpLog) (err error) { var ( - l *Halog + l *HttpLog k string v string ) |
