From cc080a1ce8d672018ff364824961f756d904b7a4 Mon Sep 17 00:00:00 2001 From: dletta Date: Mon, 30 Sep 2024 11:32:34 -0500 Subject: [PATCH] Small improvements for Connection error logic, Capitalization across logs --- publish/hep.go | 35 ++++++++++++++++++----------------- sniffer/sniffer.go | 4 ++-- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/publish/hep.go b/publish/hep.go index 49ea3a1..cf2516c 100644 --- a/publish/hep.go +++ b/publish/hep.go @@ -39,7 +39,7 @@ func NewHEPOutputer(serverAddr string) (*HEPOutputer, error) { errCnt := 0 for n := range a { if err := h.ConnectServer(n); err != nil { - logp.Err("%v", err) + logp.Err("Error connecting to HEP server (%s): %v", h.addr[n], err) errCnt++ } else { if config.Cfg.HEPBufferEnable { @@ -52,7 +52,7 @@ func NewHEPOutputer(serverAddr string) (*HEPOutputer, error) { } } if errCnt == l { - return nil, fmt.Errorf("cannot establish a connection") + return nil, fmt.Errorf("Cannot establish a connection") } go h.Start() @@ -61,12 +61,13 @@ func NewHEPOutputer(serverAddr string) (*HEPOutputer, error) { func (h *HEPOutputer) Close(n int) { if err := h.client[n].conn.Close(); err != nil { - logp.Err("cannnot close connection to %s: %v", h.addr[n], err) + logp.Err("Cannot close connection to %s: %v", h.addr[n], err) } } func (h *HEPOutputer) ReConnect(n int) (err error) { if err = h.ConnectServer(n); err != nil { + logp.Err("Error reconnecting to HEP server (%s): %v", h.addr[n], err) return err } h.client[n].writer.Reset(h.client[n].conn) @@ -154,7 +155,7 @@ func (h *HEPOutputer) Send(msg []byte) { var err error if h.client[n].conn == nil || h.client[n].writer == nil { - logp.Debug("connection is not up", fmt.Sprintf("index: %d, Len: %d, once: %v", n, len(h.addr), onceSent)) + logp.Debug("Connection is not up", fmt.Sprintf("index: %d, Len: %d, once: %v", n, len(h.addr), onceSent)) err = fmt.Errorf("connection is broken") } else { h.client[n].writer.Write(msg) @@ -216,13 +217,13 @@ func (h *HEPOutputer) copyHEPFileOut(n int) (int, error) { defer func() { if r := recover(); r != nil { - logp.Err("copy hep file out panic: %v, %v", r, debug.Stack()) + logp.Err("Copy hep file out panic: %v, %v", r, debug.Stack()) return } }() if _, err := os.Stat(config.Cfg.HEPBufferFile); err != nil { - logp.Debug("file doesn't exists: ", config.Cfg.HEPBufferFile) + logp.Debug("File doesn't exists: ", config.Cfg.HEPBufferFile) return 1, nil } @@ -233,15 +234,15 @@ func (h *HEPOutputer) copyHEPFileOut(n int) (int, error) { } if h.client[n].conn == nil { - logp.Err("connection is not up....") - return 0, fmt.Errorf("connection is broken") + logp.Err("Connection is not up....") + return 0, fmt.Errorf("Connection is broken") } //Send Logged HEP upon reconnect out to backend hl, err := h.client[n].conn.Write(HEPFileData) if err != nil { promstats.HepFileFlushesError.Inc() - return 0, fmt.Errorf("bad write to socket") + return 0, fmt.Errorf("Bad write to socket") } err = h.client[n].writer.Flush() @@ -268,19 +269,19 @@ func (h *HEPOutputer) copyHEPbufftoFile(inbytes []byte) (int64, error) { defer func() { if r := recover(); r != nil { - logp.Err("copy buffer to panic: %v,\n%s", r, debug.Stack()) + logp.Err("Copy buffer to panic: %v,\n%s", r, debug.Stack()) return } }() if config.Cfg.HEPBufferDebug { - logp.Err("adding packet to BUFFER: %s\n", string(inbytes)) + logp.Err("Adding packet to BUFFER: %s\n", string(inbytes)) } destination, err := os.OpenFile(config.Cfg.HEPBufferFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666) if err != nil { - logp.Err("open HEP file error: %v\n", err) - return 0, fmt.Errorf("open HEP file error: %v", err) + logp.Err("Open HEP file error: %v\n", err) + return 0, fmt.Errorf("Open HEP file error: %v", err) } defer destination.Close() @@ -288,12 +289,12 @@ func (h *HEPOutputer) copyHEPbufftoFile(inbytes []byte) (int64, error) { if config.Cfg.MaxBufferSizeBytes > 0 { fi, err := destination.Stat() if err != nil { - logp.Debug("collector", fmt.Sprintf("couldn't retrive stats from buffer file error: %v", err.Error())) + logp.Debug("collector", fmt.Sprintf("Couldn't retrive stats from buffer file error: %v", err.Error())) return 0, err } else { if fi.Size() >= config.Cfg.MaxBufferSizeBytes { - logp.Debug("collector", fmt.Sprintln("Buffer size has been excited error: Maxsize: ", config.Cfg.MaxBufferSizeBytes, " vs CurrentSize: ", fi.Size())) - return 0, fmt.Errorf("buffer size has been excited: %d", fi.Size()) + logp.Debug("collector", fmt.Sprintln("Buffer size has been exceeded error: Maxsize: ", config.Cfg.MaxBufferSizeBytes, " vs CurrentSize: ", fi.Size())) + return 0, fmt.Errorf("Buffer size has been exceeded: %d", fi.Size()) } } } @@ -301,7 +302,7 @@ func (h *HEPOutputer) copyHEPbufftoFile(inbytes []byte) (int64, error) { nBytes, err := destination.Write(inbytes) if err != nil { - logp.Err("file Send HEP from buffer to file error: %v", err.Error()) + logp.Err("File send HEP from buffer to file error: %v", err.Error()) return 0, fmt.Errorf("file Send HEP from buffer to file error: %v", err.Error()) } else { logp.Debug("collector", " File Send HEP from buffer to file OK") diff --git a/sniffer/sniffer.go b/sniffer/sniffer.go index c335050..633abf2 100644 --- a/sniffer/sniffer.go +++ b/sniffer/sniffer.go @@ -714,7 +714,7 @@ func (sniffer *SnifferSetup) handleRequestExtended(conn net.Conn) { // Read the incoming connection into the buffer. n, err := conn.Read(message) if err != nil { - logp.Err("closed tcp connection [1]: %s", err.Error()) + logp.Err("Incoming tcp connection closed during read with error [1]: %s", err.Error()) break } @@ -776,7 +776,7 @@ func (sniffer *SnifferSetup) handleRequestExtended(conn net.Conn) { // Read the incoming connection into the buffer. n, err := conn.Read(message) if err != nil { - logp.Err("closed tcp connection [2]: %s", err.Error()) + logp.Err("Incoming tcp connection closed during direct read from buffer with error [2]: %s", err.Error()) bufferPool.Reset() break }