Skip to content
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

Closed
wants to merge 9 commits into from

Conversation

pierrehilbert
Copy link
Contributor

What does this PR do?

Fix @michalpristas PR: #686

Why is it important?

#686

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

@pierrehilbert pierrehilbert requested a review from a team as a code owner July 21, 2022 11:40
@pierrehilbert pierrehilbert requested review from AndersonQ and aleksmaus and removed request for a team July 21, 2022 11:40
@mergify
Copy link
Contributor

mergify bot commented Jul 21, 2022

This pull request does not have a backport label. Could you fix it @pierrehilbert? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v./d./d./d is the label to automatically backport to the 8./d branch. /d is the digit

NOTE: backport-skip has been added to this pull request.

@pierrehilbert pierrehilbert added enhancement New feature or request Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team v8.4.0 labels Jul 21, 2022
@elasticmachine
Copy link
Contributor

❕ Build Aborted

Either there was a build timeout or someone aborted the build.

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Start Time: 2022-07-21T11:40:30.165+0000

  • Duration: 122 min 57 sec

Test stats 🧪

Test Results
Failed 0
Passed 4915
Skipped 21
Total 4936

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages.

  • run integration tests : Run the Elastic Agent Integration tests.

  • run end-to-end tests : Generate the packages and run the E2E Tests.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@elasticmachine
Copy link
Contributor

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 97.297% (72/74) 👍 0.075
Files 69.027% (156/226) 👍 1.153
Classes 68.973% (309/448) 👍 0.946
Methods 53.129% (866/1630) 👍 1.214
Lines 39.142% (9322/23816) 👍 0.914
Conditionals 100.0% (0/0) 💚

@criamico
Copy link

criamico commented Jul 21, 2022

I tested this functionality e2e together with my changes in Kibana. The reloading itself seems to work as expected:

  • Created In Kibana a new source download source object with a mock URI https://test-registry.co
  • Created a new agent policy and assigned the download source object to it
  • I ran elastic-agent inspect and the source_URI is present there:
  • elastic-agent@b907b836ccf4:~$ elastic-agent inspect
    agent:
      download:
        source_uri: https://test-registry.co
    
  • I then changed back the agent policy to the default value and ran elastic-agent inspect again. The policy reloaded properly:
    elastic-agent@b907b836ccf4:~$ elastic-agent inspect
    agent:
      download:
        source_uri: https://artifacts.elastic.co/downloads/beats/elastic-agent
    

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.

@michalpristas
Copy link
Contributor

i will test it as well. i finally got my HW

@michalpristas
Copy link
Contributor

michalpristas commented Jul 25, 2022

i see where the problem is, kibana sets this as source_uri but we use sourceURI as mentioned in the original proposal/issue as well.
renaming from our end seems like breaking so i will handle both changes in reloader part but Kibana side should also stick to our naming
inspect returns whatever comes from fleet, it does not mean agent understands the value

@michalpristas
Copy link
Contributor

actually looking at it it will make our code messy, @criamico please fix this on your end

@michalpristas
Copy link
Contributor

nevermind, i added support for changed coming from fleet as well not exposing source_uri to standalone.
latest changes and fix from this one in my original PR #686

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +51 to +82
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
}

Copy link
Member

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

Copy link
Contributor

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.

@pierrehilbert
Copy link
Contributor Author

@michalpristas is back now and added my changes to his PR.
I close this one to avoid confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-skip enhancement New feature or request Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team v8.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants