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

Re-implement connected_client to have deterministic cardinality #950

Merged

Conversation

mindw
Copy link
Contributor

@mindw mindw commented Sep 9, 2024

The current connected client suffers from some drawbacks rendering much less useful than it should:

  1. unbound cardinality - the labels "idle_since", "omem" and "cmd" values are unpredictable and there for unbound.
  2. Having values as labels made using them in queries all but impossible, getting the idlest client for example.
  3. The id field which uniquely identifies the client is missing from the labels.

This PR attempts to ratify all that:

  • renames connected_clients_details to connected_client_info (as per prometheus naming conventions) - dropping all high cardinality labels.
  • adds connected_client_output_buffer_memory_usage_bytes, connected_client_total_memory_consumed, connected_client_created_at_timestamp, connected_client_idle_since_timestamp, connected_client_channel_subscriptions_count, connected_client_pattern_matching_subscriptions_count, connected_client_shard_channel_subscriptions_count and connected_client_shard_channel_watched_keys metrics per client.
  • add id to all metrics.

I'm still running some tests on the output metrics, so please don't merge it yet :)

Input, missing bits (docs?) are welcome!

@hiroshi-ishii
Copy link

Quick comments (warning: I do not know any go):

  1. Did you intend to remove the parsing of Cmd entirely (i.e. not just removing it as a label)?
  2. Can you also parse/output the following: qbuf, qbuf-free, obl, oll
  3. port could be an int64; it may be useful to do numerical comparisons on it
  4. Typo on several lines (e.g. 63): cloud not parse ...; not yours but might as well fix it
  5. line 102: error message for watch case instead prints ... 'sub' field ...
  6. Can we replace connected_client_info with flags as a label (there are many flags that can change moment-to-moment), with connected_client_flags as flags as the gauge value? Not sure about this one.
  7. Don't forget to remove the log.Debug() in the ExportClientsInclPort case
  8. Should metric description's descriptions start with caps? i.e. A connected client's ...
  9. I think name should not be part of clientBaseLabels since name can be changed with CLIENT SETNAME. The name should be mapped to the id by other means.
  10. Could we refactor metricDescriptions / registerConstMetricGauge calls with an array & loop -- make it shorter and easier to read?

@mindw
Copy link
Contributor Author

mindw commented Sep 9, 2024

Thanks @hiroshi-ishii for the review - see below:

Quick comments (warning: I do not know any go):

  1. Did you intend to remove the parsing of Cmd entirely (i.e. not just removing it as a label)?
    It was - are there leftovers?
  2. Can you also parse/output the following: qbuf, qbuf-free, obl, oll
    Yes, I'll add it later.
  3. port could be an int64; it may be useful to do numerical comparisons on it
    Port is arbitrary, and isn't unique, I don't recall ever it being exposed as a value.
  4. Typo on several lines (e.g. 63): cloud not parse ...; not yours but might as well fix it
    Fixed.
  5. line 102: error message for watch case instead prints ... 'sub' field ...
    Fixed.
  6. Can we replace connected_client_info with flags as a label (there are many flags that can change moment-to-moment), with connected_client_flags as flags as the gauge value? Not sure about this one.
    Possible - need to look into this.
  7. Don't forget to remove the log.Debug() in the ExportClientsInclPort case
    Fixed, thanks!
  8. Should metric description's descriptions start with caps? i.e. A connected client's ...
    Yes, fixed.
  9. I think name should not be part of clientBaseLabels since name can be changed with CLIENT SETNAME. The name should be mapped to the id by other means.
    That's actually the reason for it to be on the info metric. While ID is unique and name is not, the name is far more human friendly IMO.
  10. Could we refactor metricDescriptions / registerConstMetricGauge calls with an array & loop -- make it shorter and easier to read?
    Maybe, from my experience these kind of generics hurt readability and maintainability. In case of exporters it is quite common to avoid them unless there is something smarter behind them (like generating metrics from struct members dynamically to support future changes).

@oliver006
Copy link
Owner

Hey there and thanks for opening the PR!
I haven't looked at the code yet but I like the idea a lot to break out the details into separate metrics that can be queried and graphed. So go ahead with that.

One request though: can we keep the name of the current client detail metric the same so you don't introduce backwards incompatible changes?

Let me know when you're ready for code review and want comments and then I'll have a look.

Oh, and one more request: can you rebase the PR please? I moved the tests over to Github Actions yesterday and I don't see that here yet.

@mindw mindw force-pushed the dev/mindw/client_connection_info_reworked branch from 356dd9a to 648f6f8 Compare September 9, 2024 15:32
@mindw
Copy link
Contributor Author

mindw commented Sep 9, 2024

Hey there and thanks for opening the PR! I haven't looked at the code yet but I like the idea a lot to break out the details into separate metrics that can be queried and graphed. So go ahead with that.

Tx!

One request though: can we keep the name of the current client detail metric the same so you don't introduce backwards incompatible changes?

It is an optional feature and I'm not sure how much it was used given it's current state also it wont have the same labels. Then again the old name doesn't really follow the Prometheus naming convention. I would suggest to duplicate it the name instead.

Let me know when you're ready for code review and want comments and then I'll have a look.

It's ready :)

Oh, and one more request: can you rebase the PR please? I moved the tests over to Github Actions yesterday and I don't see that here yet.

I've rebased on the latest and greatest main/master.

Thanks!

@hiroshi-ishii
Copy link

@mindw
On (2) Thanks!
On (3) I didn't understand your response.
On (6) maybe we could replace flags in the labels with a subset of mostly permanent flags (e.g. client is replica, client is master)
On (9), on second thought, you're right, and client name doesn't change that often so we're OK.
On (10) I understand what you're saying but I still think it's worthwhile in this case. But it's your rodeo...

Copy link

@hiroshi-ishii hiroshi-ishii left a comment

Choose a reason for hiding this comment

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

Looked at the new changes

exporter/clients.go Outdated Show resolved Hide resolved
exporter/clients.go Outdated Show resolved Hide resolved
exporter/clients_test.go Show resolved Hide resolved
exporter/clients_test.go Outdated Show resolved Hide resolved
exporter/clients_test.go Outdated Show resolved Hide resolved
exporter/clients_test.go Show resolved Hide resolved
@hiroshi-ishii
Copy link

Thanks @mindw, looks good.

Let's see what @oliver006 says.

@mindw mindw force-pushed the dev/mindw/client_connection_info_reworked branch from 7ead98b to 11daff8 Compare September 11, 2024 11:52
@coveralls
Copy link

coveralls commented Sep 11, 2024

Pull Request Test Coverage Report for Build 10993316969

Details

  • 183 of 183 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+1.0%) to 85.116%

Totals Coverage Status
Change from base Build 10969721321: 1.0%
Covered Lines: 2173
Relevant Lines: 2553

💛 - Coveralls

Copy link

codecov bot commented Sep 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.63%. Comparing base (827e6b5) to head (4ff2795).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #950      +/-   ##
==========================================
+ Coverage   80.25%   81.63%   +1.38%     
==========================================
  Files          17       17              
  Lines        1980     2129     +149     
==========================================
+ Hits         1589     1738     +149     
  Misses        306      306              
  Partials       85       85              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mindw
Copy link
Contributor Author

mindw commented Sep 11, 2024

@oliver006 this is ready for your review :)

@mindw mindw force-pushed the dev/mindw/client_connection_info_reworked branch from 11daff8 to fd3ea08 Compare September 13, 2024 05:23
@oliver006
Copy link
Owner

@oliver006 this is ready for your review :)

Sorry about the delay - having a look now.

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.

Overall approach looks good - just a couple of smaller things

docker-compose.yml Show resolved Hide resolved
exporter/clients_test.go Show resolved Hide resolved
exporter/clients.go Outdated Show resolved Hide resolved
exporter/clients.go Outdated Show resolved Hide resolved
@mindw mindw force-pushed the dev/mindw/client_connection_info_reworked branch from 17efb98 to 4f2bf38 Compare September 21, 2024 08:15
@mindw
Copy link
Contributor Author

mindw commented Sep 27, 2024

@oliver006 IMO all comments were addressed, anything else?

@oliver006
Copy link
Owner

@oliver006 IMO all comments were addressed, anything else?

Apologies for the delay, I didn't have much time last week, will get back to this again in the next few days.

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.

Nice work - thanks for getting this done!

docker-compose.yml Show resolved Hide resolved
@oliver006 oliver006 merged commit f1bafc8 into oliver006:master Oct 5, 2024
10 checks passed
@mindw mindw deleted the dev/mindw/client_connection_info_reworked branch October 8, 2024 05:56
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.

4 participants