Merge pull request #9757 from influxdata/js-suppress-write-log

Add suppress-write-log option to disable the write log when the log is enabled
pull/9759/head
Jonathan A. Sternberg 2018-04-23 13:09:54 -05:00 committed by GitHub
commit 6d325398cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 1 deletions

View File

@ -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.

View File

@ -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"`

View File

@ -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.
@ -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

View File

@ -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
@ -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),
}