-
Notifications
You must be signed in to change notification settings - Fork 801
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 Gauge
s
#794
Merged
csmarchbanks
merged 3 commits into
prometheus:master
from
JoshKarpel:more-multiproc-modes
Apr 25, 2022
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import os | ||
import warnings | ||
|
||
from .metrics import Gauge | ||
from .metrics_core import Metric | ||
from .mmap_dict import MmapedDict | ||
from .samples import Sample | ||
|
@@ -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]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe |
||
# Those files can disappear between the glob of collect | ||
# and now (via a mark_process_dead call) so don't fail if | ||
# the file is missing | ||
|
@@ -96,15 +97,15 @@ def _accumulate_metrics(metrics, accumulate): | |
name, labels, value, timestamp, exemplar = s | ||
if metric.type == 'gauge': | ||
without_pid_key = (name, tuple(l for l in labels if l[0] != 'pid')) | ||
if metric._multiprocess_mode == 'min': | ||
if metric._multiprocess_mode in ('min', 'livemin'): | ||
current = samples_setdefault(without_pid_key, value) | ||
if value < current: | ||
samples[without_pid_key] = value | ||
elif metric._multiprocess_mode == 'max': | ||
elif metric._multiprocess_mode in ('max', 'livemax'): | ||
current = samples_setdefault(without_pid_key, value) | ||
if value > current: | ||
samples[without_pid_key] = value | ||
elif metric._multiprocess_mode == 'livesum': | ||
elif metric._multiprocess_mode in ('sum', 'livesum'): | ||
samples[without_pid_key] += value | ||
else: # all/liveall | ||
samples[(name, labels)] = value | ||
|
@@ -156,7 +157,6 @@ def mark_process_dead(pid, path=None): | |
"""Do bookkeeping for when one process dies in a multi-process setup.""" | ||
if path is None: | ||
path = os.environ.get('PROMETHEUS_MULTIPROC_DIR', os.environ.get('prometheus_multiproc_dir')) | ||
for f in glob.glob(os.path.join(path, f'gauge_livesum_{pid}.db')): | ||
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}: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: |
||
for f in glob.glob(os.path.join(path, f'gauge_{mode}_{pid}.db')): | ||
os.remove(f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
since the support is comprehensive with this change, wonder if we should simplify this to be something like: