coupergateway / couper

Couper is a lightweight API gateway designed to support developers in building and operating API-driven Web projects
https://couper.io
MIT License
85 stars 15 forks source link

Provide and extend `Server-Timing` header #652

Closed malud closed 1 year ago

malud commented 1 year ago

It would be a great addition if Couper provides the backend timings additionally to the existing log timings as Server-Timing header. Extending an existing Server-Timing header while chaining multiple gateways is also a valid use-case.

filex commented 1 year ago

Typically the request’s name is default. That would be boring. We could use the backend’s name to provide more useful info in the browser’s network inspector. Then it would be smth like api or print_service.

If an endpoint issues multiple requests, they need to have different names. Then, we could create a timing name from the backend and the non-default request name:

api  (omit redundant :default)
api:request2
alex-schneider commented 1 year ago

Do we need a config/setting flag for this feature? Or should Couper always send this header if a backend is used?

filex commented 1 year ago

We need to configure it. I would make it a boolean setting (cli flag, env, settings).

johakoch commented 1 year ago

Currently, the metrics may have a suffix (_[0-9a-f]{6}), which is unique, ok. But it's not possible to identify the position in a sequence of couper layers. Better use numbers, again.

Another idea: Instead of suffixes, use prefixes, as Chrome seems to sort Server Timings in the Timing tab.

filex commented 1 year ago

How can couper know in which position in a sandwich it is in? Or do you mean request sequences in a single endpoint?

alex-schneider commented 1 year ago

The last Couper instance (from client direction) would not have a prefix (or a prefix with the smallest digit).

client <- 2_metric <- 1_metric <- metric

filex commented 1 year ago

I don't think that we need to have those prefixes. if you have a sandwich with multiple coupers and services inbetween, I would hope that the backend-names are distinguishable.