This PR changes the UI server so that instead of fetching metrics data from the Fn server's /stats endpoint, it fetches them directly from the Fn server's /metrics endpoint, which is implemented by the Prometheus client running in the Fn server.
Readers will remember that the UI client currently polls the UI server's /api/stats endpoint, which in turn polls the Fn server's /stats endpoint.
With these changes, the UI client continues to poll the UI server's /api/stats endpoint as now, and receives metrics data in the same convenient JSON format as now.
However when the UI server receives a request on /api/stats it now polls the Fn server's /metrics endpoint. This returns the same data in a different format defined by Prometheus. The UI server parses this data using a single regular expression, builds a JSON structure containing this data, and passes it on to the client.
This keeps the regular expression parsing on the server, thereby avoiding increasing the load on the client. However it's just standard Javascript and would be easy to move to the client if we wanted to in the future.
The actual parsing code comes out fairly nicely, though I have added lots of comments and intermediate variables to make it easy to understand and change if needed.
This PR changes the UI server so that instead of fetching metrics data from the Fn server's
/stats
endpoint, it fetches them directly from the Fn server's/metrics
endpoint, which is implemented by the Prometheus client running in the Fn server.Readers will remember that the UI client currently polls the UI server's
/api/stats
endpoint, which in turn polls the Fn server's/stats
endpoint.With these changes, the UI client continues to poll the UI server's
/api/stats
endpoint as now, and receives metrics data in the same convenient JSON format as now.However when the UI server receives a request on
/api/stats
it now polls the Fn server's/metrics
endpoint. This returns the same data in a different format defined by Prometheus. The UI server parses this data using a single regular expression, builds a JSON structure containing this data, and passes it on to the client.This keeps the regular expression parsing on the server, thereby avoiding increasing the load on the client. However it's just standard Javascript and would be easy to move to the client if we wanted to in the future.
The actual parsing code comes out fairly nicely, though I have added lots of comments and intermediate variables to make it easy to understand and change if needed.