8000 Refactor MultiProcessCollector.collect() to allow for arbitrary merging. by bloodearnest · Pull Request #302 · prometheus/client_python · GitHub
[go: up one dir, main page]

Skip to content

Refactor MultiProcessCollector.collect() to allow for arbitrary merging. #302

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

Merged

Conversation

bloodearnest
Copy link
Contributor
@bloodearnest bloodearnest commented Sep 5, 2018

Factors out a merge() method from the previous collect() method, which
is parameterized, and thus can be used for arbitrary merging of samples.
For motivation, see discussion in issue #275 around merging dead worker's
data into a single mmaped file.

This basically allows us to parameterize the files to be merged, and
also whether to accumulate histograms or not. Accumulation is on by
default, as that is what the prometheus format expects. But it can now
be disabled, which allows merged values to be correctly written back to
an mmaped file. For the same reason, the order of labels is preserved
via OrderedDict.

@brian-brazil
Copy link
Contributor

You've test failures, and need to add a DCO.

@bloodearnest bloodearnest force-pushed the refactor-multiprocess-collect branch from f4cde59 to 34c366d Compare September 5, 2018 13:15
try:
from collections import OrderedDict
except ImportError:
OrderedDict = dict
Copy link
Contributor

Choose a reason for hiding this comment

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

The code should still work on 2.6

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code works, but the order is not preserved on 2.6, so it's different behaviour

Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than changing this, how about changing the format of the multiprocess key to be a dict for the labels and using sort_keys=True?

@bloodearnest bloodearnest force-pushed the refactor-multiprocess-collect branch from 2f12be2 to afaf04d Compare September 7, 2018 13:07
else:
# The duplicates and labels are fixed in the next for.
metric.add_sample(name, tuple(zip(labelnames, labelvalues)), value)
metric.add_sample(name, tuple(labels.items()), value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the ordering here deterministic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, good catch.

@@ -844,6 +851,11 @@ def _floatToGoString(d):
return '-Inf'
elif math.isnan(d):
return 'NaN'
elif sys.version_info[:2] == (2, 6):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was todo with trying to fix that fact that repr of float in 2.6 is different. Ended up just skipping those tests on 2.6.

@brian-brazil
Copy link
Contributor

Can you resolve the conflict? I just merged a large reworking of the library to support openmetrics.

Simon Davy added 7 commits September 7, 2018 18:00
Factors out a merge() method from the previous collect() method, which
is parameterized, and thus can be used for arbitrary merging of samples.
For motivation, see discussion in issue prometheus#275 around merging dead workers
data into a single mmaped file.

This basically allows us to parameterize the files to be merged, and
also whether to accumulate histograms or not. Accumulation is on by
default, as that is what the prometheus format expects. But it can now
be disabled, which allows merged values to be correctly written back to
an mmaped file. For the same reason, the order of labels is preserved
via OrderedDict.

Signed-off-by: Simon Davy <simon.davy@canonical.com>
Signed-off-by: Simon Davy <simon.davy@canonical.com>
Signed-off-by: Simon Davy <simon.davy@canonical.com>
Signed-off-by: Simon Davy <simon.davy@canonical.com>
…ion differences make it too difficult

Signed-off-by: Simon Davy <simon.davy@canonical.com>
Signed-off-by: Simon Davy <simon.davy@canonical.com>
Signed-off-by: Simon Davy <simon.davy@canonical.com>
@bloodearnest bloodearnest force-pushed the refactor-multiprocess-collect branch from c955f42 to a4370a5 Compare September 7, 2018 17:09
@bloodearnest
Copy link
Contributor Author

Rebased on latest master

@brian-brazil brian-brazil merged commit 18017c6 into prometheus:master Sep 7, 2018
@brian-brazil
Copy link
Contributor

Thanks!

@bloodearnest
Copy link
Contributor Author

Awesome, thanks :)

@bloodearnest bloodearnest deleted the refactor-multiprocess-collect branch September 7, 2018 18:17
@xavfernandez
Copy link
Contributor

Thanks @bloodearnest for this feature.

@brian-brazil : any idea when you might release the next version including this ?

@brian-brazil
Copy link
Contributor

I'm waiting to get all the openmetrics stuff in, and then release.

brian-brazil pushed a commit that referenced this pull request Oct 2, 2018
…ng. (#302)

* Refactor MultiprocessCollector.collect to allow for arbitrary merging.

Factors out a merge() method from the previous collect() method, which
is parameterized, and thus can be used for arbitrary merging of samples.
For motivation, see discussion in issue #275 around merging dead workers
data into a single mmaped file.

This basically allows us to parameterize the files to be merged, and
also whether to accumulate histograms or not. Accumulation is on by
default, as that is what the prometheus format expects. But it can now
be disabled, which allows merged values to be correctly written back to
an mmaped file.

Signed-off-by: Simon Davy <simon.davy@canonical.com>
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
0