Skip to content

Commit 7914e85

Browse files
authored
Merge pull request #305 from Dletta/master
Small improvements for Connection error logic, Capitalization across …
2 parents 9d102bb + cc080a1 commit 7914e85

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

publish/hep.go

+18-17
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func NewHEPOutputer(serverAddr string) (*HEPOutputer, error) {
3939
errCnt := 0
4040
for n := range a {
4141
if err := h.ConnectServer(n); err != nil {
42-
logp.Err("%v", err)
42+
logp.Err("Error connecting to HEP server (%s): %v", h.addr[n], err)
4343
errCnt++
4444
} else {
4545
if config.Cfg.HEPBufferEnable {
@@ -52,7 +52,7 @@ func NewHEPOutputer(serverAddr string) (*HEPOutputer, error) {
5252
}
5353
}
5454
if errCnt == l {
55-
return nil, fmt.Errorf("cannot establish a connection")
55+
return nil, fmt.Errorf("Cannot establish a connection")
5656
}
5757

5858
go h.Start()
@@ -61,12 +61,13 @@ func NewHEPOutputer(serverAddr string) (*HEPOutputer, error) {
6161

6262
func (h *HEPOutputer) Close(n int) {
6363
if err := h.client[n].conn.Close(); err != nil {
64-
logp.Err("cannnot close connection to %s: %v", h.addr[n], err)
64+
logp.Err("Cannot close connection to %s: %v", h.addr[n], err)
6565
}
6666
}
6767

6868
func (h *HEPOutputer) ReConnect(n int) (err error) {
6969
if err = h.ConnectServer(n); err != nil {
70+
logp.Err("Error reconnecting to HEP server (%s): %v", h.addr[n], err)
7071
return err
7172
}
7273
h.client[n].writer.Reset(h.client[n].conn)
@@ -154,7 +155,7 @@ func (h *HEPOutputer) Send(msg []byte) {
154155
var err error
155156

156157
if h.client[n].conn == nil || h.client[n].writer == nil {
157-
logp.Debug("connection is not up", fmt.Sprintf("index: %d, Len: %d, once: %v", n, len(h.addr), onceSent))
158+
logp.Debug("Connection is not up", fmt.Sprintf("index: %d, Len: %d, once: %v", n, len(h.addr), onceSent))
158159
err = fmt.Errorf("connection is broken")
159160
} else {
160161
h.client[n].writer.Write(msg)
@@ -216,13 +217,13 @@ func (h *HEPOutputer) copyHEPFileOut(n int) (int, error) {
216217

217218
defer func() {
218219
if r := recover(); r != nil {
219-
logp.Err("copy hep file out panic: %v, %v", r, debug.Stack())
220+
logp.Err("Copy hep file out panic: %v, %v", r, debug.Stack())
220221
return
221222
}
222223
}()
223224

224225
if _, err := os.Stat(config.Cfg.HEPBufferFile); err != nil {
225-
logp.Debug("file doesn't exists: ", config.Cfg.HEPBufferFile)
226+
logp.Debug("File doesn't exists: ", config.Cfg.HEPBufferFile)
226227
return 1, nil
227228
}
228229

@@ -233,15 +234,15 @@ func (h *HEPOutputer) copyHEPFileOut(n int) (int, error) {
233234
}
234235

235236
if h.client[n].conn == nil {
236-
logp.Err("connection is not up....")
237-
return 0, fmt.Errorf("connection is broken")
237+
logp.Err("Connection is not up....")
238+
return 0, fmt.Errorf("Connection is broken")
238239
}
239240

240241
//Send Logged HEP upon reconnect out to backend
241242
hl, err := h.client[n].conn.Write(HEPFileData)
242243
if err != nil {
243244
promstats.HepFileFlushesError.Inc()
244-
return 0, fmt.Errorf("bad write to socket")
245+
return 0, fmt.Errorf("Bad write to socket")
245246
}
246247

247248
err = h.client[n].writer.Flush()
@@ -268,40 +269,40 @@ func (h *HEPOutputer) copyHEPbufftoFile(inbytes []byte) (int64, error) {
268269

269270
defer func() {
270271
if r := recover(); r != nil {
271-
logp.Err("copy buffer to panic: %v,\n%s", r, debug.Stack())
272+
logp.Err("Copy buffer to panic: %v,\n%s", r, debug.Stack())
272273
return
273274
}
274275
}()
275276

276277
if config.Cfg.HEPBufferDebug {
277-
logp.Err("adding packet to BUFFER: %s\n", string(inbytes))
278+
logp.Err("Adding packet to BUFFER: %s\n", string(inbytes))
278279
}
279280

280281
destination, err := os.OpenFile(config.Cfg.HEPBufferFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
281282
if err != nil {
282-
logp.Err("open HEP file error: %v\n", err)
283-
return 0, fmt.Errorf("open HEP file error: %v", err)
283+
logp.Err("Open HEP file error: %v\n", err)
284+
return 0, fmt.Errorf("Open HEP file error: %v", err)
284285
}
285286

286287
defer destination.Close()
287288

288289
if config.Cfg.MaxBufferSizeBytes > 0 {
289290
fi, err := destination.Stat()
290291
if err != nil {
291-
logp.Debug("collector", fmt.Sprintf("couldn't retrive stats from buffer file error: %v", err.Error()))
292+
logp.Debug("collector", fmt.Sprintf("Couldn't retrive stats from buffer file error: %v", err.Error()))
292293
return 0, err
293294
} else {
294295
if fi.Size() >= config.Cfg.MaxBufferSizeBytes {
295-
logp.Debug("collector", fmt.Sprintln("Buffer size has been excited error: Maxsize: ", config.Cfg.MaxBufferSizeBytes, " vs CurrentSize: ", fi.Size()))
296-
return 0, fmt.Errorf("buffer size has been excited: %d", fi.Size())
296+
logp.Debug("collector", fmt.Sprintln("Buffer size has been exceeded error: Maxsize: ", config.Cfg.MaxBufferSizeBytes, " vs CurrentSize: ", fi.Size()))
297+
return 0, fmt.Errorf("Buffer size has been exceeded: %d", fi.Size())
297298
}
298299
}
299300
}
300301

301302
nBytes, err := destination.Write(inbytes)
302303

303304
if err != nil {
304-
logp.Err("file Send HEP from buffer to file error: %v", err.Error())
305+
logp.Err("File send HEP from buffer to file error: %v", err.Error())
305306
return 0, fmt.Errorf("file Send HEP from buffer to file error: %v", err.Error())
306307
} else {
307308
logp.Debug("collector", " File Send HEP from buffer to file OK")

sniffer/sniffer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ func (sniffer *SnifferSetup) handleRequestExtended(conn net.Conn) {
714714
// Read the incoming connection into the buffer.
715715
n, err := conn.Read(message)
716716
if err != nil {
717-
logp.Err("closed tcp connection [1]: %s", err.Error())
717+
logp.Err("Incoming tcp connection closed during read with error [1]: %s", err.Error())
718718
break
719719
}
720720

@@ -776,7 +776,7 @@ func (sniffer *SnifferSetup) handleRequestExtended(conn net.Conn) {
776776
// Read the incoming connection into the buffer.
777777
n, err := conn.Read(message)
778778
if err != nil {
779-
logp.Err("closed tcp connection [2]: %s", err.Error())
779+
logp.Err("Incoming tcp connection closed during direct read from buffer with error [2]: %s", err.Error())
780780
bufferPool.Reset()
781781
break
782782
}

0 commit comments

Comments
 (0)