grafana / grafana-image-renderer

A Grafana backend plugin that handles rendering of panels & dashboards to PNGs using headless browser (Chromium/Chrome)
Apache License 2.0
375 stars 151 forks source link

"User locale" is not used when render image #146

Open sanchomuzax opened 4 years ago

sanchomuzax commented 4 years ago

What happened: The formatting of the number is not true on rendered image.

What you expected to happen: The format of it should be equal than browser version.

How to reproduce it (as minimally and precisely as possible): see below...

Anything else we need to know?: see below...

Environment:

How can I change the format of numbers on Graphs?

The rendered image is wrong for me, it is not our local format: image

This is our local format of numbers, see the browser version is: image

Y-axis setting: image

The parameter of the image link included at the end of the url:

&tz=Europe%2FBudapest

How can I render it as a browser version? The language setting of Chrome on Windows desktop client side is Hungarian. How could I configure of the language of the server side Chrome on CentOS for Grafana image renderer? I can't found it.

marefr commented 4 years ago

Please update description using the bug template to cover what versions etc you're using.

sanchomuzax commented 4 years ago

Please update description using the bug template to cover what versions etc you're using.

Done!

sanchomuzax commented 4 years ago

This is an old bug or flaw that was included in the previous engine: https://github.com/grafana/grafana-image-renderer/issues/45

marefr commented 4 years ago

You want to configure language https://github.com/grafana/grafana/blob/ad870c07cf7d2aa9215fc32de6d5c991ef76b082/conf/defaults.ini#L711 in the Grafana configuration.

marefr commented 4 years ago

The idea is that the language being used in user browser should be sent to the image renderer in each request. Please inspect the direct link rendered image request using chrome developer tools network tab to see what your value of the Accept-Language request header is. You probably also want to enable verbose logging using https://github.com/grafana/grafana/blob/ad870c07cf7d2aa9215fc32de6d5c991ef76b082/conf/defaults.ini#L725 and enable debug log message. Please include debug output here.

sanchomuzax commented 4 years ago

I tried the "rendering_language" with empty and following value also (and restart the server), but no changes.

rendering_language = 'hu-hu, hu;q=0.8'

From the log:

t=2020-05-25T20:33:38+0200 lvl=info msg=Rendering logger=rendering renderer=plugin path="d-solo/{delete by me}/{delete by me}?orgId=3&from=1587765600000&to=1590357599999&var-timezone=2&panelId=7&width=1000&height=500&tz=Europe%2FBudapest"
t=2020-05-25T20:33:38+0200 lvl=dbug msg="Calling renderer plugin" logger=rendering renderer=plugin req="url:\"http://localhost:3000/d-solo/{delete by me}/{delete by me}?orgId=3&from=1587765600000&to=1590357599999&panelId=7&width=1000&height=500&tz=Europe%2FBudapest&render=1\" width:1000 height:500 deviceScaleFactor:1 filePath:\"/var/lib/grafana/png/jU8uSOcAdcNSrm6Efdnx.png\" renderKey:\"RlSikhKOPoQELu572FlA9EiOEr8fnY6X\" domain:\"localhost\" timeout:60 timezone:\"Europe/Budapest\" headers:<key:\"Accept-Language\" value:<values:\"hu-HU,hu;q=0.9,en-US;q=0.8,en;q=0.7\" > > "
marefr commented 4 years ago

I'm confused now. Thought I had tested and verified this. Pretty certain I did. Maybe something weird going on with *nix systems. I'm running Ubuntu with Language English (United States) and regional format Swedish:

> locale
LANG=en_US.UTF-8
LANGUAGE=en_US:
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=sv_SE.UTF-8
LC_TIME=sv_SE.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=sv_SE.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=sv_SE.UTF-8
LC_NAME=sv_SE.UTF-8
LC_ADDRESS=sv_SE.UTF-8
LC_TELEPHONE=sv_SE.UTF-8
LC_MEASUREMENT=sv_SE.UTF-8
LC_IDENTIFICATION=sv_SE.UTF-8
LC_ALL=

With this dashboard still gives me English (United States) numeric formatting when Unit is Locale format: image

For my regular Chrome browser to actually pick up my Swedish number format I had to make code change to Grafana code base. Super strange. Still with this change rendering doesn't work.

Think this is because of HTTP header keys are sent in lower-case: https://github.com/puppeteer/puppeteer/issues/5124

This is definitely not working as expected right now and I'm not sure this can be solved properly without update of Puppeteer/Grafana.

marefr commented 4 years ago

For reference seems like using the raw protocol is working better. Something along these lines.

    page._client.send('Network.setUserAgentOverride', {
      userAgent:
        this.opts.userAgent ||
        (await page.browser().userAgent()).replace(
          'HeadlessChrome/',
          'Chrome/'
        ),
      acceptLanguage: this.opts.locale || 'en-US,en',
      platform: this.opts.platform || 'Win32'
    })
sanchomuzax commented 3 years ago

Could you add a tip for a workaround, until the repair is complete?

sanchomuzax commented 1 year ago

Unfortunately, I still can't set the local (HU) formats.

Grafana: v8.5.15 Grafana Image Renderer: v3.6.2