Skip to content

Conversation

@LKaemmerling
Copy link
Member

@LKaemmerling LKaemmerling commented Nov 6, 2020

This allows incrementing counters with floats.

For this, we need to change the storing logic within the APCuStorage, which used apcu_inc before and now uses the same way as we have it for gauges. We should refactor this a bit in the future.

Additionally, we need to set the Redis storage command based on what the type of the value is with that we want to increment, otherwise, it won't increment and fail "silently".
https://github.com/PromPHP/prometheus_client_php/pull/22/files#diff-e8fd41f0e9039fc21760030aeae90caae1f76729cac8d15cdb3a96df34c37454R45

Closes #20

@LKaemmerling LKaemmerling force-pushed the allow-incrementing-counters-with-floats branch from 7b9fea1 to 5c4ac50 Compare November 6, 2020 13:32
@LKaemmerling LKaemmerling marked this pull request as ready for review November 6, 2020 13:34
@LKaemmerling LKaemmerling requested a review from rdohms November 6, 2020 13:37
rdohms
rdohms previously approved these changes Nov 16, 2020
Copy link
Member

@rdohms rdohms left a comment

Choose a reason for hiding this comment

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

Small comment in case you want to improve understanding, but not blocking.

while (!$done) {
$old = apcu_fetch($valueKey);
if ($old !== false) {
$done = apcu_cas($valueKey, $old, $this->toInteger($this->fromInteger($old) + $data['value']));
Copy link
Member

Choose a reason for hiding this comment

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

am I correct in assuming the toInteger method is to avoid storing a float, and we then convert it back to float?
Might be worth noting that in the commit, or maybe renaming the method to be more expicit.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, apcu can only store integers. I was "confused" by this too a bit at the first view, but then I understood it. It packs the float value as its binary represent which is then an int. The methods was used before and i just reused it but yeah it makes sense to clarify it.

Copy link
Member Author

Choose a reason for hiding this comment

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

@rdohms i renamed them, could you please have a look again?

Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
@LKaemmerling LKaemmerling force-pushed the allow-incrementing-counters-with-floats branch from 5c4ac50 to 7e3186e Compare November 17, 2020 10:52
@LKaemmerling LKaemmerling requested a review from rdohms November 17, 2020 10:52
@LKaemmerling LKaemmerling merged commit d576d10 into master Nov 17, 2020
@LKaemmerling LKaemmerling deleted the allow-incrementing-counters-with-floats branch November 17, 2020 22:06
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.

Support floats in Counters

3 participants