-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce memory footprint by reordering struct elements #804
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,11 +26,11 @@ type stateStore interface { | |
// Unenroll results in running agent entering idle state, non managed non standalone. | ||
// For it to be operational again it needs to be either enrolled or reconfigured. | ||
type Unenroll struct { | ||
dispatcher pipeline.Router | ||
stateStore stateStore | ||
log *logger.Logger | ||
emitter pipeline.EmitterFunc | ||
dispatcher pipeline.Router | ||
closers []context.CancelFunc | ||
stateStore stateStore | ||
} | ||
|
||
// NewUnenroll creates a new Unenroll handler. | ||
|
@@ -75,6 +75,7 @@ func (h *Unenroll) Handle(ctx context.Context, a fleetapi.Action, acker store.Fl | |
} else if h.stateStore != nil { | ||
// backup action for future start to avoid starting fleet gateway loop | ||
h.stateStore.Add(a) | ||
// nolint: errcheck // Ignore the error at this point. | ||
h.stateStore.Save() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. linter complained: Error return value of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It introduces quite a change on the method's behaviour. @ph do you think it might cause any undesired side effect? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you prefer a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets do the nolint here, I am not sure of the impact of this changes here, wdyt @michel-laterman ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that currently I think if the action fails to persist, then the agent will try to start with the persisted policy if it's restarted. But at that point it's api key has likely been revoked. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated the PR to use the |
||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,15 +44,15 @@ var ( | |
|
||
// Upgrader performs an upgrade | ||
type Upgrader struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. struct with 120 pointer bytes could be 96 |
||
agentInfo *info.AgentInfo | ||
reporter stateReporter | ||
caps capabilities.Capability | ||
reexec reexecManager | ||
acker acker | ||
settings *artifact.Config | ||
agentInfo *info.AgentInfo | ||
log *logger.Logger | ||
closers []context.CancelFunc | ||
reexec reexecManager | ||
acker acker | ||
reporter stateReporter | ||
upgradeable bool | ||
caps capabilities.Capability | ||
} | ||
|
||
// Action is the upgrade action state. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,8 @@ import ( | |
// if nth operation fails all preceding are retried as well | ||
type retryableOperations struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. struct with 40 pointer bytes could be 24 |
||
logger *logger.Logger | ||
operations []operation | ||
retryConfig *retry.Config | ||
operations []operation | ||
} | ||
|
||
func newRetryableOperations( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,10 +60,10 @@ func (s *state) String() string { | |
} | ||
|
||
type active struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. struct with 272 pointer bytes could be 256 |
||
LastChange stateChange | ||
Program program.Program | ||
LastModified time.Time | ||
Identifier string | ||
Program program.Program | ||
LastChange stateChange | ||
} | ||
|
||
func (s *active) String() string { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,15 +23,15 @@ import ( | |
) | ||
|
||
type pod struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. struct with 120 pointer bytes could be 104 |
||
logger *logp.Logger | ||
cleanupTimeout time.Duration | ||
comm composable.DynamicProviderComm | ||
scope string | ||
config *Config | ||
metagen metadata.MetaGen | ||
watcher kubernetes.Watcher | ||
nodeWatcher kubernetes.Watcher | ||
comm composable.DynamicProviderComm | ||
metagen metadata.MetaGen | ||
namespaceWatcher kubernetes.Watcher | ||
config *Config | ||
logger *logp.Logger | ||
scope string | ||
cleanupTimeout time.Duration | ||
|
||
// Mutex used by configuration updates not triggered by the main watcher, | ||
// to avoid race conditions between cross updates and deletions. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,12 @@ import "github.com/elastic/elastic-agent-autodiscover/kubernetes" | |
|
||
// Config for kubernetes_leaderelection provider | ||
type Config struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. struct with 40 pointer bytes could be 24 |
||
KubeConfig string `config:"kube_config"` | ||
KubeClientOptions kubernetes.KubeClientOptions `config:"kube_client_options"` | ||
KubeConfig string `config:"kube_config"` | ||
|
||
// Name of the leaderelection lease | ||
LeaderLease string `config:"leader_lease"` | ||
|
||
KubeClientOptions kubernetes.KubeClientOptions `config:"kube_client_options"` | ||
} | ||
|
||
// InitDefaults initializes the default values for the config. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,34 +35,32 @@ var ( | |
|
||
// Application encapsulates a concrete application ran by elastic-agent e.g Beat. | ||
type Application struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. struct with 296 pointer bytes could be 264 |
||
bgContext context.Context | ||
id string | ||
name string | ||
pipelineID string | ||
logLevel string | ||
desc *app.Descriptor | ||
srv *server.Server | ||
srvState *server.ApplicationState | ||
limiter *tokenbucket.Bucket | ||
startContext context.Context | ||
tag app.Taggable | ||
state state.State | ||
reporter state.Reporter | ||
watchClosers map[int]context.CancelFunc | ||
state state.State | ||
startContext context.Context | ||
statusReporter status.Reporter | ||
monitor monitoring.Monitor | ||
reporter state.Reporter | ||
tag app.Taggable | ||
bgContext context.Context | ||
srvState *server.ApplicationState | ||
limiter *tokenbucket.Bucket | ||
srv *server.Server | ||
desc *app.Descriptor | ||
restartCanceller context.CancelFunc | ||
logger *logger.Logger | ||
watchClosers map[int]context.CancelFunc | ||
processConfig *process.Config | ||
restartConfig map[string]interface{} | ||
|
||
name string | ||
id string | ||
pipelineID string | ||
logLevel string | ||
|
||
uid int | ||
gid int | ||
|
||
monitor monitoring.Monitor | ||
statusReporter status.Reporter | ||
|
||
processConfig *process.Config | ||
|
||
logger *logger.Logger | ||
|
||
appLock sync.Mutex | ||
restartCanceller context.CancelFunc | ||
restartConfig map[string]interface{} | ||
appLock sync.Mutex | ||
} | ||
|
||
// ArgsDecorator decorates arguments before calling an application | ||
|
@@ -79,8 +77,8 @@ func NewApplication( | |
logger *logger.Logger, | ||
reporter state.Reporter, | ||
monitor monitoring.Monitor, | ||
statusController status.Controller) (*Application, error) { | ||
|
||
statusController status.Controller, | ||
) (*Application, error) { | ||
s := desc.ProcessSpec() | ||
uid, gid, err := s.UserGroup() | ||
if err != nil { | ||
|
@@ -157,7 +155,6 @@ func (a *Application) Stop() { | |
|
||
a.logger.Error(err) | ||
} | ||
|
||
} | ||
|
||
a.appLock.Lock() | ||
|
@@ -231,6 +228,7 @@ func (a *Application) watch(ctx context.Context, p app.Taggable, proc *process.I | |
a.setState(state.Restarting, msg, nil) | ||
|
||
// it was a crash | ||
// nolint: errcheck // Ignore the error at this point. | ||
a.start(ctx, p, cfg, true) | ||
florianl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}() | ||
} | ||
|
@@ -277,6 +275,7 @@ func (a *Application) setState(s state.Status, msg string, payload map[string]in | |
} | ||
|
||
func (a *Application) cleanUp() { | ||
// nolint: errcheck // Ignore the error at this point. | ||
a.monitor.Cleanup(a.desc.Spec(), a.pipelineID) | ||
florianl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,9 +76,9 @@ func FromProto(s proto.StateObserved_Status) Status { | |
// State wraps the process state and application status. | ||
type State struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. struct with 40 pointer bytes could be 24 |
||
ProcessInfo *process.Info | ||
Status Status | ||
Message string | ||
Payload map[string]interface{} | ||
Message string | ||
Status Status | ||
} | ||
|
||
// Reporter is interface that is called when a state is changed. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,19 +39,19 @@ func (s AgentStatusCode) String() string { | |
|
||
// AgentApplicationStatus returns the status of specific application. | ||
type AgentApplicationStatus struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. struct with 64 pointer bytes could be 48 |
||
Payload map[string]interface{} | ||
ID string | ||
Name string | ||
Status state.Status | ||
Message string | ||
Payload map[string]interface{} | ||
Status state.Status | ||
} | ||
|
||
// AgentStatus returns the overall status of the Elastic Agent. | ||
type AgentStatus struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. struct with 72 pointer bytes could be 48 |
||
Status AgentStatusCode | ||
UpdateTime time.Time | ||
Message string | ||
Applications []AgentApplicationStatus | ||
UpdateTime time.Time | ||
Status AgentStatusCode | ||
} | ||
|
||
// Controller takes track of component statuses. | ||
|
@@ -68,15 +68,15 @@ type Controller interface { | |
} | ||
|
||
type controller struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. struct with 104 pointer bytes could be 88 |
||
mx sync.Mutex | ||
status AgentStatusCode | ||
message string | ||
updateTime time.Time | ||
log *logger.Logger | ||
reporters map[string]*reporter | ||
appReporters map[string]*reporter | ||
log *logger.Logger | ||
stateID string | ||
message string | ||
agentID string | ||
status AgentStatusCode | ||
mx sync.Mutex | ||
} | ||
|
||
// NewController creates a new reporter. | ||
|
@@ -272,15 +272,15 @@ type Reporter interface { | |
} | ||
|
||
type reporter struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. struct with 80 pointer bytes could be 48 |
||
name string | ||
mx sync.Mutex | ||
isPersistent bool | ||
isRegistered bool | ||
status state.Status | ||
message string | ||
payload map[string]interface{} | ||
unregisterFunc func() | ||
notifyChangeFunc func() | ||
message string | ||
name string | ||
status state.Status | ||
mx sync.Mutex | ||
isRegistered bool | ||
isPersistent bool | ||
} | ||
|
||
// Update updates the status of a component. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,11 @@ import ( | |
// Option is the default options used to generate the encrypt and decrypt writer. | ||
// NOTE: the defined options need to be same for both the Reader and the writer. | ||
type Option struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. struct with 40 pointer bytes could be 8 |
||
Generator bytesGen | ||
IterationsCount int | ||
KeyLength int | ||
SaltLength int | ||
IVLength int | ||
Generator bytesGen | ||
|
||
// BlockSize must be a factor of aes.BlockSize | ||
BlockSize int | ||
|
@@ -180,7 +180,6 @@ func (w *Writer) Write(b []byte) (int, error) { | |
} | ||
|
||
func (w *Writer) writeBlock(b []byte) error { | ||
|
||
// randomly generate the salt and the initialization vector, this information will be saved | ||
// on disk in the file as part of the header | ||
iv, err := w.generator(w.option.IVLength) | ||
|
@@ -189,12 +188,14 @@ func (w *Writer) writeBlock(b []byte) error { | |
return w.err | ||
} | ||
|
||
// nolint: errcheck // Ignore the error at this point. | ||
w.writer.Write(iv) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. linter complained: Error return value of |
||
|
||
encodedBytes := w.gcm.Seal(nil, iv, b, nil) | ||
|
||
l := make([]byte, 4) | ||
binary.LittleEndian.PutUint32(l, uint32(len(encodedBytes))) | ||
// nolint: errcheck // Ignore the error at this point. | ||
w.writer.Write(l) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. linter complained: Error return value of a.monitor.Cleanup is not checked (errcheck) |
||
|
||
_, err = w.writer.Write(encodedBytes) | ||
|
@@ -325,7 +326,7 @@ func (r *Reader) consumeBlock() error { | |
} | ||
|
||
encodedBytes := make([]byte, l) | ||
_, err = io.ReadAtLeast(r.reader, encodedBytes, int(l)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. linter complained: unnecessary conversion (unconvert) |
||
_, err = io.ReadAtLeast(r.reader, encodedBytes, l) | ||
if err != nil { | ||
r.err = errors.Wrapf(err, "fail read the block of %d bytes", l) | ||
} | ||
|
@@ -364,7 +365,6 @@ func (r *Reader) Close() error { | |
func randomBytes(length int) ([]byte, error) { | ||
r := make([]byte, length) | ||
_, err := rand.Read(r) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,19 +32,19 @@ type Option func(*Retrier) | |
|
||
// Retrier implements retrier for actions acks | ||
type Retrier struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. struct with 96 pointer bytes could be 48 |
||
log *logger.Logger | ||
acker BatchAcker // AckBatch provider | ||
log *logger.Logger | ||
|
||
initialRetryInterval time.Duration // initial retry interval | ||
maxRetryInterval time.Duration // max retry interval | ||
maxRetries int // configurable maxNumber of retries per action | ||
doneCh chan struct{} // signal channel to kickoff retry loop if not running | ||
kickCh chan struct{} // signal channel when retry loop is done | ||
|
||
actions []fleetapi.Action // pending actions | ||
mx sync.Mutex | ||
|
||
kickCh chan struct{} // signal channel to kickoff retry loop if not running | ||
maxRetryInterval time.Duration // max retry interval | ||
maxRetries int // configurable maxNumber of retries per action | ||
initialRetryInterval time.Duration // initial retry interval | ||
|
||
doneCh chan struct{} // signal channel when retry loop is done | ||
mx sync.Mutex | ||
} | ||
|
||
// New creates new instance of retrier | ||
|
@@ -173,7 +173,6 @@ func (r *Retrier) runRetries(ctx context.Context) { | |
default: | ||
} | ||
r.log.Debug("ack retrier: exit retry loop") | ||
|
||
} | ||
|
||
func (r *Retrier) updateRetriesMap(retries map[string]int, actions []fleetapi.Action, resp *fleetapi.AckResponse) (failed []fleetapi.Action) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
struct with 72 pointer bytes could be 56