From 0dc687cffc0542608f1ee0777fd57eff88a1dad3 Mon Sep 17 00:00:00 2001 From: james pickett Date: Mon, 20 Nov 2023 09:39:14 -0800 Subject: [PATCH 1/5] override log shipping level on start up --- cmd/launcher/launcher.go | 4 + pkg/agent/flags/flag_controller.go | 93 ++++++++++++++--------- pkg/agent/flags/flag_value_string.go | 16 ++++ pkg/agent/flags/flag_value_string_test.go | 11 ++- pkg/agent/knapsack/knapsack.go | 3 + pkg/agent/types/flags.go | 3 +- pkg/agent/types/mocks/knapsack.go | 11 ++- pkg/log/logshipper/logshipper.go | 15 ++-- pkg/sendbuffer/sendbuffer.go | 15 ++-- 9 files changed, 116 insertions(+), 55 deletions(-) diff --git a/cmd/launcher/launcher.go b/cmd/launcher/launcher.go index 6b9e9907c..348de4f05 100644 --- a/cmd/launcher/launcher.go +++ b/cmd/launcher/launcher.go @@ -179,6 +179,10 @@ func runLauncher(ctx context.Context, cancel func(), slogger, systemSlogger *mul })) } + // Run launcher in debug mode for first 10 minutes. Intentionally doing this after setting up + // stderr debug logger becaues we don't want to write evertyhing to stderr. + k.SetLogShippingLevelOverride("debug", 10*time.Minute) + // Need to set up the log shipper so that we can get the logger early // and pass it to the various systems. var logShipper *logshipper.LogShipper diff --git a/pkg/agent/flags/flag_controller.go b/pkg/agent/flags/flag_controller.go index dbfb248bd..9832472a7 100644 --- a/pkg/agent/flags/flag_controller.go +++ b/pkg/agent/flags/flag_controller.go @@ -18,21 +18,22 @@ import ( // FlagController is responsible for retrieving flag values from the appropriate sources, // determining precedence, sanitizing flag values, and notifying observers of changes. type FlagController struct { - logger log.Logger - cmdLineOpts *launcher.Options - agentFlagsStore types.KVStore - overrideMutex sync.RWMutex - controlRequestOverride FlagValueOverride - observers map[types.FlagsChangeObserver][]keys.FlagKey - observersMutex sync.RWMutex + logger log.Logger + cmdLineOpts *launcher.Options + agentFlagsStore types.KVStore + overrideMutex sync.RWMutex + overrides map[keys.FlagKey]*Override + observers map[types.FlagsChangeObserver][]keys.FlagKey + observersMutex sync.RWMutex } func NewFlagController(logger log.Logger, agentFlagsStore types.KVStore, opts ...Option) *FlagController { fc := &FlagController{ - logger: logger, + logger: log.With(logger, "component", "flag_controller"), cmdLineOpts: &launcher.Options{}, agentFlagsStore: agentFlagsStore, observers: make(map[types.FlagsChangeObserver][]keys.FlagKey), + overrides: make(map[keys.FlagKey]*Override), } for _, opt := range opts { @@ -114,6 +115,44 @@ func (fc *FlagController) notifyObservers(flagKeys ...keys.FlagKey) { } } +func (fc *FlagController) overrideFlag(key keys.FlagKey, duration time.Duration, value any) { + // Always notify observers when overrides start, so they know to refresh. + // Defering this before defering unlocking the mutex so that notifications occur outside of the critical section. + defer fc.notifyObservers(key) + + fc.overrideMutex.Lock() + defer fc.overrideMutex.Unlock() + + level.Info(fc.logger).Log( + "msg", "overriding flag", + "key", key, + "value", value, + "duration", duration, + ) + + override, ok := fc.overrides[key] + if !ok || override.Value() == nil { + // Creating the override implicitly causes future ControlRequestInterval retrievals to use the override until expiration + override = &Override{} + fc.overrides[key] = override + } + + overrideExpired := func(key keys.FlagKey) { + // Always notify observers when overrides expire, so they know to refresh. + // Defering this before defering unlocking the mutex so that notifications occur outside of the critical section. + defer fc.notifyObservers(key) + + fc.overrideMutex.Lock() + defer fc.overrideMutex.Unlock() + + // Deleting the override implictly allows the next value to take precedence + delete(fc.overrides, key) + } + + // start the override + fc.overrides[key].Start(key, value, duration, overrideExpired) +} + func (fc *FlagController) AutoloadedExtensions() []string { return fc.cmdLineOpts.AutoloadedExtensions } @@ -250,40 +289,15 @@ func (fc *FlagController) ControlServerURL() string { func (fc *FlagController) SetControlRequestInterval(interval time.Duration) error { return fc.setControlServerValue(keys.ControlRequestInterval, durationToBytes(interval)) } -func (fc *FlagController) SetControlRequestIntervalOverride(interval, duration time.Duration) { - // Always notify observers when overrides start, so they know to refresh. - // Defering this before defering unlocking the mutex so that notifications occur outside of the critical section. - defer fc.notifyObservers(keys.ControlRequestInterval) - - fc.overrideMutex.Lock() - defer fc.overrideMutex.Unlock() - - if fc.controlRequestOverride == nil || fc.controlRequestOverride.Value() == nil { - // Creating the override implicitly causes future ControlRequestInterval retrievals to use the override until expiration - fc.controlRequestOverride = &Override{} - } - - overrideExpired := func(key keys.FlagKey) { - // Always notify observers when overrides expire, so they know to refresh. - // Defering this before defering unlocking the mutex so that notifications occur outside of the critical section. - defer fc.notifyObservers(key) - - fc.overrideMutex.Lock() - defer fc.overrideMutex.Unlock() - - // Deleting the override implictly allows the next value to take precedence - fc.controlRequestOverride = nil - } - - // Start a new override, or re-start an existing one with a new value, duration, and expiration - fc.controlRequestOverride.Start(keys.ControlRequestInterval, interval, duration, overrideExpired) +func (fc *FlagController) SetControlRequestIntervalOverride(value time.Duration, duration time.Duration) { + fc.overrideFlag(keys.ControlRequestInterval, duration, value) } func (fc *FlagController) ControlRequestInterval() time.Duration { fc.overrideMutex.RLock() defer fc.overrideMutex.RUnlock() return NewDurationFlagValue(fc.logger, keys.ControlRequestInterval, - WithOverride(fc.controlRequestOverride), + WithOverride(fc.overrides[keys.ControlRequestInterval]), WithDefault(fc.cmdLineOpts.ControlRequestInterval), WithMin(5*time.Second), WithMax(10*time.Minute), @@ -490,10 +504,17 @@ func (fc *FlagController) LogIngestServerURL() string { func (fc *FlagController) SetLogShippingLevel(level string) error { return fc.setControlServerValue(keys.LogShippingLevel, []byte(level)) } +func (fc *FlagController) SetLogShippingLevelOverride(value string, duration time.Duration) { + fc.overrideFlag(keys.LogShippingLevel, duration, value) +} func (fc *FlagController) LogShippingLevel() string { + fc.overrideMutex.RLock() + defer fc.overrideMutex.RUnlock() + const defaultLevel = "info" return NewStringFlagValue( + WithOverrideString(fc.overrides[keys.LogShippingLevel]), WithDefaultString(defaultLevel), WithSanitizer(func(value string) string { value = strings.ToLower(value) diff --git a/pkg/agent/flags/flag_value_string.go b/pkg/agent/flags/flag_value_string.go index 3de36090a..bd6663cd4 100644 --- a/pkg/agent/flags/flag_value_string.go +++ b/pkg/agent/flags/flag_value_string.go @@ -2,6 +2,12 @@ package flags type stringFlagValueOption func(*stringFlagValue) +func WithOverrideString(override FlagValueOverride) stringFlagValueOption { + return func(s *stringFlagValue) { + s.override = override + } +} + func WithDefaultString(defaultVal string) stringFlagValueOption { return func(s *stringFlagValue) { s.defaultVal = defaultVal @@ -17,6 +23,7 @@ func WithSanitizer(sanitizer func(value string) string) stringFlagValueOption { type stringFlagValue struct { defaultVal string sanitizer func(value string) string + override FlagValueOverride } func NewStringFlagValue(opts ...stringFlagValueOption) *stringFlagValue { @@ -35,9 +42,18 @@ func (s *stringFlagValue) get(controlServerValue []byte) string { stringValue = string(controlServerValue) } + if s.override != nil && s.override.Value() != nil { + // An override was provided, if it's valid let it take precedence + value, ok := s.override.Value().(string) + if ok { + stringValue = value + } + } + // Run the string through a sanitizer, if one was provided if s.sanitizer != nil { stringValue = s.sanitizer(stringValue) } + return stringValue } diff --git a/pkg/agent/flags/flag_value_string_test.go b/pkg/agent/flags/flag_value_string_test.go index aded6c0d9..d2d16bb29 100644 --- a/pkg/agent/flags/flag_value_string_test.go +++ b/pkg/agent/flags/flag_value_string_test.go @@ -3,14 +3,15 @@ package flags import ( "testing" + "github.com/kolide/launcher/pkg/agent/flags/mocks" "github.com/stretchr/testify/assert" ) func TestFlagValueString(t *testing.T) { t.Parallel() - // mockOverride := mocks.NewFlagValueOverride(t) - // mockOverride.On("Value").Return(7 * time.Second) + mockOverride := mocks.NewFlagValueOverride(t) + mockOverride.On("Value").Return("override_value") tests := []struct { name string @@ -52,6 +53,12 @@ func TestFlagValueString(t *testing.T) { controlServerValue: []byte("control-server-says-this"), expected: "SANITIZED control-server-says-this", }, + { + name: "control server with override", + options: []stringFlagValueOption{WithDefaultString("default_value"), WithOverrideString(mockOverride)}, + controlServerValue: []byte("enabled"), + expected: mockOverride.Value().(string), + }, } for _, tt := range tests { tt := tt diff --git a/pkg/agent/knapsack/knapsack.go b/pkg/agent/knapsack/knapsack.go index 00cda2c90..a36e46df3 100644 --- a/pkg/agent/knapsack/knapsack.go +++ b/pkg/agent/knapsack/knapsack.go @@ -436,6 +436,9 @@ func (k *knapsack) LogIngestServerURL() string { func (k *knapsack) SetLogShippingLevel(level string) error { return k.flags.SetLogShippingLevel(level) } +func (k *knapsack) SetLogShippingLevelOverride(value string, duration time.Duration) { + k.flags.SetLogShippingLevelOverride(value, duration) +} func (k *knapsack) LogShippingLevel() string { return k.flags.LogShippingLevel() } diff --git a/pkg/agent/types/flags.go b/pkg/agent/types/flags.go index 1b2955b02..ba014b0a7 100644 --- a/pkg/agent/types/flags.go +++ b/pkg/agent/types/flags.go @@ -89,7 +89,7 @@ type Flags interface { // ControlRequestInterval is the interval at which control client will check for updates from the control server. SetControlRequestInterval(interval time.Duration) error // SetControlRequestIntervalOverride stores an interval to be temporarily used as an override of any other interval, until the duration has elapased. - SetControlRequestIntervalOverride(interval, duration time.Duration) + SetControlRequestIntervalOverride(value time.Duration, duration time.Duration) ControlRequestInterval() time.Duration // DisableControlTLS disables TLS transport with the control server. @@ -183,6 +183,7 @@ type Flags interface { // LogShippingLevel is the level at which logs should be shipped to the server SetLogShippingLevel(level string) error + SetLogShippingLevelOverride(value string, duration time.Duration) LogShippingLevel() string // TraceIngestServerURL is the URL of the ingest server for traces diff --git a/pkg/agent/types/mocks/knapsack.go b/pkg/agent/types/mocks/knapsack.go index 12e92b657..855b95adf 100644 --- a/pkg/agent/types/mocks/knapsack.go +++ b/pkg/agent/types/mocks/knapsack.go @@ -926,9 +926,9 @@ func (_m *Knapsack) SetControlRequestInterval(interval time.Duration) error { return r0 } -// SetControlRequestIntervalOverride provides a mock function with given fields: interval, duration -func (_m *Knapsack) SetControlRequestIntervalOverride(interval time.Duration, duration time.Duration) { - _m.Called(interval, duration) +// SetControlRequestIntervalOverride provides a mock function with given fields: value, duration +func (_m *Knapsack) SetControlRequestIntervalOverride(value time.Duration, duration time.Duration) { + _m.Called(value, duration) } // SetControlServerURL provides a mock function with given fields: url @@ -1169,6 +1169,11 @@ func (_m *Knapsack) SetLogShippingLevel(level string) error { return r0 } +// SetLogShippingLevelOverride provides a mock function with given fields: value, duration +func (_m *Knapsack) SetLogShippingLevelOverride(value string, duration time.Duration) { + _m.Called(value, duration) +} + // SetLoggingInterval provides a mock function with given fields: interval func (_m *Knapsack) SetLoggingInterval(interval time.Duration) error { ret := _m.Called(interval) diff --git a/pkg/log/logshipper/logshipper.go b/pkg/log/logshipper/logshipper.go index f9723b2b9..83cc00233 100644 --- a/pkg/log/logshipper/logshipper.go +++ b/pkg/log/logshipper/logshipper.go @@ -21,7 +21,7 @@ import ( const ( truncatedFormatString = "%s[TRUNCATED]" defaultSendInterval = 1 * time.Minute - debugSendInterval = 1 * time.Second + debugSendInterval = 5 * time.Second ) type LogShipper struct { @@ -43,10 +43,6 @@ func New(k types.Knapsack, baseLogger log.Logger) *LogShipper { sender := newAuthHttpSender() sendInterval := defaultSendInterval - if k.Debug() { - sendInterval = debugSendInterval - } - sendBuffer := sendbuffer.New(sender, sendbuffer.WithSendInterval(sendInterval)) // setting a ulid as session_ulid allows us to follow a single run of launcher @@ -63,7 +59,7 @@ func New(k types.Knapsack, baseLogger log.Logger) *LogShipper { } ls.slogLevel = new(slog.LevelVar) - ls.slogLevel.Set(slog.LevelError) + ls.slogLevel.Set(slog.LevelInfo) ls.Ping() return ls @@ -91,9 +87,13 @@ func (ls *LogShipper) Ping() { } startingLevel := ls.slogLevel.Level() + sendInterval := defaultSendInterval + switch ls.knapsack.LogShippingLevel() { case "debug": ls.slogLevel.Set(slog.LevelDebug) + // if we using debug level logging, send logs more frequently + sendInterval = debugSendInterval case "info": ls.slogLevel.Set(slog.LevelInfo) case "warn": @@ -111,9 +111,12 @@ func (ls *LogShipper) Ping() { ls.knapsack.Slogger().Info("log shipping level changed", "old_log_level", startingLevel.String(), "new_log_level", ls.slogLevel.Level().String(), + "send_interval", sendInterval.String(), ) } + ls.sendBuffer.SetSendInterval(sendInterval) + ls.isShippingEnabled = ls.sender.endpoint != "" ls.addDeviceIdentifyingAttributesToLogger() diff --git a/pkg/sendbuffer/sendbuffer.go b/pkg/sendbuffer/sendbuffer.go index 09cec52ca..9779ca638 100644 --- a/pkg/sendbuffer/sendbuffer.go +++ b/pkg/sendbuffer/sendbuffer.go @@ -26,7 +26,7 @@ type SendBuffer struct { writeMutex, sendMutex sync.Mutex logger log.Logger sender sender - sendInterval time.Duration + sendTicker *time.Ticker isSending bool } @@ -53,7 +53,7 @@ func WithLogger(logger log.Logger) option { // WithSendInterval sets the interval at which the buffer will send data. func WithSendInterval(sendInterval time.Duration) option { return func(sb *SendBuffer) { - sb.sendInterval = sendInterval + sb.sendTicker.Reset(sendInterval) } } @@ -62,9 +62,9 @@ func New(sender sender, opts ...option) *SendBuffer { maxStorageSize: defaultMaxSize, maxSendSize: defaultMaxSendSize, sender: sender, - sendInterval: 1 * time.Minute, logger: log.NewNopLogger(), isSending: false, + sendTicker: time.NewTicker(1 * time.Minute), } for _, opt := range opts { @@ -129,16 +129,13 @@ func (sb *SendBuffer) Run(ctx context.Context) error { sb.isSending = false }() - ticker := time.NewTicker(sb.sendInterval) - defer ticker.Stop() - for { if err := sb.sendAndPurge(); err != nil { sb.logger.Log("msg", "failed to send and purge", "err", err) } select { - case <-ticker.C: + case <-sb.sendTicker.C: continue case <-ctx.Done(): return nil @@ -146,6 +143,10 @@ func (sb *SendBuffer) Run(ctx context.Context) error { } } +func (sb *SendBuffer) SetSendInterval(sendInterval time.Duration) { + sb.sendTicker.Reset(sendInterval) +} + func (sb *SendBuffer) DeleteAllData() { sb.writeMutex.Lock() defer sb.writeMutex.Unlock() From d0f81b2b1ea0e615562f0d6c44a8ef189db9fd0d Mon Sep 17 00:00:00 2001 From: james pickett Date: Mon, 20 Nov 2023 10:16:40 -0800 Subject: [PATCH 2/5] register log shipper for flag changes --- cmd/launcher/launcher.go | 1 - pkg/log/logshipper/logshipper.go | 9 +++++++++ pkg/log/logshipper/logshipper_test.go | 8 +++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/cmd/launcher/launcher.go b/cmd/launcher/launcher.go index dbd4cf877..e89c90f2f 100644 --- a/cmd/launcher/launcher.go +++ b/cmd/launcher/launcher.go @@ -361,7 +361,6 @@ func runLauncher(ctx context.Context, cancel func(), slogger, systemSlogger *mul if logShipper != nil { runGroup.Add("logShipper", logShipper.Run, logShipper.Stop) controlService.RegisterSubscriber(authTokensSubsystemName, logShipper) - controlService.RegisterSubscriber(agentFlagsSubsystemName, logShipper) } if metadataWriter := internal.NewMetadataWriter(logger, k); metadataWriter == nil { diff --git a/pkg/log/logshipper/logshipper.go b/pkg/log/logshipper/logshipper.go index 83cc00233..1b314fd1b 100644 --- a/pkg/log/logshipper/logshipper.go +++ b/pkg/log/logshipper/logshipper.go @@ -12,6 +12,7 @@ import ( "github.com/go-kit/kit/log/level" "github.com/kolide/kit/ulid" "github.com/kolide/kit/version" + "github.com/kolide/launcher/pkg/agent/flags/keys" "github.com/kolide/launcher/pkg/agent/storage" "github.com/kolide/launcher/pkg/agent/types" "github.com/kolide/launcher/pkg/sendbuffer" @@ -61,10 +62,18 @@ func New(k types.Knapsack, baseLogger log.Logger) *LogShipper { ls.slogLevel = new(slog.LevelVar) ls.slogLevel.Set(slog.LevelInfo) + ls.knapsack.RegisterChangeObserver(ls, keys.LogShippingLevel, keys.LogIngestServerURL) + ls.Ping() return ls } +func (ls *LogShipper) FlagsChanged(flagKeys ...keys.FlagKey) { + // TODO: only make updates that are relevant to flag key changes + // calling ping does more work than needed + ls.Ping() +} + // Ping gets the latest token and endpoint from knapsack and updates the sender func (ls *LogShipper) Ping() { // set up new auth token diff --git a/pkg/log/logshipper/logshipper_test.go b/pkg/log/logshipper/logshipper_test.go index d8022bee2..800f71b93 100644 --- a/pkg/log/logshipper/logshipper_test.go +++ b/pkg/log/logshipper/logshipper_test.go @@ -8,11 +8,13 @@ import ( "github.com/go-kit/kit/log" "github.com/kolide/kit/ulid" + "github.com/kolide/launcher/pkg/agent/flags/keys" "github.com/kolide/launcher/pkg/agent/storage" storageci "github.com/kolide/launcher/pkg/agent/storage/ci" "github.com/kolide/launcher/pkg/agent/types" "github.com/kolide/launcher/pkg/agent/types/mocks" "github.com/kolide/launcher/pkg/log/multislogger" + "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -42,9 +44,9 @@ func TestLogShipper(t *testing.T) { endpoint := "https://someurl" knapsack.On("LogIngestServerURL").Return(endpoint).Times(1) knapsack.On("ServerProvidedDataStore").Return(tokenStore) - knapsack.On("Debug").Return(true) knapsack.On("LogShippingLevel").Return("debug").Times(2) knapsack.On("Slogger").Return(multislogger.New().Logger) + knapsack.On("RegisterChangeObserver", mock.Anything, keys.LogShippingLevel, keys.LogIngestServerURL) ls := New(knapsack, log.NewNopLogger()) @@ -106,9 +108,9 @@ func TestStop_Multiple(t *testing.T) { endpoint := "https://someurl" knapsack.On("LogIngestServerURL").Return(endpoint).Times(1) knapsack.On("ServerProvidedDataStore").Return(tokenStore) - knapsack.On("Debug").Return(true) knapsack.On("LogShippingLevel").Return("debug") knapsack.On("Slogger").Return(multislogger.New().Logger) + knapsack.On("RegisterChangeObserver", mock.Anything, keys.LogShippingLevel, keys.LogIngestServerURL) ls := New(knapsack, log.NewNopLogger()) @@ -158,9 +160,9 @@ func TestStopWithoutRun(t *testing.T) { endpoint := "https://someurl" knapsack.On("LogIngestServerURL").Return(endpoint).Times(1) knapsack.On("ServerProvidedDataStore").Return(tokenStore) - knapsack.On("Debug").Return(true) knapsack.On("LogShippingLevel").Return("debug") knapsack.On("Slogger").Return(multislogger.New().Logger) + knapsack.On("RegisterChangeObserver", mock.Anything, keys.LogShippingLevel, keys.LogIngestServerURL) ls := New(knapsack, log.NewNopLogger()) From 371d16964f1ee0ba31bfb0f34fe87502d64dc8ad Mon Sep 17 00:00:00 2001 From: james pickett Date: Mon, 20 Nov 2023 10:19:16 -0800 Subject: [PATCH 3/5] comments --- pkg/agent/flags/flag_controller.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/agent/flags/flag_controller.go b/pkg/agent/flags/flag_controller.go index 9832472a7..d0a0d5423 100644 --- a/pkg/agent/flags/flag_controller.go +++ b/pkg/agent/flags/flag_controller.go @@ -132,7 +132,7 @@ func (fc *FlagController) overrideFlag(key keys.FlagKey, duration time.Duration, override, ok := fc.overrides[key] if !ok || override.Value() == nil { - // Creating the override implicitly causes future ControlRequestInterval retrievals to use the override until expiration + // Creating the override implicitly causes future flag value retrievals to use the override until expiration override = &Override{} fc.overrides[key] = override } @@ -149,7 +149,7 @@ func (fc *FlagController) overrideFlag(key keys.FlagKey, duration time.Duration, delete(fc.overrides, key) } - // start the override + // Start a new override, or re-start an existing one with a new value, duration, and expiration fc.overrides[key].Start(key, value, duration, overrideExpired) } From d4238b5e7dd875156195819f6d88a32025cb7fd6 Mon Sep 17 00:00:00 2001 From: james pickett Date: Mon, 20 Nov 2023 10:24:35 -0800 Subject: [PATCH 4/5] update mocks --- pkg/agent/types/mocks/flags.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/agent/types/mocks/flags.go b/pkg/agent/types/mocks/flags.go index 7c7b93bc4..478932f5b 100644 --- a/pkg/agent/types/mocks/flags.go +++ b/pkg/agent/types/mocks/flags.go @@ -734,9 +734,9 @@ func (_m *Flags) SetControlRequestInterval(interval time.Duration) error { return r0 } -// SetControlRequestIntervalOverride provides a mock function with given fields: interval, duration -func (_m *Flags) SetControlRequestIntervalOverride(interval time.Duration, duration time.Duration) { - _m.Called(interval, duration) +// SetControlRequestIntervalOverride provides a mock function with given fields: value, duration +func (_m *Flags) SetControlRequestIntervalOverride(value time.Duration, duration time.Duration) { + _m.Called(value, duration) } // SetControlServerURL provides a mock function with given fields: url @@ -977,6 +977,11 @@ func (_m *Flags) SetLogShippingLevel(level string) error { return r0 } +// SetLogShippingLevelOverride provides a mock function with given fields: value, duration +func (_m *Flags) SetLogShippingLevelOverride(value string, duration time.Duration) { + _m.Called(value, duration) +} + // SetLoggingInterval provides a mock function with given fields: interval func (_m *Flags) SetLoggingInterval(interval time.Duration) error { ret := _m.Called(interval) From 67c6e2d8fd476b3d34f43f31f06d11eb63df493d Mon Sep 17 00:00:00 2001 From: james pickett Date: Tue, 21 Nov 2023 07:48:11 -0800 Subject: [PATCH 5/5] correct comment, only override shipping level if actually using log shipper --- cmd/launcher/launcher.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/launcher/launcher.go b/cmd/launcher/launcher.go index e89c90f2f..48534c496 100644 --- a/cmd/launcher/launcher.go +++ b/cmd/launcher/launcher.go @@ -179,14 +179,14 @@ func runLauncher(ctx context.Context, cancel func(), slogger, systemSlogger *mul })) } - // Run launcher in debug mode for first 10 minutes. Intentionally doing this after setting up - // stderr debug logger becaues we don't want to write evertyhing to stderr. - k.SetLogShippingLevelOverride("debug", 10*time.Minute) - // Need to set up the log shipper so that we can get the logger early // and pass it to the various systems. var logShipper *logshipper.LogShipper if k.ControlServerURL() != "" { + // Set log shipping level to debug for the first X minutes of + // run time. This will also increase the sending frequency. + k.SetLogShippingLevelOverride("debug", 10*time.Minute) + logShipper = logshipper.New(k, logger) logger = teelogger.New(logger, logShipper) logger = log.With(logger, "caller", log.Caller(5))