disable user function logs at debug level config (#1179)

This commit is contained in:
Reed Allman
2018-08-21 21:02:49 -07:00
committed by GitHub
parent e1c87e000d
commit a6d60551ab
4 changed files with 22 additions and 10 deletions

View File

@@ -342,7 +342,7 @@ func TestLoggerIsStringerAndWorks(t *testing.T) {
// TODO test limit writer, logrus writer, etc etc
var call models.Call
logger := setupLogger(context.Background(), 1*1024*1024, &call)
logger := setupLogger(context.Background(), 1*1024*1024, true, &call)
if _, ok := logger.(fmt.Stringer); !ok {
// NOTE: if you are reading, maybe what you've done is ok, but be aware we were relying on this for optimization...
@@ -366,7 +366,7 @@ func TestLoggerIsStringerAndWorks(t *testing.T) {
func TestLoggerTooBig(t *testing.T) {
var call models.Call
logger := setupLogger(context.Background(), 10, &call)
logger := setupLogger(context.Background(), 10, true, &call)
str := fmt.Sprintf("0 line\n1 l\n-----max log size 10 bytes exceeded, truncating log-----\n")

View File

@@ -431,7 +431,7 @@ func (a *agent) GetCall(opts ...CallOpt) (Call, error) {
c.handler = a.da
c.ct = a
c.stderr = setupLogger(c.req.Context(), a.cfg.MaxLogSize, c.Call)
c.stderr = setupLogger(c.req.Context(), a.cfg.MaxLogSize, !a.cfg.DisableDebugUserLogs, c.Call)
if c.w == nil {
// send STDOUT to logs if no writer given (async...)
// TODO we could/should probably make this explicit to GetCall, ala 'WithLogger', but it's dupe code (who cares?)

View File

@@ -33,6 +33,7 @@ type Config struct {
EnableNBResourceTracker bool `json:"enable_nb_resource_tracker"`
MaxTmpFsInodes uint64 `json:"max_tmpfs_inodes"`
DisableReadOnlyRootFs bool `json:"disable_readonly_rootfs"`
DisableDebugUserLogs bool `json:"disable_debug_user_logs"`
}
const (
@@ -83,6 +84,8 @@ const (
EnvMaxTmpFsInodes = "FN_MAX_TMPFS_INODES"
// EnvDisableReadOnlyRootFs makes the root fs for a container have rw permissions, by default it is read only
EnvDisableReadOnlyRootFs = "FN_DISABLE_READONLY_ROOTFS"
// EnvDisableDebugUserLogs disables user function logs being logged at level debug. wise to enable for production.
EnvDisableDebugUserLogs = "FN_DISABLE_DEBUG_USER_LOGS"
// MaxMsDisabled is used to determine whether mr freeze is lying in wait. TODO remove this manuever
MaxMsDisabled = time.Duration(math.MaxInt64)
@@ -137,6 +140,9 @@ func NewConfig() (*Config, error) {
if _, ok := os.LookupEnv(EnvDisableReadOnlyRootFs); ok {
cfg.DisableReadOnlyRootFs = true
}
if _, ok := os.LookupEnv(EnvDisableDebugUserLogs); ok {
cfg.DisableDebugUserLogs = true
}
if cfg.EjectIdle == time.Duration(0) {
return cfg, fmt.Errorf("error %s cannot be zero", EnvEjectIdle)

View File

@@ -25,7 +25,7 @@ var (
// multiWriteCloser ignores errors. Close will flush the line writers
// appropriately. The returned io.ReadWriteCloser is not safe for use after
// calling Close.
func setupLogger(ctx context.Context, maxSize uint64, c *models.Call) io.ReadWriteCloser {
func setupLogger(ctx context.Context, maxSize uint64, debug bool, c *models.Call) io.ReadWriteCloser {
lbuf := bufPool.Get().(*bytes.Buffer)
dbuf := logPool.Get().(*bytes.Buffer)
@@ -41,14 +41,20 @@ func setupLogger(ctx context.Context, maxSize uint64, c *models.Call) io.ReadWri
// we don't need to log per line to db, but we do need to limit it
limitw := &nopCloser{newLimitWriter(int(maxSize), dbuf)}
// order matters, in that closer should be last and limit should be next to last
mw := make(multiWriteCloser, 0, 3)
if debug {
// accumulate all line writers, wrap in same line writer (to re-use buffer)
stderrLogger := common.Logger(ctx).WithFields(logrus.Fields{"user_log": true, "app_id": c.AppID, "path": c.Path, "image": c.Image, "call_id": c.ID})
loggo := &nopCloser{&logWriter{stderrLogger}}
// we don't need to limit the log writer(s), but we do need it to dispense lines
linew := newLineWriterWithBuffer(lbuf, loggo)
mw = append(mw, linew)
}
mw := multiWriteCloser{linew, limitw, &fCloser{close}}
mw = append(mw, limitw, &fCloser{close})
return &rwc{mw, dbuf}
}