From 3af0d4d0f21df312c5bdeab8552e1e99cdf6c796 Mon Sep 17 00:00:00 2001 From: Joe Tsai Date: Wed, 5 Oct 2022 12:27:52 -0700 Subject: [PATCH] logtail: always record timestamps in UTC (#5732) Upstream optimizations to the Go time package will make unmarshaling of time.Time 3-6x faster. See: * https://go.dev/cl/425116 * https://go.dev/cl/425197 * https://go.dev/cl/429862 The last optimization avoids a []byte -> string allocation if the timestamp string less than than 32B. Unfortunately, the presence of a timezone breaks that optimization. Drop recording of timezone as this is non-essential information. Most of the performance gains is upon unmarshal, but there is also a slight performance benefit to not marshaling the timezone as well. Signed-off-by: Joe Tsai --- logtail/logtail.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/logtail/logtail.go b/logtail/logtail.go index 7ffdeac67..6cb910ada 100644 --- a/logtail/logtail.go +++ b/logtail/logtail.go @@ -524,7 +524,7 @@ func (l *Logger) encodeText(buf []byte, skipClientTime bool, procID uint32, proc b = append(b, `"logtail": {`...) if !skipClientTime { b = append(b, `"client_time": "`...) - b = now.AppendFormat(b, time.RFC3339Nano) + b = now.UTC().AppendFormat(b, time.RFC3339Nano) b = append(b, `",`...) } if procID != 0 { @@ -617,7 +617,7 @@ func (l *Logger) encodeLocked(buf []byte, level int) []byte { if !l.skipClientTime || l.procID != 0 || l.procSequence != 0 { logtail := map[string]any{} if !l.skipClientTime { - logtail["client_time"] = now.Format(time.RFC3339Nano) + logtail["client_time"] = now.UTC().Format(time.RFC3339Nano) } if l.procID != 0 { logtail["proc_id"] = l.procID