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

Add logic for beats User-Agent #39403

Merged

Conversation

fearful-symmetry
Copy link
Contributor

@fearful-symmetry fearful-symmetry commented May 3, 2024

Proposed commit message

This adds a bit of logic to change the beats ES connection user agent if the beat is running under agent, dependent upon both the fleet status and the underlying management mode of agent itself.

In order for this to be fully functional, we'll need a PR from elastic-agent to add support for the AgentManagedMode enum. That PR is incoming.

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.

Related

Closes elastic/elastic-agent#3065

@fearful-symmetry fearful-symmetry added the Team:Elastic-Agent Label for the Agent team label May 3, 2024
@fearful-symmetry fearful-symmetry self-assigned this May 3, 2024
@fearful-symmetry fearful-symmetry requested a review from a team as a code owner May 3, 2024 19:33
@fearful-symmetry fearful-symmetry requested review from belimawr and faec May 3, 2024 19:33
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent (Team:Elastic-Agent)

@botelastic botelastic bot added needs_team Indicates that the issue/PR needs a Team:* label and removed needs_team Indicates that the issue/PR needs a Team:* label labels May 3, 2024
Copy link
Contributor

mergify bot commented May 3, 2024

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @fearful-symmetry? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

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

Copy link
Contributor

@belimawr belimawr left a comment

Choose a reason for hiding this comment

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

LGTM, I agree with Craig's suggestion. Once it's implemented I'll approve the PR.

@elasticmachine
Copy link
Collaborator

elasticmachine commented May 3, 2024

💚 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: 2024-05-03T22:00:05.623+0000

  • Duration: 112 min 42 sec

Test stats 🧪

Test Results
Failed 0
Passed 29427
Skipped 2061
Total 31488

💚 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 and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

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

@amitkanfer
Copy link
Collaborator

Did we also want to add --unprivileged to the User Agent string (if running in that mode)? @pierrehilbert

@strawgate
Copy link
Contributor

Not to pile on... But distinguishing managed from standalone might be nice too...

@pierrehilbert pierrehilbert added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label May 5, 2024
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@pierrehilbert
Copy link
Collaborator

@amitkanfer As we are already having this information in the local metadata, do you have a specific case you want to cover by adding it to User-Agent? For Telemetry only?

@strawgate We discussed this quickly during our meeting on Thursday and I think this is a great idea to user the User-Agent for that! @fearful-symmetry WDYT?

@fearful-symmetry
Copy link
Contributor Author

@pierrehilbert I think that's a good idea. I'm not sure if there's any way for beats to know what mode agent is running under? Never heard of anything like that. If we're interested in telemetry, I wonder if we can add that string to some headers sent by agent itself somehow?

@jlind23
Copy link
Collaborator

jlind23 commented May 6, 2024

@fearful-symmetry @pierrehilbert can we piggy back on this to also tackle elastic/elastic-agent#3065?

@fearful-symmetry
Copy link
Contributor Author

@jlind23 that issue seems largely the same as https://github.com/elastic/ingest-dev/issues/3202, with the addition of also reporting the agent version. I'm not sure it's possible for the agent version to differ from the beats version?

@cmacknz
Copy link
Member

cmacknz commented May 6, 2024

I'm not sure it's possible for the agent version to differ from the beats version?

For now and with independent releases they'll always be the same major.minor, the patch may differ.

Copy link
Contributor

mergify bot commented Jun 7, 2024

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b beats-user-agent-managed upstream/beats-user-agent-managed
git merge upstream/main
git push upstream beats-user-agent-managed

@fearful-symmetry
Copy link
Contributor Author

Alright, PR updated with all the feature requests; elastic-agent PR incoming...

Copy link
Contributor

@belimawr belimawr left a comment

Choose a reason for hiding this comment

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

I still believe the test can be simpler and not rely on the current implementation details from mock-es. See #39403 (comment) for more details.

@fearful-symmetry
Copy link
Contributor Author

I think the CI errors are unrelated?

@fearful-symmetry fearful-symmetry requested a review from cmacknz June 20, 2024 17:15
@pierrehilbert
Copy link
Collaborator

Looks like we are all green.
@belimawr could you please do another review?

@fearful-symmetry fearful-symmetry merged commit 72b6de3 into elastic:main Jun 25, 2024
121 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Elastic-Agent Label for the Agent team Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Include agent version in user-agent header for Beats
8 participants