[Elastic-Agent] Added source uri reloading#756
Conversation
|
This pull request does not have a backport label. Could you fix it @pierrehilbert? 🙏
NOTE: |
🌐 Coverage report
|
|
I tested this functionality e2e together with my changes in Kibana. The reloading itself seems to work as expected:
However I tried to force the upgrade of the agent and it doesn't read the source_uri from the policy as I would expect. It only gets the uri from the actions if it's passed through the endpoint, otherwise it uses some hardcoded values. I can raise a ticket where I detail the use case and in the meantime this PR can be merged. |
|
i will test it as well. i finally got my HW |
|
i see where the problem is, kibana sets this as |
|
actually looking at it it will make our code messy, @criamico please fix this on your end |
|
nevermind, i added support for changed coming from fleet as well not exposing |
| } | ||
| // discard body for proper cancellation and connection reuse | ||
| io.Copy(ioutil.Discard, resp.Body) | ||
| _, _ = io.Copy(ioutil.Discard, resp.Body) |
| 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 | ||
| } | ||
|
|
There was a problem hiding this comment.
[Blocker]
Sorry but I'm a bit puzzled here. How does it changes the source URI the agent uses? The changes made by the Reload method seem to be only local. It only affects r.cfg.SourceURI that isn't used anywhere else. Perhaps you forgot to change the SourceURI returned by DefaultConfig as elastic-agent/pull/686 did?
Also, it'd be good to add a test for that
There was a problem hiding this comment.
r has a pointer to a config on a heap. this one is propagated down the stack to each component.
downloader has the pointer to the same thing so when it tries to resolve URI it will pick it up.
same logic applied for monitoring reloader.
|
@michalpristas is back now and added my changes to his PR. |
What does this PR do?
Fix @michalpristas PR: #686
Why is it important?
#686
Checklist
CHANGELOG.next.asciidocorCHANGELOG-developer.next.asciidoc.