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

Allow URL format in Metricbeat Redis module #10920

Conversation

matiasinsaurralde
Copy link

@matiasinsaurralde matiasinsaurralde commented Feb 24, 2019

Potential fix for #10917

This change will keep the usual functionality when using this approach:

- module: redis
  period: 10s
  # Redis hosts
  hosts: ["127.0.0.1:6379", "127.0.0.2:6379"]

Additionally allowing the use of Redis URL syntax:

- module: redis
  period: 10s
  # Redis hosts
  hosts: ["127.0.0.1:6379", "redis://:[email protected]:6379"]

The password field will be used for all host:port values. On URL values, the password set in the scheme will have priority.

@matiasinsaurralde matiasinsaurralde requested a review from a team as a code owner February 24, 2019 10:49
@elasticmachine
Copy link
Collaborator

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@andrewkroh
Copy link
Member

The way we handle this in most of the other MetricSets is to register a "host parser" when registering the metricset. It would be done here:

https://github.com/elastic/beats/blob/18b42c8804adb1f2aa60d2edb9873c0fccbad8fa/metricbeat/module/redis/info/info.go#L37

The main benefit is that the password redacted so that we don't show it in the logs. An example you can look at is in mysql:

https://github.com/elastic/beats/blob/master/metricbeat/module/mysql/status/status.go#L43

Please consider refactoring this to use a HostParser.

@matiasinsaurralde
Copy link
Author

@andrewkroh Great, I've updated it to use the URLHostParserBuilder, all formats seem to work correctly (host:port, redis://host:port, redis://:password@host:port).
Do you think that introducing a DefaultPort in URLHostParserBuilder makes sense too? At the moment using redis://host without specifying a port will fail.

if base.HostData().Password != "" {
password = base.HostData().Password
} else {
password = config.Password
Copy link
Member

Choose a reason for hiding this comment

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

If you look at URLHostParserBuilder you'll see that it takes into account the value of the password config option when the URL doesn't contain a password. That should make this code block unnecessary. Likewise Password can be removed from the struct declaration above (like 42).

Then down below you can pass base.HostData().Password into CreatePool. Try that and make sure it's working like I think it supposed to 😉 .

Copy link
Author

Choose a reason for hiding this comment

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

I don't see the password being populated as you describe:
a) With this config:

- module: redis
  period: 10s
  hosts: ["redis://127.0.0.1:6379"]
  password: testpassword

These are the values:

  • base.HostData().Password is empty.
  • config.Password is testpassword

b) With this config:

- module: redis
  period: 10s
  hosts: ["redis://:[email protected]:6379"]
  password: testpassword

These are the values:

  • base.HostData().Password is newpassword (in my changes we prioritize this one, the other hosts would use config.Password).
  • config.Password is testpassword

c) With this config:

- module: redis
  period: 10s
  hosts: ["127.0.0.1:6379"]
  password: testpassword

These are the values:

  • base.HostData().Password is empty.
  • config.Password is testpassword.

Copy link
Member

@andrewkroh andrewkroh Mar 4, 2019

Choose a reason for hiding this comment

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

I found the problem have provided a patch that you can incorporate. The issue was that the URL parser was not setting the password when there was no username. I also added a test case to verify the behavior or the redis metricset.

url-parse-password.patch.txt
(you can use git apply <filename> to add these changes to your local branch and test them)

Copy link
Author

Choose a reason for hiding this comment

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

Great, thanks!

@andrewkroh
Copy link
Member

andrewkroh commented Feb 28, 2019

Do you think that introducing a DefaultPort in URLHostParserBuilder makes sense too? At the moment using redis://host without specifying a port will fail.

Yeah, that makes sense to me.

@matiasinsaurralde matiasinsaurralde requested a review from a team as a code owner March 4, 2019 21:38
@ruflin ruflin added module review Metricbeat Metricbeat Team:Integrations Label for the Integrations team labels Mar 5, 2019
@kaiyan-sheng
Copy link
Contributor

@matiasinsaurralde Seems like there are some merge conflicts need to be solved here 😬

@kaiyan-sheng
Copy link
Contributor

Hi @matiasinsaurralde Thank you for contributing! It will be great to have this fix in. I have opened #12408 to resolve merge conflicts so we can continue the work and merge it.
I am closing this for now and @matiasinsaurralde please feel free to reopen it and continue the work! Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Metricbeat Metricbeat module review Team:Integrations Label for the Integrations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants