envoy icon indicating copy to clipboard operation
envoy copied to clipboard

DateFormatter only provide second level precision for absl format

Open wbpcode opened this issue 1 year ago • 4 comments

This is because two problems:

  1. time_t is used when calling the absl::FormatTime. The time_t only provide second level precision.
  2. The time cache. The cache is updated in second level. And the code will get the cached string and replace sub-second part to sub-second of current timepoint. But the code only handle the specifier %f and don't handle absl format (actually it's not easy to handle it, this means we maybe shouldn't use time cache for dynamic format string).

wbpcode avatar Jul 24 '24 07:07 wbpcode

cc @dio @mattklein123

wbpcode avatar Jul 24 '24 10:07 wbpcode

START_TIME can be customized using a format string.

IIUC, the doc does not mention support the fractional second format in absl::FormatTime, instead it only mention the %f format. So, it's safe to cache by seconds, thoughts?

doujiang24 avatar Jul 26 '24 03:07 doujiang24

The default format that used by Envoy is %Y-%m-%dT%H:%M:%E3SZ but current DateFormtter even cannot support it correctly.

And the DateFormatter has tell it could support absl::FormatTime in its comments.

https://github.com/envoyproxy/envoy/blob/9537fce85d4f919d4b16de280f0ddf5b0130b8b5/source/common/common/utility.h#L43

So, I am inclined this is a code bug rather than a users-aware bug? If someone want to use this utility class, he may get unexpected result.

wbpcode avatar Jul 26 '24 13:07 wbpcode

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity occurs. Thank you for your contributions.

github-actions[bot] avatar Aug 25 '24 16:08 github-actions[bot]

This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted" or "no stalebot". Thank you for your contributions.

github-actions[bot] avatar Sep 01 '24 16:09 github-actions[bot]