Skip to content

Commit

Permalink
Merge pull request #495 from go-graphite/emadolsky/reduce-useless-logs
Browse files Browse the repository at this point in the history
Reduce useless logs
  • Loading branch information
emadolsky committed Sep 12, 2022
2 parents 48e799c + 436724b commit 8dc10ec
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion carbonserver/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (listener *CarbonserverListener) renderHandler(wr http.ResponseWriter, req
zap.Strings("targets", tgs),
)

logger := TraceContextToZap(ctx, listener.accessLogger.With(
logger := TraceContextToZap(ctx, listener.logger.With(
zap.String("handler", "render"),
zap.String("url", req.URL.RequestURI()),
zap.String("peer", req.RemoteAddr),
Expand Down
22 changes: 22 additions & 0 deletions persister/whisper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package persister

import (
"errors"
"fmt"
"io/fs"
"log"
Expand All @@ -22,6 +23,8 @@ import (
)

const storeMutexCount = 32768
const maxPathLength = 4095
const maxFilenameLength = 255

type StoreFunc func(metric string)

Expand Down Expand Up @@ -255,6 +258,25 @@ func (p *Whisper) store(metric string) {
path = filepath.Join(p.rootPath, strings.ReplaceAll(metric, ".", "/")+".wsp")
}

if len(path) > maxPathLength {
p.logger.Debug("metric name exceeds limit",
zap.String("path", path),
zap.Error(errors.New("path too long")))
p.popConfirm(metric)
return
}
filenames := strings.Split(path, "/")
for _, filename := range filenames {
if len(filename) > maxFilenameLength {
p.logger.Debug("metric name exceeds limit",
zap.String("path", path),
zap.String("filename", filename),
zap.Error(errors.New("filename too long")))
p.popConfirm(metric)
return
}
}

var newFile bool
w, err := whisper.OpenWithOptions(path, &whisper.Options{
FLock: p.flock,
Expand Down
2 changes: 1 addition & 1 deletion receiver/tcp/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (rcv *TCP) HandleConnection(conn net.Conn) {
name, value, timestamp, err := parse.PlainLine(line)
if err != nil {
atomic.AddUint32(&rcv.errors, 1)
rcv.logger.Info("parse failed",
rcv.logger.Debug("parse failed",
zap.Error(err),
zap.String("peer", conn.RemoteAddr().String()),
)
Expand Down
2 changes: 1 addition & 1 deletion receiver/udp/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (rcv *UDP) receiveWorker(exit chan bool) {
name, value, timestamp, err := parse.PlainLine(line)
if err != nil {
atomic.AddUint32(&rcv.errors, 1)
rcv.logger.Info("parse failed",
rcv.logger.Debug("parse failed",
zap.Error(err),
zap.String("peer", peer.String()),
)
Expand Down

0 comments on commit 8dc10ec

Please sign in to comment.