fnproject / ui

User interface for fn project.
Apache License 2.0
89 stars 21 forks source link

Fetch metrics from /metrics instead of /stats #48

Closed nigeldeakin closed 6 years ago

nigeldeakin commented 6 years ago

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.

skinowski commented 6 years ago

Thanks for doing this. :+1: Good step in getting rid of /stats eventually.

nigeldeakin commented 6 years ago

I've changed the RE to expect the metric name to be at the start of the line. This forces an exact match. And retested.