Open wangfakang opened 3 years ago
@mattklein123 @htuch Plz help reviews it, I can pull PR if that's ok.
Checking my understanding. You are saying that the per-filter access log handlers run after the access log sink handlers registered with HCM?
It seems reasonable for them to run before, but it seems kind of hacky to be mutating stream state at this point when the stream is undergoing destruction.
Checking my understanding. You are saying that the per-filter access log handlers run after the access log sink handlers registered with HCM?
Yeah. It means per-filter-log and access-log handler should be runs in the same order as the p2
picture.
It seems reasonable for them to run before, but it seems kind of hacky to be mutating stream state at this point when the stream is undergoing destruction.
Usually we might need to do something in the filter log phase and then log it via the access_log
handler, but this is invalid now. Forexample we create the metadata xxx :yy
is set in the log phase of HTTP filter, then the %DYNAMIC_METADATA(xxx :yy)%
in access_log format does not work.
So I propose that the runtime of the access_log
handler should be placed at the end of the per-filter log, Just like the picture p2
above.
ping @htuch
This seems reasonable, although I still don't fully grok why you do dynamic metadata creation during destruction.
This seems reasonable, although I still don't fully grok why you do dynamic metadata creation during destruction.
@htuch Forexample, we need to unify the processing time of some http filter, and then record the statistical results to the access log through dynamic metadata.
+1 on this request
@htuch @mattklein123
What about adding a new method prependAccessLogHandler
? Adding this method won't break any code. If a filter wants to record the statistical results to the access log through dynamic metadata, it can choose the new method. The addAccessLogHandler
can still be used by the HCM to insert multiple access log handlers in the current order.
This also solves #30859 easily: Just change one line addAccessLogHandler
to prependAccessLogHandler
.
Sounds reasonable to me, @mattklein123?
Hey @spacewander, could you elaborate more on the prependAccessLogHandler
? is prependAccessLogHandler
still adding loggers to the access_loghandlers? Why could it ensure that access_logger logs after the filter log?
to provide some context: Seems we still require fix for https://github.com/envoyproxy/envoy/issues/30859 . We would love to make the prependAccessLogHandler
changes if it could solve our problem.
Sure sounds good to me.
Hey @spacewander, could you elaborate more on the
prependAccessLogHandler
? isprependAccessLogHandler
still adding loggers to the access_loghandlers? Why could it ensure that access_logger logs after the filter log?to provide some context: Seems we still require fix for #30859 . We would love to make the
prependAccessLogHandler
changes if it could solve our problem.
@Elliot-xq
Yes, prependAccessLogHandler
still adds loggers to the access_log_handlers_
, just in a different direction.
The current status is:
So if we provide a new method to add an access log handler by prepending it, we can use this method to add the filter log before the access_loggers, without changing the execution order (just change the method we call in the filter).
I am also going to change the golang filter's access log, which is a part of my recent job to improve its access log mechanism. Hope this would be helpful to you.
Thanks for the explanation @spacewander !!
Title: The order of
access_log
handler settings may not be the bestDescription
Now
access_log
is always runs before each filter log phase of HTTP, which will cause some operations in the log phase of http filter to not take effect in the access_log handler. Forexample, if the metadataxxx :yy
is set in the log phase of HTTP filter, then%DYNAMIC_METADATA(xxx :yy)%
in access_log format does not work.Analysis
access_log
is registered at the ActiveStream.each filter log handler of HTTP is registered at the decodeHeaders.
The log handler is registered using push_back, So it means FIFO.
So the
access_log
handler will be called first during the log phase.Expect
The
access_log
handler may be better to runs after all log handler of http filter.