Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit c48b843

Browse files
committed
Keep it simple
1 parent f47f02a commit c48b843

File tree

1 file changed

+6
-50
lines changed

1 file changed

+6
-50
lines changed

platform/logger/log_sender.go

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
"errors"
88
"fmt"
99
"github.com/QuesmaOrg/quesma/platform/telemetry/headers"
10-
"github.com/goccy/go-json"
11-
"log"
1210
"net/http"
1311
"net/url"
1412
"strconv"
@@ -24,45 +22,6 @@ type LogSender struct {
2422
httpClient *http.Client
2523
}
2624

27-
func (logSender *LogSender) cutMessage(msg []byte) ([]byte, bool) {
28-
29-
var msgMap map[string]any
30-
if err := json.Unmarshal(msg, &msgMap); err != nil {
31-
32-
return nil, false // if not a valid JSON, return as is
33-
}
34-
35-
message, ok := msgMap["message"].(string)
36-
37-
if !ok {
38-
return nil, false // if "message" key is not present or not a string, return as is
39-
}
40-
41-
cutMark := "..."
42-
newLine := "\n"
43-
charToCut := len(message) + len(cutMark) + len(newLine) - cap(logSender.LogBuffer)
44-
45-
log.Println("XXXX LogSender: cutting message to fit buffer, charToCut:", charToCut, "message length:", len(message), "buffer capacity:", cap(logSender.LogBuffer))
46-
47-
// cutting the message will not help, let's drop it
48-
if charToCut < 0 {
49-
return nil, false // if buffer has enough space, return original message
50-
}
51-
52-
if charToCut < len(message) {
53-
msgCut := message[:len(message)-charToCut]
54-
msgMap["message"] = msgCut + cutMark
55-
} else {
56-
msgMap["message"] = message
57-
}
58-
59-
trimmedMsg, err := json.Marshal(msgMap)
60-
if err != nil {
61-
return nil, false // if marshalling fails, return as is
62-
}
63-
return append(trimmedMsg, newLine...), ok // append newline to maintain log format
64-
}
65-
6625
func (logSender *LogSender) EatLogMessage(msg []byte) struct {
6726
bufferLengthCondition bool
6827
timeCondition bool
@@ -80,15 +39,12 @@ func (logSender *LogSender) EatLogMessage(msg []byte) struct {
8039
addedBefore := false
8140
if !bufferLengthCondition && len(logSender.LogBuffer) == 0 { // msg longer than buffer, let's cut it
8241

83-
// we can the message part
84-
trimmedMsg, ok := logSender.cutMessage(msg)
85-
if ok {
86-
log.Println("XXXX LogSender: message was too long, cutting it to fit buffer")
87-
logSender.LogBuffer = append(logSender.LogBuffer, trimmedMsg...)
88-
addedBefore = true
89-
} else {
90-
log.Println("XXXX LogSender: message was too long, but could not cut it, dropping it")
91-
}
42+
// Keep it simple. Drop the message if it is too long.
43+
//
44+
// We were cutting the message before, but it leads to broken JSONs. These JSONs where dropped by the collector
45+
// afterward.
46+
//
47+
addedBefore = true
9248

9349
} else if len(logSender.LogBuffer)+len(msg) <= cap(logSender.LogBuffer) { // still fits in buffer
9450
logSender.LogBuffer = append(logSender.LogBuffer, msg...)

0 commit comments

Comments
 (0)