snikket-im / snikket-web-portal

This is the web portal for Snikket Chat services. To learn more about what Snikket Chat services are, check the website.
https://snikket.org
GNU Affero General Public License v3.0
32 stars 12 forks source link

Error retrieving statistics immediately on startup #171

Closed Zash closed 7 months ago

Zash commented 8 months ago
  1. Start Snikket
  2. Login as an admin
  3. Navigate to /admin/system/
  4. Observe error
  5. Wait a minute or so
  6. Refresh page
  7. Observe that it works

Theory: Something about statistics collection is not ready until after a bit.

  File "/usr/lib/python3/dist-packages/quart/app.py", line 1673, in full_dispatch_request
    result = await self.dispatch_request(request_context)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/quart/app.py", line 1718, in dispatch_request
    return await self.ensure_async(handler)(**request_.view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/snikket-web-portal/snikket_web/prosodyclient.py", line 498, in wrapped
    return await f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/snikket-web-portal/snikket_web/prosodyclient.py", line 522, in wrapped
    return await f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/snikket-web-portal/snikket_web/admin.py", line 786, in system
    prosody_metrics = await client.get_system_metrics()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/snikket-web-portal/snikket_web/prosodyclient.py", line 329, in wrapper
    return (await f(self, *args, session=session, **kwargs))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/snikket-web-portal/snikket_web/prosodyclient.py", line 1378, in get_system_metrics
    return await resp.json()
           ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/aiohttp/client_reqrep.py", line 1120, in json
    return loads(stripped.decode(encoding))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 38 (char 37)
mwild1 commented 7 months ago

Found the problem here - Prosody returns 'nan' before the metrics have properly initialized:

{"memory":21438464,"cpu":{"since":1705099455.7352,"value":0.355697},"uploads":nan,"c2s":0}
mwild1 commented 7 months ago

Fixed by the latest commit (f76909ec1300) in prosody-modules.