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

Lightweight modules parses hosts twice #19849

Closed
sayden opened this issue Jul 13, 2020 · 3 comments · Fixed by #20149
Closed

Lightweight modules parses hosts twice #19849

sayden opened this issue Jul 13, 2020 · 3 comments · Fixed by #20149
Labels
bug libbeat Team:Services (Deprecated) Label for the former Integrations-Services team

Comments

@sayden
Copy link
Contributor

sayden commented Jul 13, 2020

The Lightweight modules executes the WithHostParser twice. This is currently creating a bug when using a custom host parser like the DSN parsers that you can use in MySQL.

How to reproduce

Exiting: 1 error: host parser failed on light metricset factory for 'mysql/performance': error parsing mysql host: default addr for network 'root:/' unknown

What is happening is that it gets the config data from mysql.yml creates the uri and parses it. Then it mutates incoming config with the output of the parser. Finally, the parser is executed again with the mutated data and it fails.

Failling block is probably this one https://github.com/elastic/beats/blob/master/metricbeat/mb/lightmetricset.go#L86

It seems that the solution would be to avoid the second execution of the host parser.

Related issues

#16205

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Jul 13, 2020
@sayden sayden added the Team:Services (Deprecated) Label for the former Integrations-Services team label Jul 13, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/integrations-services (Team:Services)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Jul 13, 2020
@urso
Copy link

urso commented Jul 14, 2020

What is happening is that it gets the config data from mysql.yml creates the uri and parses it. Then it mutates incoming config with the output of the parser. Finally, the parser is executed again with the mutated data and it fails.

Why do we need to mutate the config object. We should try to never mutate the config object, as it is a source for potential bugs, race conditions and inconsistent configurations applied in Beats. Using the setters should be reserved for a few edge cases that need to create a config object only.
Can we store the parsed connection string in another, properly typed variable?

@jsoriano
Copy link
Member

What is happening is that it gets the config data from mysql.yml creates the uri and parses it. Then it mutates incoming config with the output of the parser. Finally, the parser is executed again with the mutated data and it fails.

Why do we need to mutate the config object. We should try to never mutate the config object, as it is a source for potential bugs, race conditions and inconsistent configurations applied in Beats. Using the setters should be reserved for a few edge cases that need to create a config object only.

In light modules a new configuration is created with some initial default values, we then update this configuration with the user defined settings from the original base module, and this configuration is used to create a new base module, that is the one actually used at the end. Original base module or its configuration is not modified during this process.

Host parsers also don't mutate the config. The problem is that we use to call the host parser with the value of the host in the base module, and then we modify the host in the base module, so we lose the original string. Then if we make multiple calls to the host parser, we can have different results (as happens with light modules now).

Can we store the parsed connection string in another, properly typed variable?

The parsed host is already stored in a host data object, that is something like this. The problem is that from the information there we cannot know the original value of the host setting in case we want to call the host parser again.

I am exploring two options to fix this issue:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug libbeat Team:Services (Deprecated) Label for the former Integrations-Services team
Projects
None yet
5 participants