Skip to content

Allow resetting request context instrumentation data

While working on !118614 (closed), I realized that the way instrumentation sessions are initialized/reset does not currently work if we need to run multiple individual sessions per "request". The problem is really with how we track this data: per request. However, in the context of a websockets push there is no request. It is server-initiated and in this case re-executes a query N times for each subscriber, each of these should be instrumented individually. This leads to counters compounding over each of these invocations, which yields incorrect data when logged per each query execution.

I think the best long-term solution would be to completely separate instrumentation of server work loads (HTTP requests, Action Cable RPCs or pushes) from RequestContext. However, that is a lot more work, so I think an incremental step toward this would be to restructure how instrumentation data is tracked in the request context to provide an easier way to reset it:

Currently, instrumentation data uses a flat approach to storing things like counters:

  • context
    • zoekt_request_count
    • zoekt_call_duration
    • gitaly_query_time
    • ...
    • some_other_random_key

What if we made this a nested structure instead:

  • context
    • instrumentation
      • zoekt
        • request_count
      • gitaly
        • query_time
      • ...
    • some_other_random_key

It would give us a clean way to wipe instrumentation data either entirely delete(:instrumentation) or partially delete(:zoekt).

Edited by Matthias Käppler