aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--forwarder_influxd.go16
-rw-r--r--http_log.go88
-rw-r--r--testdata/ParseUDPPacket_test.txt26
3 files changed, 67 insertions, 63 deletions
diff --git a/forwarder_influxd.go b/forwarder_influxd.go
index 3ee358c..dc093e1 100644
--- a/forwarder_influxd.go
+++ b/forwarder_influxd.go
@@ -142,8 +142,8 @@ func (cl *forwarderInfluxd) write(halogs []*HTTPLog) (err error) {
l.HTTPURL,
l.HTTPQuery,
l.HTTPProto,
- l.HTTPStatus,
- l.TermState,
+ l.StatusCode,
+ l.TerminationState,
l.ClientIP,
l.ClientPort,
)
@@ -151,7 +151,7 @@ func (cl *forwarderInfluxd) write(halogs []*HTTPLog) (err error) {
return err
}
- for k, v = range l.RequestHeaders {
+ for k, v = range l.HeaderRequest {
_, err = fmt.Fprintf(&cl.buf, ",%s=%s", k, v)
if err != nil {
return err
@@ -161,18 +161,18 @@ func (cl *forwarderInfluxd) write(halogs []*HTTPLog) (err error) {
cl.buf.WriteByte(' ')
_, err = fmt.Fprintf(&cl.buf, influxdFields,
- l.TimeReq, l.TimeWait, l.TimeConnect,
- l.TimeRsp, l.TimeAll,
+ l.TimeRequest, l.TimeWait, l.TimeConnect,
+ l.TimeResponse, l.TimeAll,
l.ConnActive, l.ConnFrontend, l.ConnBackend,
- l.ConnServer, l.ConnRetries,
- l.QueueServer, l.QueueBackend,
+ l.ConnServer, l.Retries,
+ l.ServerQueue, l.BackendQueue,
l.BytesRead,
)
if err != nil {
return err
}
- _, err = fmt.Fprintf(&cl.buf, " %d\n", l.Timestamp.UnixNano())
+ _, err = fmt.Fprintf(&cl.buf, " %d\n", l.RequestDate.UnixNano())
if err != nil {
return err
}
diff --git a/http_log.go b/http_log.go
index b90abb5..b4ad0b2 100644
--- a/http_log.go
+++ b/http_log.go
@@ -48,10 +48,13 @@ const (
//
// Reference: https://cbonte.github.io/haproxy-dconv/1.7/configuration.html#8.2.3
type HTTPLog struct {
- Timestamp time.Time
+ RequestDate time.Time
- RequestHeaders map[string]string
- ResponseHeaders map[string]string
+ HeaderRequest map[string]string
+ HeaderResponse map[string]string
+
+ rawHeaderRequest string
+ rawHeaderResponse string
ClientIP string
@@ -59,35 +62,35 @@ type HTTPLog struct {
BackendName string
ServerName string
+ HTTPProto string
HTTPMethod string
HTTPURL string
HTTPQuery string
- HTTPProto string
tagHTTPURL string
- CookieReq string
- CookieRsp string
- TermState string
+ CookieRequest string
+ CookieResponse string
+ TerminationState string
BytesRead int64
- HTTPStatus int32
+ StatusCode int32
ClientPort int32
- TimeReq int32
- TimeWait int32
- TimeConnect int32
- TimeRsp int32
- TimeAll int32
+ TimeRequest int32
+ TimeWait int32
+ TimeConnect int32
+ TimeResponse int32
+ TimeAll int32
ConnActive int32
ConnFrontend int32
ConnBackend int32
ConnServer int32
- ConnRetries int32
+ Retries int32
- QueueServer int32
- QueueBackend int32
+ ServerQueue int32
+ BackendQueue int32
}
// ParseUDPPacket convert UDP packet (in bytes) to instance of HTTPLog.
@@ -142,7 +145,7 @@ func Parse(in []byte, reqHeaders []string) (httpLog *HTTPLog) {
var err error
- httpLog.Timestamp, err = time.Parse(`2/Jan/2006:15:04:05.000`, ts)
+ httpLog.RequestDate, err = time.Parse(`2/Jan/2006:15:04:05.000`, ts)
if err != nil {
return nil
}
@@ -168,7 +171,7 @@ func Parse(in []byte, reqHeaders []string) (httpLog *HTTPLog) {
return nil
}
- httpLog.HTTPStatus, ok = parseToInt32(in, ' ')
+ httpLog.StatusCode, ok = parseToInt32(in, ' ')
if !ok {
return nil
}
@@ -178,16 +181,16 @@ func Parse(in []byte, reqHeaders []string) (httpLog *HTTPLog) {
return nil
}
- httpLog.CookieReq, ok = parseToString(in, ' ')
+ httpLog.CookieRequest, ok = parseToString(in, ' ')
if !ok {
return nil
}
- httpLog.CookieRsp, ok = parseToString(in, ' ')
+ httpLog.CookieResponse, ok = parseToString(in, ' ')
if !ok {
return nil
}
- httpLog.TermState, ok = parseToString(in, ' ')
+ httpLog.TerminationState, ok = parseToString(in, ' ')
if !ok {
return nil
}
@@ -203,7 +206,7 @@ func Parse(in []byte, reqHeaders []string) (httpLog *HTTPLog) {
}
if len(reqHeaders) > 0 {
- ok = httpLog.parseRequestHeaders(in, reqHeaders)
+ ok = httpLog.parseHeaderRequest(in, reqHeaders)
if !ok {
return nil
}
@@ -292,7 +295,7 @@ func parseToInt64(in []byte, sep byte) (int64, bool) {
}
func (httpLog *HTTPLog) parseConnectionTimes(in []byte) (ok bool) {
- httpLog.TimeReq, ok = parseToInt32(in, '/')
+ httpLog.TimeRequest, ok = parseToInt32(in, '/')
if !ok {
return
}
@@ -307,7 +310,7 @@ func (httpLog *HTTPLog) parseConnectionTimes(in []byte) (ok bool) {
return
}
- httpLog.TimeRsp, ok = parseToInt32(in, '/')
+ httpLog.TimeResponse, ok = parseToInt32(in, '/')
if !ok {
return
}
@@ -341,7 +344,7 @@ func (httpLog *HTTPLog) parseConns(in []byte) (ok bool) {
return
}
- httpLog.ConnRetries, ok = parseToInt32(in, ' ')
+ httpLog.Retries, ok = parseToInt32(in, ' ')
if !ok {
return
}
@@ -350,20 +353,20 @@ func (httpLog *HTTPLog) parseConns(in []byte) (ok bool) {
}
func (httpLog *HTTPLog) parseQueue(in []byte) (ok bool) {
- httpLog.QueueServer, ok = parseToInt32(in, '/')
+ httpLog.ServerQueue, ok = parseToInt32(in, '/')
if !ok {
return
}
- httpLog.QueueBackend, ok = parseToInt32(in, ' ')
+ httpLog.BackendQueue, ok = parseToInt32(in, ' ')
return
}
-// parserRequestHeaders parse the request header values in log file.
+// parserHeaderRequest parse the request header values in log file.
// The request headers start with '{' and end with '}'.
// Each header is separated by '|'.
-func (httpLog *HTTPLog) parseRequestHeaders(in []byte, reqHeaders []string) (ok bool) {
+func (httpLog *HTTPLog) parseHeaderRequest(in []byte, reqHeaders []string) (ok bool) {
if in[0] != '{' {
// Skip if we did not find the beginning.
return true
@@ -375,16 +378,17 @@ func (httpLog *HTTPLog) parseRequestHeaders(in []byte, reqHeaders []string) (ok
return
}
- sep := []byte{'|'}
- bheaders := bytes.Split(in[1:end], sep)
+ httpLog.rawHeaderRequest = string(in[1:end])
+
+ var headers = strings.Split(httpLog.rawHeaderRequest, `|`)
- if len(reqHeaders) != len(bheaders) {
+ if len(reqHeaders) != len(headers) {
return
}
- httpLog.RequestHeaders = make(map[string]string)
+ httpLog.HeaderRequest = make(map[string]string)
for x, name := range reqHeaders {
- httpLog.RequestHeaders[name] = string(bheaders[x])
+ httpLog.HeaderRequest[name] = headers[x]
}
copy(in, in[end+2:])
@@ -435,8 +439,8 @@ func (httpLog *HTTPLog) writeIlp(out io.Writer) (err error) {
httpLog.HTTPURL,
httpLog.HTTPQuery,
httpLog.HTTPProto,
- httpLog.HTTPStatus,
- httpLog.TermState,
+ httpLog.StatusCode,
+ httpLog.TerminationState,
httpLog.ClientIP,
httpLog.ClientPort,
)
@@ -444,7 +448,7 @@ func (httpLog *HTTPLog) writeIlp(out io.Writer) (err error) {
return err
}
- for k, v = range httpLog.RequestHeaders {
+ for k, v = range httpLog.HeaderRequest {
_, err = fmt.Fprintf(out, `,%s=%s`, k, v)
if err != nil {
return err
@@ -457,18 +461,18 @@ func (httpLog *HTTPLog) writeIlp(out io.Writer) (err error) {
}
_, err = fmt.Fprintf(out, influxdFields,
- httpLog.TimeReq, httpLog.TimeWait, httpLog.TimeConnect,
- httpLog.TimeRsp, httpLog.TimeAll,
+ httpLog.TimeRequest, httpLog.TimeWait, httpLog.TimeConnect,
+ httpLog.TimeResponse, httpLog.TimeAll,
httpLog.ConnActive, httpLog.ConnFrontend, httpLog.ConnBackend,
- httpLog.ConnServer, httpLog.ConnRetries,
- httpLog.QueueServer, httpLog.QueueBackend,
+ httpLog.ConnServer, httpLog.Retries,
+ httpLog.ServerQueue, httpLog.BackendQueue,
httpLog.BytesRead,
)
if err != nil {
return err
}
- _, err = fmt.Fprintf(out, " %d\n", httpLog.Timestamp.UnixNano())
+ _, err = fmt.Fprintf(out, " %d\n", httpLog.RequestDate.UnixNano())
if err != nil {
return err
}
diff --git a/testdata/ParseUDPPacket_test.txt b/testdata/ParseUDPPacket_test.txt
index 9b93015..d108277 100644
--- a/testdata/ParseUDPPacket_test.txt
+++ b/testdata/ParseUDPPacket_test.txt
@@ -5,33 +5,33 @@ Test data for ParseUDPPacket.
<<< http_log_0000
{
- "Timestamp": "2024-03-17T05:08:28.886Z",
- "RequestHeaders": null,
- "ResponseHeaders": null,
+ "RequestDate": "2024-03-17T05:08:28.886Z",
+ "HeaderRequest": null,
+ "HeaderResponse": null,
"ClientIP": "169.254.63.64",
"FrontendName": "fe-http",
"BackendName": "be-http",
"ServerName": "be-http2",
+ "HTTPProto": "HTTP/1.1",
"HTTPMethod": "GET",
"HTTPURL": "/",
"HTTPQuery": "",
- "HTTPProto": "HTTP/1.1",
- "CookieReq": "-",
- "CookieRsp": "-",
- "TermState": "----",
+ "CookieRequest": "-",
+ "CookieResponse": "-",
+ "TerminationState": "----",
"BytesRead": 149,
- "HTTPStatus": 200,
+ "StatusCode": 200,
"ClientPort": 52722,
- "TimeReq": 10,
+ "TimeRequest": 10,
"TimeWait": 20,
"TimeConnect": 30,
- "TimeRsp": 40,
+ "TimeResponse": 40,
"TimeAll": 50,
"ConnActive": 1,
"ConnFrontend": 1,
"ConnBackend": 2,
"ConnServer": 3,
- "ConnRetries": 4,
- "QueueServer": 5,
- "QueueBackend": 6
+ "Retries": 4,
+ "ServerQueue": 5,
+ "BackendQueue": 6
}