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

include user info in redis_connected_clients_details #776

Merged
merged 12 commits into from
Mar 18, 2023

Conversation

misTrasteos
Copy link
Contributor

Related to issue #775, redis_connected_clients_details don't show user info.

This is still a WIP as there are no test yet. But it tries to follow comment

Please let me know if this approach and code changes are likely to be merged, and I will finish it. Otherwise feel free to reject it.

parseClientListString now returns a map containing the parsed output of the client list reply
extractConnectedClientMetrics now creates the metric description. Instead during startup at exporter.go

Maybe this is not somehow very efficient as they are created at every scrape.

Copy link
Owner

@oliver006 oliver006 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!
Looking good - left two comments.

@@ -16,7 +16,7 @@ import (
id=11 addr=127.0.0.1:63508 fd=8 name= age=6321 idle=6320 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=setex
id=14 addr=127.0.0.1:64958 fd=9 name= age=5 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=32742 obl=0 oll=0 omem=0 events=r cmd=client
*/
func parseClientListString(clientInfo string) ([]string, bool) {
func parseClientListString(clientInfo string) (map[string]string, bool) {
Copy link
Owner

Choose a reason for hiding this comment

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

I like that you're making this a bit more explicit and not use the array any longer but while you're changing this, maybe turn this into a ClientInfo struct.

Copy link
Owner

Choose a reason for hiding this comment

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

Also, I don't see where you're extracting "user" - I think that's missing.
White you're at it, want to add resp as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • There is now a ClientInfo struct.

  • "user" field is extracted as the rest of the fields during the range strings.Split(clientInfo, " ")

The clientinfo string is like id=4 addr=127.0.0.1:50000 laddr=127.0.0.1:6379 fd=8 name= age=5 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=40928 argv-mem=10 obl=0 oll=0 omem=0 tot-mem=61466 events=r cmd=client user=default redir=-1 from a redis>6 server

  • Sorry, but I do not understand the resp part

Please let me know anything, thanks for the feedback !

Copy link
Owner

Choose a reason for hiding this comment

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

Oh, the documentation here says resp: client RESP protocol version. Added in Redis 7.0

@oliver006
Copy link
Owner

Check the tests:
https://drone-github.21zoo.com/oliver006/redis_exporter/66

They're failing:
vet: exporter/clients_test.go:95:23: cannot range over lbls (variable of type *ClientInfo)

I think in the tests you can just replace expectedLbls with the ClientInfo that matches the expected return from the parseClientListString() function

exporter/clients.go Outdated Show resolved Hide resolved
exporter/clients.go Outdated Show resolved Hide resolved
@@ -16,7 +16,7 @@ import (
id=11 addr=127.0.0.1:63508 fd=8 name= age=6321 idle=6320 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=setex
id=14 addr=127.0.0.1:64958 fd=9 name= age=5 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=32742 obl=0 oll=0 omem=0 events=r cmd=client
*/
func parseClientListString(clientInfo string) ([]string, bool) {
func parseClientListString(clientInfo string) (map[string]string, bool) {
Copy link
Owner

Choose a reason for hiding this comment

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

Oh, the documentation here says resp: client RESP protocol version. Added in Redis 7.0

@oliver006
Copy link
Owner

Have a look at the tests, there are still errors:
https://drone-github.21zoo.com/oliver006/redis_exporter/76/1/16

=== RUN   TestParseClientListString

    clients_test.go:105: TestParseClientListString( id=11 addr=127.0.0.1:63508 fd=8 name= age=6321 idle=6320 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=setex ) error. Given: &{  1678807654 1678807655 N 0 0 setex 127.0.0.1 63508 } Wanted: {  1678807654 1678807655 N 0 0 setex 127.0.0.1 63508 }

    clients_test.go:105: TestParseClientListString( id=14 addr=127.0.0.1:64958 fd=9 name=foo age=5 idle=0 flags=N db=1 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=32742 obl=0 oll=0 omem=0 events=r cmd=client ) error. Given: &{foo  1678813970 1678813975 N 1 0 client 127.0.0.1 64958 } Wanted: {foo  1678813970 1678813975 N 1 0 client 127.0.0.1 64958 }

    clients_test.go:105: TestParseClientListString( id=14 addr=127.0.0.1:64959 fd=9 name= age=5 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=32742 obl=0 oll=0 omem=0 events=r cmd=client user=default resp=3 ) error. Given: &{ default 1678813970 1678813975 N 0 0 client 127.0.0.1 64959 3} Wanted: { default 1678813970 1678813975 N 0 0 client 127.0.0.1 64959 3}

--- FAIL: TestParseClientListString (0.00s)

@coveralls
Copy link

coveralls commented Mar 15, 2023

Pull Request Test Coverage Report for Build 85

  • 53 of 55 (96.36%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.06%) to 92.544%

Changes Missing Coverage Covered Lines Changed/Added Lines %
exporter/clients.go 53 55 96.36%
Totals Coverage Status
Change from base Build 63: 0.06%
Covered Lines: 1899
Relevant Lines: 2052

💛 - Coveralls

@misTrasteos
Copy link
Contributor Author

I think everything should be OK by now. I had some problems running the tests.

Any feedback is really welcome, thanks !

Copy link
Owner

@oliver006 oliver006 left a comment

Choose a reason for hiding this comment

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

🚀

@oliver006 oliver006 merged commit de4f5eb into oliver006:master Mar 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants