Skip to content

Commit

Permalink
Merge pull request #564 from deniszh/dzhdanov/no-404-logs
Browse files Browse the repository at this point in the history
Optionally disable 404 error logging (fix #563)
  • Loading branch information
deniszh authored Sep 4, 2023
2 parents 880c21d + 7b9a2fc commit a3d9985
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ 1.17.x, 1.18.x, 1.19.x, 1.20.x, tip ]
go: [ 1.18.x, 1.19.x, 1.20.x, 1.21.x, tip ]

steps:
- name: Set up Go stable
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Install packaging dependencies
run: |
gem install rake fpm:1.10.2 package_cloud
GO111MODULE=off go get github.com/mitchellh/gox
go install github.com/mitchellh/gox@latest
- name: Check packaging
run: |
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@ graphite-web-10-strict-mode = true
# Return a 404 instead of empty results. Set to true if you are serving requests to graphite-web
empty-result-ok = false

# Do not log 404 (metric not found) errors
do-not-log-404s = false

# Allows to keep track for "last time readed" between restarts, leave empty to disable
internal-stats-dir = ""
# Calculate /render request time percentiles for the bucket, '95' means calculate 95th Percentile.
Expand Down
1 change: 1 addition & 0 deletions carbon/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ func (app *App) Start(version string) (err error) {
carbonserver.SetWhisperData(conf.Whisper.DataDir)
carbonserver.SetMaxGlobs(conf.Carbonserver.MaxGlobs)
carbonserver.SetEmptyResultOk(conf.Carbonserver.EmptyResultOk)
carbonserver.SetDoNotLog404s(conf.Carbonserver.DoNotLog404s)
carbonserver.SetFLock(app.Config.Whisper.FLock)
carbonserver.SetCompressed(app.Config.Whisper.Compressed)
carbonserver.SetRemoveEmptyFile(app.Config.Whisper.RemoveEmptyFile)
Expand Down
1 change: 1 addition & 0 deletions carbon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ type carbonserverConfig struct {
MaxGlobs int `toml:"max-globs"`
FailOnMaxGlobs bool `toml:"fail-on-max-globs"`
EmptyResultOk bool `toml:"empty-result-ok"`
DoNotLog404s bool `toml:"do-not-log-404s"`
MetricsAsCounters bool `toml:"metrics-as-counters"`
TrigramIndex bool `toml:"trigram-index"`
InternalStatsDir string `toml:"internal-stats-dir"`
Expand Down
4 changes: 4 additions & 0 deletions carbonserver/carbonserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ type CarbonserverListener struct {
buckets int
maxGlobs int
emptyResultOk bool
doNotLog404s bool
failOnMaxGlobs bool
percentiles []int
scanFrequency time.Duration
Expand Down Expand Up @@ -508,6 +509,9 @@ func (listener *CarbonserverListener) SetMaxGlobs(maxGlobs int) {
func (listener *CarbonserverListener) SetEmptyResultOk(emptyResultOk bool) {
listener.emptyResultOk = emptyResultOk
}
func (listener *CarbonserverListener) SetDoNotLog404s(doNotLog404s bool) {
listener.doNotLog404s = doNotLog404s
}
func (listener *CarbonserverListener) SetFailOnMaxGlobs(failOnMaxGlobs bool) {
listener.failOnMaxGlobs = failOnMaxGlobs
}
Expand Down
26 changes: 15 additions & 11 deletions carbonserver/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,14 @@ func (listener *CarbonserverListener) renderHandler(wr http.ResponseWriter, req
}

if response.metricsFetched == 0 && !listener.emptyResultOk {
accessLogger.Error("fetch failed",
zap.Duration("runtime_seconds", time.Since(t0)),
zap.String("reason", "no metrics found"),
zap.Int("http_code", http.StatusNotFound),
zap.Error(err),
)
if !listener.doNotLog404s {
accessLogger.Error("fetch failed",
zap.Duration("runtime_seconds", time.Since(t0)),
zap.String("reason", "no metrics found"),
zap.Int("http_code", http.StatusNotFound),
zap.Error(err),
)
}
http.Error(wr, "Bad request (Not Found)", http.StatusNotFound)
return
}
Expand Down Expand Up @@ -808,11 +810,13 @@ func (listener *CarbonserverListener) Render(req *protov2.MultiFetchRequest, str
}

if metricsFetched == 0 && !listener.emptyResultOk {
accessLogger.Error("fetch failed",
zap.Duration("runtime_seconds", time.Since(t0)),
zap.String("reason", "no metrics found"),
zap.Error(err),
)
if !listener.doNotLog404s {
accessLogger.Error("fetch failed",
zap.Duration("runtime_seconds", time.Since(t0)),
zap.String("reason", "no metrics found"),
zap.Error(err),
)
}
return status.New(codes.NotFound, "no metrics found").Err()
}

Expand Down
3 changes: 3 additions & 0 deletions go-carbon.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ graphite-web-10-strict-mode = true
# Return a 404 instead of empty results. Set to true if you are serving requests to graphite-web
empty-result-ok = false

# Do not log 404 (metric not found) errors
do-not-log-404s = false

# Allows to keep track for "last time readed" between restarts, leave empty to disable
internal-stats-dir = ""
# Calculate /render request time percentiles for the bucket, '95' means calculate 95th Percentile.
Expand Down

0 comments on commit a3d9985

Please sign in to comment.