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

Invalidate host context provider cache when FQDN feature flag is toggled #2461

Merged
merged 11 commits into from
Apr 6, 2023

Conversation

ycombinator
Copy link
Contributor

What does this PR do?

This PR invalidates the host context provider's cache whenever the FQDN feature flag is toggled.

Why is it important?

With this change, the host context provider will regenerate host information - which includes the hostname / FQDN - whenever the FQDN feature flag is toggled.

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/fragments using the changelog tool
  • I have added an integration test or an E2E test

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

Questions to ask yourself

  • How are we going to support this in production?
  • How are we going to measure its adoption?
  • How are we going to debug this?
  • What are the metrics I should take care of?
  • ...

@ycombinator ycombinator added enhancement New feature or request Team:Elastic-Agent Label for the Agent team backport-v8.7.0 Automated backport with mergify labels Apr 5, 2023
@ycombinator ycombinator requested a review from a team as a code owner April 5, 2023 19:32
@ycombinator ycombinator requested review from michel-laterman and pchila and removed request for a team April 5, 2023 19:32
@elasticmachine
Copy link
Collaborator

elasticmachine commented Apr 5, 2023

💚 Build Succeeded

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

Expand to view the summary

Build stats

  • Start Time: 2023-04-06T16:34:35.804+0000

  • Duration: 16 min 29 sec

Test stats 🧪

Test Results
Failed 0
Passed 5423
Skipped 23
Total 5446

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

Expand to view the 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
Collaborator

elasticmachine commented Apr 5, 2023

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 98.507% (66/67) 👍
Files 69.432% (159/229) 👍
Classes 68.65% (300/437) 👍
Methods 54.0% (918/1700) 👍 0.081
Lines 39.199% (10272/26205) 👍 0.084
Conditionals 100.0% (0/0) 💚

@cmacknz cmacknz requested a review from blakerouse April 5, 2023 20:08
Copy link
Contributor

@blakerouse blakerouse left a comment

Choose a reason for hiding this comment

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

Looks good, just one comment that would make the cleanup in the host provider a little better.

// Update context when any host information changes.
for {
t := time.NewTimer(c.CheckInterval)
select {
case <-comm.Done():
t.Stop()
features.RemoveFQDNOnChangeCallback(fqdnFeatureFlagCallbackID)
close(fqdnFFChangeCh)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move to a defer on line 61 it would be cleaner in the case that a future change results in it not being unregistered.

defer func() {
   features.RemoveFQDNOnChangeCallback(fqdnFeatureFlagCallbackID)
   close(fqdnFFChangeCh)
}()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, thanks. Done in c008e54.

@ycombinator ycombinator merged commit 0640efd into elastic:main Apr 6, 2023
@ycombinator ycombinator deleted the fqdn-host-provider-cache branch April 6, 2023 17:01
mergify bot pushed a commit that referenced this pull request Apr 6, 2023
…led (#2461)

* Add callback mechanism to notify when FQDN feature flag is toggled

* Use callback to bust host provider cache

* Moving const inside method

* Fixing typo

* Formatting for better readability

* Fixing comment

* Fixing comment

* Check error from features.Apply

* Simplify test

* Increasing sleep times

* Better cleanup of resources

(cherry picked from commit 0640efd)
ycombinator added a commit that referenced this pull request Apr 6, 2023
…led (#2461) (#2469)

* Add callback mechanism to notify when FQDN feature flag is toggled

* Use callback to bust host provider cache

* Moving const inside method

* Fixing typo

* Formatting for better readability

* Fixing comment

* Fixing comment

* Check error from features.Apply

* Simplify test

* Increasing sleep times

* Better cleanup of resources

(cherry picked from commit 0640efd)

Co-authored-by: Shaunak Kashyap <ycombinator@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v8.7.0 Automated backport with mergify enhancement New feature or request Team:Elastic-Agent Label for the Agent team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants