-
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 #12408
Allow URL format in Metricbeat Redis module #12408
Conversation
Tests seem to be failing. Is this change backwards compatible? I think so but want to confirm |
Thanks for reviewing. The failing test is fixed and also added a test to prove it is backwards compatible. |
LGTM, this will need a changelog |
It seems that the password in redis URIs can be defined as parameter too ( |
Good point, thank you @jsoriano ! I just changed the CreatePool method to call rd.DialURL directly. But when I was testing this, But the parameter way When I look for documentation on URL format, I see this: https://www.npmjs.com/package/redis-url#url-format hmmm is the parameter way officially supported or I'm doing something wrong here? 😬 |
@jsoriano I added some 'nasty' parsing in order to make |
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.
Just a quick drive-by review. 😄 (I may have commented on things that were already discussed, so sorry if I did.)
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.
Turned out
redis.DialURL
does not recognize the PASSWORD and DATABASE as a part of the query parameters. I had to manually parse PASSWORD and DATABASE out and pass them asDialOptions
intoDialURL
function.
Ouch 🙁 docs misguided me, thanks for investigating this! And great you found a solution. Maybe we can contribute back the support for query parameters to the client library we use? 🙂
Is there any reason to don't use URL.Query()
or url.ParseQuery()
to parse the query arguments?
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.
Sorry, a few more small things... mainly about handing of database
configuration, and some details in error messages and tests.
metricbeat/module/redis/metricset.go
Outdated
err := base.Module().UnpackConfig(&config) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to read configuration") | ||
} | ||
|
||
password, database, err := getPasswordDatabase(base.HostData().URI, base.HostData().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.
Database can be also in the path of the url (redis://[:password@]host[:port][/db-number][?option=value]
). For an URL like redis://host/16
, will it use the 0
returned here instead of the 16
? I think we should add the DialDatabase
option only if the database is set as an option.
If it complicates things a lot I am also ok with giving some working examples in the documentation.
In any case it wouldn't be a regression because I think that we cannot configure the database now.
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.
Missed it!! Thanks!!
I added a part in the same function to check db-number from URI itself. Please let me know what you think 👍
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.
Looks good, thanks! We should contribute these things to redigo
so all this is done by DialURL
😄
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.
Thanks for all the work here to cover all the cases! 👍
}, | ||
{ | ||
"test redis uri with db number in URI and query field", | ||
mb.HostData{URI: "redis://:password1@127.0.0.2:6379/1?password=password2&db=2", Password: "password1"}, |
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.
😄
Thanks for all the reviews!! |
Continues with #10920
Original commit message:
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.Co-authored-by: Matias Insaurralde matias@insaurral.de