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

double guages incorrectly formatted in non-C locales #281

Closed
mjj29 opened this issue Jun 25, 2019 · 2 comments · Fixed by #283
Closed

double guages incorrectly formatted in non-C locales #281

mjj29 opened this issue Jun 25, 2019 · 2 comments · Fixed by #283
Assignees

Comments

@mjj29
Copy link

mjj29 commented Jun 25, 2019

The prometheus ToString(double) calls std::to_string which if you're running in a non-english locale and you've called setlocale (which in our case initializing a in-process JVM will do) can format numbers to be: 123,45 rather than 123.45.

For formatting the output of /metrics I think it needs to always be .-format and not locale-dependent, so you need to use a different mechanism (it looks like getting an ostringstream and calling imbue on it to force a C locale is probably simplest)

To demonstrate outside of prometheus use:

#include <string>
#include <iostream>

int main( int, char** )
{
   std::locale::global(std::locale(""));
   double d = 123.45;
   std::cout << std::to_string(d) << std::endl;
}

To demonstrate with prometheus-cpp just call std::locale::global(std::locale(""));

Unfortunately leaving the global locale set to C isn't an option because loading a JVM with the invocation API in the same process seems to do that.

@gjasny gjasny self-assigned this Jun 25, 2019
gjasny added a commit that referenced this issue Jun 25, 2019
gjasny added a commit that referenced this issue Jun 25, 2019
@gjasny
Copy link
Collaborator

gjasny commented Jun 25, 2019

Hi,

thanks for the report. I added an naive fix as well as a test. Will refine it later.

Thanks,
Gregor

@capone212
Copy link

I can confirm that after the problem is gone. Thanks

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 a pull request may close this issue.

3 participants