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

Remove x-pack code from OSS filebeat. #40483

Merged
merged 17 commits into from
Sep 3, 2024

Conversation

vinit-chauhan
Copy link
Contributor

@vinit-chauhan vinit-chauhan commented Aug 9, 2024

Proposed commit message

To fix the failing linter rule that requires OSS code to not depend on x-pack
code, this change removes the dependency on x-pack/dockerlogbeat/pipelinemock
from the Filebeat filestream input. It does this by creating a mock client
that is local to filestream test code ("A little copying is better than a
little dependency").

Fixes #40293

Remove x-pack code from OSS filebeat.

This PR creates a MockPipelineConnector and MockClient interface in the libbeat to drop the x-pack dependency in OSS code.

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.

Disruptive User Impact

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Aug 9, 2024
Copy link
Contributor

mergify bot commented Aug 9, 2024

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @vinit-chauhan? 🙏.
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

@vinit-chauhan vinit-chauhan marked this pull request as ready for review August 10, 2024 18:43
@vinit-chauhan vinit-chauhan requested a review from a team as a code owner August 10, 2024 18:43
@pierrehilbert pierrehilbert added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Aug 11, 2024
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Aug 11, 2024
@elasticmachine
Copy link
Collaborator

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

@andrzej-stencel
Copy link
Contributor

Hey @vinit-chauhan, thanks for your contribution.

I'm comparing the code you added in libbeat/mock/pipeline_client.go to the original code in x-pack/dockerlogbeat/pipelinemock/pipelines.go, and I'm finding quite a lot of differences. My assumption was the code would be moved as-is, without any changes. Can you explain what was the rationale for the changes?

I'm worried that the changes to the package's API might make migration harder for any other code that currently relies on the x-pack library.

The changes I noticed:

  • package name changed from pipelinemock to mock
  • MockBeatClient type changed to MockClient
  • MockPipelineConnector type replaced with MockPipeline type
  • removed MockPipelineConnector methods GetAllEvents and HasConnectedClients.

@leehinman Do you have any thoughts on this?

vinit-chauhan and others added 10 commits August 13, 2024 12:54
This adds support for hyphens (`-`) in extension keys. The CEF spec says that extension keys alphanumeric. So this is a deviation, but a minor one that is inline with past deviations to allow dots in extension keys. 

I have also added .ri file to gitignore file as they are intermediate files generated by regel.

Closes elastic#40348
In order to handle timezones we import Go's own timezone database. This
import is done indirectly by libbeat/common/cfgtype. We trust that this
package will end up being required by the dependency chain of every beats
main binary.

To ensure that the binaries continue to handle timezones correctly and to
avoid any unexpected issues, let's import time/tzdata explicitly in the
main packages.

See elastic#40326.

Co-authored-by: Pierre HILBERT <[email protected]>
* chore: add effective capabiltiies in agentbeat

* chore: comments

* fix: changelog

* fix: add license

* fix: lint

* fix: goimports

* fix: remove HasRoot for other OSes

---------

Co-authored-by: Pierre HILBERT <[email protected]>
…er/costmanagement/armcostmanagement from 1.1.0 to 1.1.1 (elastic#40422)

* build(deps): bump github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/costmanagement/armcostmanagement

Bumps [github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/costmanagement/armcostmanagement](https://github.com/Azure/azure-sdk-for-go) from 1.1.0 to 1.1.1.
- [Release notes](https://github.com/Azure/azure-sdk-for-go/releases)
- [Changelog](https://github.com/Azure/azure-sdk-for-go/blob/main/documentation/release.md)
- [Commits](Azure/azure-sdk-for-go@v1.1...sdk/azcore/v1.1.1)

---
updated-dependencies:
- dependency-name: github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/costmanagement/armcostmanagement
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* Update NOTICE.txt

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com>
Co-authored-by: Maurizio Branca <[email protected]>
elastic#40471)

* build(deps): bump the gcp-sdks group across 1 directory with 8 updates

Bumps the gcp-sdks group with 3 updates in the / directory: [cloud.google.com/go/monitoring](https://github.com/googleapis/google-cloud-go), [cloud.google.com/go/pubsub](https://github.com/googleapis/google-cloud-go) and [cloud.google.com/go/auth/oauth2adapt](https://github.com/googleapis/google-cloud-go).


Updates `cloud.google.com/go/monitoring` from 1.20.2 to 1.20.4
- [Release notes](https://github.com/googleapis/google-cloud-go/releases)
- [Changelog](https://github.com/googleapis/google-cloud-go/blob/main/CHANGES.md)
- [Commits](googleapis/google-cloud-go@video/v1.20.2...video/v1.20.4)

Updates `cloud.google.com/go/pubsub` from 1.40.0 to 1.41.0
- [Release notes](https://github.com/googleapis/google-cloud-go/releases)
- [Changelog](https://github.com/googleapis/google-cloud-go/blob/main/CHANGES.md)
- [Commits](googleapis/google-cloud-go@pubsub/v1.40.0...pubsub/v1.41.0)

Updates `cloud.google.com/go/compute` from 1.27.3 to 1.27.4
- [Release notes](https://github.com/googleapis/google-cloud-go/releases)
- [Changelog](https://github.com/googleapis/google-cloud-go/blob/main/CHANGES.md)
- [Commits](googleapis/google-cloud-go@compute/v1.27.3...compute/v1.27.4)

Updates `cloud.google.com/go/redis` from 1.16.3 to 1.16.4
- [Release notes](https://github.com/googleapis/google-cloud-go/releases)
- [Changelog](https://github.com/googleapis/google-cloud-go/blob/main/CHANGES.md)
- [Commits](googleapis/google-cloud-go@redis/v1.16.3...redis/v1.16.4)

Updates `cloud.google.com/go/auth` from 0.7.2 to 0.8.0
- [Release notes](https://github.com/googleapis/google-cloud-go/releases)
- [Changelog](https://github.com/googleapis/google-cloud-go/blob/main/CHANGES.md)
- [Commits](googleapis/google-cloud-go@auth/v0.7.2...v0.8.0)

Updates `cloud.google.com/go/auth/oauth2adapt` from 0.2.3 to 0.2.4
- [Release notes](https://github.com/googleapis/google-cloud-go/releases)
- [Changelog](https://github.com/googleapis/google-cloud-go/blob/main/CHANGES.md)
- [Commits](googleapis/google-cloud-go@netapp/v0.2.3...netapp/v0.2.4)

Updates `cloud.google.com/go/iam` from 1.1.11 to 1.1.12
- [Release notes](https://github.com/googleapis/google-cloud-go/releases)
- [Changelog](https://github.com/googleapis/google-cloud-go/blob/main/CHANGES.md)
- [Commits](googleapis/google-cloud-go@iam/v1.1.11...iam/v1.1.12)

Updates `cloud.google.com/go/longrunning` from 0.5.10 to 0.5.11
- [Release notes](https://github.com/googleapis/google-cloud-go/releases)
- [Changelog](https://github.com/googleapis/google-cloud-go/blob/main/CHANGES.md)
- [Commits](googleapis/google-cloud-go@longrunning/v0.5.10...longrunning/v0.5.11)

---
updated-dependencies:
- dependency-name: cloud.google.com/go/monitoring
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: gcp-sdks
- dependency-name: cloud.google.com/go/pubsub
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: gcp-sdks
- dependency-name: cloud.google.com/go/compute
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: gcp-sdks
- dependency-name: cloud.google.com/go/redis
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: gcp-sdks
- dependency-name: cloud.google.com/go/auth
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: gcp-sdks
- dependency-name: cloud.google.com/go/auth/oauth2adapt
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: gcp-sdks
- dependency-name: cloud.google.com/go/iam
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: gcp-sdks
- dependency-name: cloud.google.com/go/longrunning
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: gcp-sdks
...

Signed-off-by: dependabot[bot] <[email protected]>

* Update NOTICE.txt

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com>
* update elastic-agent-system-metrics

* add changelog
…tion ordering (elastic#40487)

Previously, the configuration was eager, this caused a panic when the request
trace logging option was turned on since it was started without a context.

Move the construction of components to when we have all the parts we need.
* [CI] Agentbeat integration testing

* Split packaging and integration test

* Fix artifacts path

* Added NodeJS version

* docker compose replace --no-ansi with --ansi never

* Mistype

* Removed metricbeat from agentbeat's GoIntegTest
@vinit-chauhan vinit-chauhan requested review from a team as code owners August 13, 2024 16:54
@vinit-chauhan vinit-chauhan requested review from a team as code owners August 13, 2024 16:54
@vinit-chauhan
Copy link
Contributor Author

Hey @andrzej-stencel - I'm always happy to contribute to Elastic. :)

The reason for not moving the code as-is is, that this code is used only in the harvestor_test.go file for the OSS codebase. But if you want I can update the PR to move the x-pack code to OSS.

For the points you mentioned,

  • Renaming package to mock: The x-pack code mocks functionality by implementing the libbeat features, that's the reason why I think the OSS version should move to libbeat. Additionally, there's already a package containing mocks named mock, so I moved it there all to a single place.
  • MockBeatClient -> MockClient: I think the original author of the code added MockBeat because they mocked the libbeat's Client interface outside of the libbeat codebase, and now the code is in beats, I think adding Beats is redundant.
  • MockPipelineConnector -> MockPipeline: I have implemented the Pipeline interface whereas the original code implements PipelineConnector interface which is a wrapper to the Pipeline interface.
  • GetAllEvents and HasConnectedClients: Those 2 are additional methods added on top of PipelineConnector and used by the tests they have written.

interfaces used:

That is the explanation for the changes I have made. Let me know your thoughts.

@AndersonQ
Copy link
Member

AndersonQ commented Aug 21, 2024

@vinit-chauhan given the limited usage of this new mock and that mock.New is a mockbeat and nothing else. Perhaps the best would be to move your mock code to filebeat/input/filestream/internal/input-logfile/harvester_test.go. There are already other mocks there, so it makes sense to have this one there as well.

@andrzej-stencel does it sound good to u?

@vinit-chauhan
Copy link
Contributor Author

Hey @AndersonQ - wouldn't that cause the same issue?
If someone decides to use mockbeat in let's say metricbeat, then they'll have to re-write it or reference the filebeat code in metricbeat.

So, I think it's better to keep the libbeat mocks in libbeat, so that we don't cross reference others.

But, let me know what you think, I'll update accordingly. :)

@AndersonQ
Copy link
Member

Oh, I meant moving just the mock you created and keeping the mockbeat where it is

@vinit-chauhan
Copy link
Contributor Author

vinit-chauhan commented Aug 21, 2024

Oh I see, it makes sense then!

Let's wait for a bit if someone else has any comments, otherwise I'll update the code as per our discusstion.

@leehinman
Copy link
Contributor

sorry for missing this. I like @AndersonQ suggestion.

@andrzej-stencel
Copy link
Contributor

Sorry for the delay, sounds good to me 👍

@pierrehilbert
Copy link
Collaborator

/test

@pierrehilbert
Copy link
Collaborator

run docs-build

@vinit-chauhan
Copy link
Contributor Author

Hey team - Apologies for the delay. I have moved the mock to the harvestor_test file as per our discussion.

Let me know if you require anything else.

@andrewkroh
Copy link
Member

/test

@andrewkroh andrewkroh enabled auto-merge (squash) August 30, 2024 13:57
@ycombinator
Copy link
Contributor

run docs-build

@andrewkroh andrewkroh merged commit 49582f4 into elastic:main Sep 3, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Filebeat Filebeat refactoring 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.

OSS filebeat harvester_test.go should not depend on Elastic-licensed code