-
Notifications
You must be signed in to change notification settings - Fork 146
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
[Elastic-Agent] Added source uri reloading #756
Changes from all commits
f1d98a0
319bd63
78cd614
19082fc
635f75b
3b89b2b
48aa387
0649adf
a74b7aa
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 |
---|---|---|
|
@@ -11,6 +11,8 @@ import ( | |
|
||
"github.com/elastic/elastic-agent-libs/transport/httpcommon" | ||
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths" | ||
"github.com/elastic/elastic-agent/internal/pkg/config" | ||
"github.com/elastic/elastic-agent/pkg/core/logger" | ||
) | ||
|
||
const ( | ||
|
@@ -46,6 +48,38 @@ type Config struct { | |
httpcommon.HTTPTransportSettings `config:",inline" yaml:",inline"` // Note: use anonymous struct for json inline | ||
} | ||
|
||
type Reloader struct { | ||
log *logger.Logger | ||
cfg *Config | ||
} | ||
|
||
func NewReloader(cfg *Config, log *logger.Logger) *Reloader { | ||
return &Reloader{ | ||
log: log, | ||
cfg: cfg, | ||
} | ||
} | ||
|
||
func (r *Reloader) Reload(rawConfig *config.Config) error { | ||
type c struct { | ||
Config *Config `config:"agent.download" yaml:"agent.download" json:"agent.download"` | ||
} | ||
|
||
cfg := &c{ | ||
Config: DefaultConfig(), | ||
} | ||
if err := rawConfig.Unpack(&cfg); err != nil { | ||
return err | ||
} | ||
|
||
r.log.Debugf("Source URI changed from %q to %q", r.cfg.SourceURI, cfg.Config.SourceURI) | ||
if cfg.Config.SourceURI != "" { | ||
r.cfg.SourceURI = cfg.Config.SourceURI | ||
} | ||
|
||
return nil | ||
} | ||
|
||
Comment on lines
+51
to
+82
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. [Blocker] Also, it'd be good to add a test for that 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. r has a pointer to a config on a heap. this one is propagated down the stack to each component. |
||
// DefaultConfig creates a config with pre-set default values. | ||
func DefaultConfig() *Config { | ||
transport := httpcommon.DefaultHTTPTransportSettings() | ||
|
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.
👍