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

[filebeat] Add a configuration option for TCP/UDP network type #40623

Merged
merged 7 commits into from
Aug 27, 2024

Conversation

aleksmaus
Copy link
Member

Proposed commit message

Add a configuration option for TCP/UDP network type.

Description below is copied from the ticket #40407:

The TCP input would accept these values for the network type:

  • tcp (default)
  • tcp4
  • tcp6

The UDP input would accept these values for the network type:

  • udp (default)
  • udp4
  • udp6

Examples

filebeat.inputs:
- type: tcp
  max_message_size: 10MiB
  host: "localhost:9000"
  network: tcp4
filebeat.inputs:
- type: udp
  max_message_size: 10KiB
  host: "localhost:8080"
  network: udp4

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 issues

Screenshots

Screenshot 2024-08-26 at 2 24 51 PM Screenshot 2024-08-26 at 2 25 21 PM Screenshot 2024-08-26 at 2 41 42 PM

@aleksmaus aleksmaus added enhancement Team:Security-Deployment and Devices Deployment and Devices Team in Security Solution labels Aug 26, 2024
@aleksmaus aleksmaus requested review from taylor-swanson and a team August 26, 2024 19:32
@aleksmaus aleksmaus self-assigned this Aug 26, 2024
@aleksmaus aleksmaus requested a review from a team as a code owner August 26, 2024 19:32
@elasticmachine
Copy link
Collaborator

Pinging @elastic/sec-deployment-and-devices (Team:Security-Deployment and Devices)

@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 Aug 26, 2024
Copy link
Contributor

mergify bot commented Aug 26, 2024

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

@aleksmaus aleksmaus added Filebeat Filebeat backport-skip Skip notification from the automated backport with mergify labels Aug 26, 2024
filebeat/inputsource/tcp/config.go Outdated Show resolved Hide resolved
filebeat/inputsource/udp/config.go Outdated Show resolved Hide resolved
Copy link
Contributor

@pkoutsovasilis pkoutsovasilis left a comment

Choose a reason for hiding this comment

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

LGMT! ty @aleksmaus

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

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

filebeat/inputsource/tcp/server.go Outdated Show resolved Hide resolved
filebeat/inputsource/udp/server.go Outdated Show resolved Hide resolved
@@ -85,3 +86,10 @@ func (s *Server) createServer() (net.Listener, error) {
}
return l, nil
}

func (s *Server) network() string {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is style/consistenty comment. I'm ok if you leave it as is, just want to bring it up to consider.

A common theme in the beats code base for default values is to make a defaultConfig function, that returns the struct with the default value filled in. And then when Unpack is run, if the supplied config didn't have the value, you get the default. And validate can work on the real values you want to check. An example would be:

func configure(cfg *conf.C) (stateless.Input, error) {
config := defaultConfig()
if err := cfg.Unpack(&config); err != nil {
return nil, err
}
return newServer(config)
}
func defaultConfig() config {
return config{
Config: tcp.Config{
Timeout: time.Minute * 5,
MaxMessageSize: 20 * humanize.MiByte,
},
LineDelimiter: "\n",
}
}

what do you think about using that pattern here?

Copy link
Member Author

@aleksmaus aleksmaus Aug 27, 2024

Choose a reason for hiding this comment

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

Yeah, I saw this pattern, was not sure if that is consistent across the board and if nobody is going to ask why we do set the configuration option when it's was not set.
One example:
https://github.com/elastic/beats/blob/main/filebeat/inputsource/udp/server_test.go#L62

The original ticket requirement was:

"When no option is provided, the default value (udp or tcp) is used"

So, took it literally in this case: not changing the config, and using the default network type "When no option is provided". I'd probably still leave this network() function at the point when the server is created in case if the config value gets messed up on a way to the server initialization.

@aleksmaus aleksmaus merged commit 56a17e0 into elastic:main Aug 27, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-skip Skip notification from the automated backport with mergify enhancement Filebeat Filebeat Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team Team:Security-Deployment and Devices Deployment and Devices Team in Security Solution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[tcp/udp] Add a configuration option for network type
7 participants