MyUnisoft / loki

Node.js Loki SDK
MIT License
15 stars 3 forks source link

gzip response: must be of type string or an instance of Buffer or Uint8Array. Received an instance of ArrayBuffer #162

Closed Sokwva closed 4 months ago

Sokwva commented 4 months ago

TypeError: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of ArrayBuffer

 const { type, parameters } = contentType.parse(contentTypeHeader ?? kDefaultMimeType);
 let body;
 try {
     if (response.headers["content-encoding"] === "gzip") {
         const buf = await response.body.arrayBuffer();
         body = (await kAsyncGunzip(buf)).toString(getEncodingCharset(parameters.charset));
                             ^

TypeError: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of ArrayBuffer

Bun v1.1.17 grafana 11.0.0

fraxken commented 4 months ago

Hello 👋

Likely to be an issue with Bun no? Do you have a complete stack trace, this code is probably related to our httpie wrapper or undici.

But anyway it mean buf is undefined which seems weird if the content-type is gzip.

Sokwva commented 4 months ago

Yes,It's related with bun and typescript. The code I used copied from readme,only change token and Grafana server url. But my Grafana server is behind a nginx.

location /grafana/ {
                proxy_pass http://localhost:3000/;
                proxy_set_header Host $host;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection $connection_upgrade;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
        }
TypeError: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of ArrayBuffer
 code: "ERR_INVALID_ARG_TYPE"

      at new NodeError (node:stream:420:20)
      at _write (node:stream:2672:20)
      at node:stream:2852:76
      at zlibBuffer (node:zlib:2389:24)
      at node:util:147:14
      at E:\test\node_modules\@myunisoft\httpie\dist\utils.js:68:27
fraxken commented 4 months ago

Do you reproduce by executing with Node? My colleague @SofianD looked and he found similar issue on Bun in the past.

If this happen on Node we need to achieve a minimal reproduction for us to work on it (else if that confirmed to be an issue with Bun then we can close this issue).

Sokwva commented 4 months ago

My loki is under nginx proxy. When I ignore nginx and direct connect to loki the problem was gone. After that,I tested the script under Node and Bun,they perferm well now,thank you.

Sokwva commented 4 months ago

btw,I changed remoteApiURL from Grafana Server url to loki api url,it is looks ok,but when I change back to Grafana Server url,Bun throw an error like before,and Node throw a Not Found error,and attached an detail said:

{
  statusMessage: 'Not Found',
  statusCode: 404,
  headers: {
    server: 'nginx/1.18.0 (Ubuntu)',
    date: 'Tue, 02 Jul 2024 07:52:17 GMT',
    'content-type': 'text/html; charset=UTF-8',
    'transfer-encoding': 'chunked',
    connection: 'keep-alive',
    'cache-control': 'no-store',
    'x-content-type-options': 'nosniff',
    'x-frame-options': 'deny',
    'x-xss-protection': '1; mode=block'
  },
  data: '<!DOCTYPE html>\n' +
    '<html lang="zh-Hans">\n' +
    '  <head>\n' +
    '    \n' +
    '    <meta charset="utf-8" />\n' +
    '    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />\n' +
    '    <meta name="viewport" content="width=device-width" />\n' +
    '    <meta name="theme-color" content="#000" />\n' +
    '\n' +
    '    <title>Grafana</title>\n' +
    '\n' +
    '    <base href="/grafana/" />\n' +
    '\n' +
    '    <link rel="icon" type="image/png" href="public/img/fav32.png" />\n' +
    '    <link rel="apple-touch-icon" sizes="180x180" href="public/img/apple-touch-icon.png" />\n' +
    '    <link rel="mask-icon" href="public/img/grafana_mask_icon.svg" color="#F05A28" />\n' +
    '\n' +
    '    \n' +
    '    \n' +
    '    <link rel="stylesheet" href="public/build/grafana.dark.044d0c515b179d71f902.css" />\n' +
    '    \n' +
    '\n' +
    '    <script nonce="">\n' +
    "      performance.mark('frontend_boot_css_time_seconds');\n" +
    '    </script>\n' +
    '\n' +
    '    <meta name="apple-mobile-web-app-capable" content="yes" />\n' +
    '    <meta name="apple-mobile-web-app-status-bar-style" content="black" />\n' +
    '    <meta name="msapplication-TileColor" content="#2b5797" />\n' +
    '    <meta name="msapplication-config" content="public/img/browserconfig.xml" />\n' +
    '  </head>\n' +
    '\n' +
    '  <body class="theme-dark app-grafana">\n' +
    '    <style>\n'
}

maybe enviromental related issue.