-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Allow URL format in Metricbeat Redis module #10920
Conversation
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? |
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: 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 |
18b42c8
to
220f822
Compare
220f822
to
5f3c46e
Compare
@andrewkroh Great, I've updated it to use the |
metricbeat/module/redis/metricset.go
Outdated
if base.HostData().Password != "" { | ||
password = base.HostData().Password | ||
} else { | ||
password = config.Password |
There was a problem hiding this comment.
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 😉 .
There was a problem hiding this comment.
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
istestpassword
b) With this config:
- module: redis
period: 10s
hosts: ["redis://:[email protected]:6379"]
password: testpassword
These are the values:
base.HostData().Password
isnewpassword
(in my changes we prioritize this one, the other hosts would useconfig.Password
).config.Password
istestpassword
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
istestpassword
.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks!
Yeah, that makes sense to me. |
5f3c46e
to
6b8f762
Compare
@matiasinsaurralde Seems like there are some merge conflicts need to be solved here 😬 |
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. |
Potential fix for #10917
This change will keep the usual functionality when using this approach:
Additionally allowing the use of Redis URL syntax:
The
password
field will be used for allhost:port
values. On URL values, the password set in the scheme will have priority.