[SecurityBundle] Improve profiler’s data #57425
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Let’s display the profiler for a request matching a lone lazy firewall:
Since no channel is forced, we know the
ChannelListenerdid not run. To make it more obvious, this PR displays(none)instead of0.00 mswhen the duration is null (which will happen once #57369 is merged).Before
After
But what about the
ContextListener? Since the firewall is stateful we know it ran, yet its displayed duration also is0.00 ms.Turns out that because the firewall is lazy, the
ContextListenerran way past the moment theTraceableFirewallListenerstored its data. In fact, it may be theSecurityDataCollectoritself which trigger it by accessing the security token. This PR makes theTraceableFirewallListenerfetch data only when needed, so that they’re up-to-date when theSecurityDataCollectorasks for them.Before
After
Now, let’s add a global access control so that the
AccessListenercan do its job:The profiler then says no security listeners have been recorded 🤔
This is because the
AccessListenerlet theExceptionListenerwork out a response by throwingAccessDeniedExceptions. When this happens, theTraceableFirewallListeneris cut short before it can store the data it needs (note that it also impacts non-lazy firewalls, but past listeners would then be recorded).This PR stores these data before listeners are called, so that they are available even if one of them throws (this includes authenticators’ data which suffer from the same issue).
Before
After
(Other listeners are hidden on this screenshot but they would be displayed in the profiler.)