-
Notifications
You must be signed in to change notification settings - Fork 145
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
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 |
@@ -151,7 +151,7 @@ func (h *PolicyChange) handleFleetServerHosts(ctx context.Context, c *config.Con | |||
errors.TypeNetwork, errors.M("hosts", h.config.Fleet.Client.Hosts)) | |||
} | |||
// discard body for proper cancellation and connection reuse | |||
io.Copy(ioutil.Discard, resp.Body) | |||
_, _ = io.Copy(ioutil.Discard, resp.Body) |
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.
👍
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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.
Choose a reason for hiding this comment
The 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.
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.asciidoc
orCHANGELOG-developer.next.asciidoc
.