Skip to content

Commit

Permalink
Merge pull request #9757 from influxdata/js-suppress-write-log
Browse files Browse the repository at this point in the history
Add suppress-write-log option to disable the write log when the log is enabled
  • Loading branch information
jsternberg authored Apr 23, 2018
2 parents dff3493 + a7e1da5 commit 6d32539
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
3 changes: 3 additions & 0 deletions etc/config.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@
# Determines whether HTTP request logging is enabled.
# log-enabled = true

# Determines whether the HTTP write request logs should be suppressed when the log is enabled.
# suppress-write-log = false

# When HTTP request logging is enabled, this option specifies the path where
# log entries should be written. If unspecified, the default is to write to stderr, which
# intermingles HTTP logs with internal InfluxDB logging.
Expand Down
1 change: 1 addition & 0 deletions services/httpd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Config struct {
BindAddress string `toml:"bind-address"`
AuthEnabled bool `toml:"auth-enabled"`
LogEnabled bool `toml:"log-enabled"`
SuppressWriteLog bool `toml:"suppress-write-log"`
WriteTracing bool `toml:"write-tracing"`
PprofEnabled bool `toml:"pprof-enabled"`
HTTPSEnabled bool `toml:"https-enabled"`
Expand Down
8 changes: 7 additions & 1 deletion services/httpd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ func NewHandler(c Config) *Handler {
requestTracker: NewRequestTracker(),
}

// Disable the write log if they have been suppressed.
writeLogEnabled := c.LogEnabled
if c.SuppressWriteLog {
writeLogEnabled = false
}

h.AddRoutes([]Route{
Route{
"query-options", // Satisfy CORS checks.
Expand All @@ -147,7 +153,7 @@ func NewHandler(c Config) *Handler {
},
Route{
"write", // Data-ingest route.
"POST", "/write", true, true, h.serveWrite,
"POST", "/write", true, writeLogEnabled, h.serveWrite,
},
Route{
"prometheus-write", // Prometheus remote write
Expand Down
29 changes: 29 additions & 0 deletions services/httpd/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,32 @@ func TestHandler_Write_EntityTooLarge_ContentLength(t *testing.T) {
}
}

func TestHandler_Write_SuppressLog(t *testing.T) {
var buf bytes.Buffer
c := httpd.NewConfig()
c.SuppressWriteLog = true
h := NewHandlerWithConfig(c)
h.CLFLogger = log.New(&buf, "", log.LstdFlags)
h.MetaClient.DatabaseFn = func(name string) *meta.DatabaseInfo {
return &meta.DatabaseInfo{}
}
h.PointsWriter.WritePointsFn = func(database, retentionPolicy string, consistencyLevel models.ConsistencyLevel, user meta.User, points []models.Point) error {
return nil
}

b := strings.NewReader("cpu,host=server01 value=2\n")
w := httptest.NewRecorder()
h.ServeHTTP(w, MustNewRequest("POST", "/write?db=foo", b))
if w.Code != http.StatusNoContent {
t.Fatalf("unexpected status: %d", w.Code)
}

// If the log has anything in it, this failed.
if buf.Len() > 0 {
t.Fatalf("expected no bytes to be written to the log, got %d", buf.Len())
}
}

// onlyReader implements io.Reader only to ensure Request.ContentLength is not set
type onlyReader struct {
r io.Reader
Expand Down Expand Up @@ -914,7 +940,10 @@ func NewHandler(requireAuthentication bool) *Handler {
config := httpd.NewConfig()
config.AuthEnabled = requireAuthentication
config.SharedSecret = "super secret key"
return NewHandlerWithConfig(config)
}

func NewHandlerWithConfig(config httpd.Config) *Handler {
h := &Handler{
Handler: httpd.NewHandler(config),
}
Expand Down

0 comments on commit 6d32539

Please sign in to comment.