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

Add sum, livemin, and livemax multiprocess modes for Gauges #794

Merged
merged 3 commits into from
Apr 25, 2022
Merged

Add sum, livemin, and livemax multiprocess modes for Gauges #794

merged 3 commits into from
Apr 25, 2022

Conversation

JoshKarpel
Copy link
Contributor

Hi!

I work on a multiprocess Flask application and we recently found ourselves wanting the equivalent of the max multiprocessing mode, but only for live processes. I came here to poke around the code and also noticed this recent issue asking for a sum mode #793 , so it seems like there's some interest in more multiprocess modes.

If I understand correctly, the core change needed to support this is actually around the deletion of the files when a process dies - files for live* metrics should be deleted, others should not. So I added the new modes with the same collection logic as their non-live counterparts and expanded the check in mark_process_dead() to automatically include any metric with live as part of its multiprocess mode name (this might be excessively fancy, but it seemed useful to reduce potential future changes).

I also added tests to cover these new modes based on the existing tests and updated the README.md to describe the new modes.

Signed-off-by: Josh Karpel <josh.karpel@gmail.com>
@csmarchbanks
Copy link
Member

Thanks! I should have some time next week to give this a review.

README.md Outdated
- 'min': Return a single timeseries that is the minimum of the values of all processes, alive or dead.
- 'livemin': Return a single timeseries that is the minimum of the values of alive processes.
Copy link

Choose a reason for hiding this comment

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

since the support is comprehensive with this change, wonder if we should simplify this to be something like:

- 'all': Default. Return a timeseries per process (alive or dead)
- 'sum': Return a single timeseries that is the some of the values of all processes (alive or dead).
- 'max': Return a single timeseries that is the maximum of the values of all processes (alive or dead).
- 'min': Return a single timeseries that is the minimum of the values of all processes (alive or dead).

Prepend 'live' to the beginning of the mode to return the same result but only considering living processes
- eg: 'liveall, 'livesum', 'livemax', 'livemin'

@@ -63,7 +64,7 @@ def _parse_key(key):
try:
file_values = MmapedDict.read_all_values_from_file(f)
except FileNotFoundError:
if typ == 'gauge' and parts[1] in ('liveall', 'livesum'):
if typ == 'gauge' and 'live' in parts[1]:
Copy link

Choose a reason for hiding this comment

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

maybe parts[1].startswith('live')?

os.remove(f)
for f in glob.glob(os.path.join(path, f'gauge_liveall_{pid}.db')):
os.remove(f)
for mode in {m for m in Gauge._MULTIPROC_MODES if 'live' in m}:
Copy link

Choose a reason for hiding this comment

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

if we agree on the previous one then probably would want to make the same change here: m.startswith('live')

Signed-off-by: Josh Karpel <josh.karpel@gmail.com>
@csmarchbanks
Copy link
Member

csmarchbanks commented Apr 13, 2022

Some personal stuff came up and it is looking unlikely I am going to be able to review this PR this week. Just wanted to let you know that I have not forgotten about it!

@JoshKarpel
Copy link
Contributor Author

Some personal stuff came up and it is looking unlikely I am going to be able to review this PR this week. Just wanted to let you know that I have not forgotten about it!

No worries, and no rush! Hope everything turns out ok!

Copy link
Member

@csmarchbanks csmarchbanks left a comment

Choose a reason for hiding this comment

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

Thanks! This looks great, one small comment otherwise 👍.

README.md Outdated Show resolved Hide resolved
Signed-off-by: Josh Karpel <josh.karpel@gmail.com>
Copy link
Member

@csmarchbanks csmarchbanks left a comment

Choose a reason for hiding this comment

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

Awesome, thanks again!

@csmarchbanks csmarchbanks merged commit 5a5261d into prometheus:master Apr 25, 2022
@JoshKarpel JoshKarpel deleted the more-multiproc-modes branch April 25, 2022 14:49
@JoshKarpel
Copy link
Contributor Author

Awesome, thanks again!

My pleasure! Thanks for reviewing!

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