From 6317c9dcb2deb7837d948ec20bf188e5dcdd339d Mon Sep 17 00:00:00 2001 From: zhanggaoming Date: Wed, 20 Jul 2022 16:15:56 +0800 Subject: [PATCH 1/3] log-backup: remove the timezone from log-date Signed-off-by: zhanggaoming --- br/pkg/stream/stream_status.go | 2 +- br/pkg/task/stream.go | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/br/pkg/stream/stream_status.go b/br/pkg/stream/stream_status.go index 53ab1a0fc2499..1dc67cd99bfd5 100644 --- a/br/pkg/stream/stream_status.go +++ b/br/pkg/stream/stream_status.go @@ -133,7 +133,7 @@ func (p *printByTable) AddTask(task TaskStatus) { if gap > 5*time.Minute { gapColor = color.New(color.FgRed) } - info := fmt.Sprintf("%s; gap=%s", pTime, gapColor.Sprint(gap)) + info := fmt.Sprintf("%s; gap=%s", pTime.Format("2006-01-02 15:04:05.999999999 -0700"), gapColor.Sprint(gap)) return info } cp := task.GetMinStoreCheckpoint() diff --git a/br/pkg/task/stream.go b/br/pkg/task/stream.go index 04b52adec2154..e5b4c6c32a471 100644 --- a/br/pkg/task/stream.go +++ b/br/pkg/task/stream.go @@ -575,10 +575,12 @@ func RunStreamMetadata( return errors.Trace(err) } + logMinDate := oracle.GetTimeFromTS(logMinTS).Format("2006-01-02 15:04:05.999999999 -0700") + logMaxDate := oracle.GetTimeFromTS(logMaxTS).Format("2006-01-02 15:04:05.999999999 -0700") summary.Log(cmdName, zap.Uint64("log-min-ts", logMinTS), - zap.String("log-min-date", oracle.GetTimeFromTS(logMinTS).String()), + zap.String("log-min-date", logMinDate), zap.Uint64("log-max-ts", logMaxTS), - zap.String("log-max-date", oracle.GetTimeFromTS(logMaxTS).String()), + zap.String("log-max-date", logMaxDate), ) return nil } From 75484bbf122c6461fade3edb12079f87f9618440 Mon Sep 17 00:00:00 2001 From: zhanggaoming Date: Wed, 20 Jul 2022 16:22:55 +0800 Subject: [PATCH 2/3] log-backup: remove the timezone from log-date Signed-off-by: zhanggaoming --- br/pkg/stream/stream_status.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/br/pkg/stream/stream_status.go b/br/pkg/stream/stream_status.go index 1dc67cd99bfd5..21e1aa6c8a362 100644 --- a/br/pkg/stream/stream_status.go +++ b/br/pkg/stream/stream_status.go @@ -117,9 +117,9 @@ func (p *printByTable) AddTask(task TaskStatus) { table := p.console.CreateTable() table.Add("name", task.Info.Name) table.Add("status", task.colorfulStatusString()) - table.Add("start", fmt.Sprint(oracle.GetTimeFromTS(task.Info.StartTs))) + table.Add("start", fmt.Sprint(oracle.GetTimeFromTS(task.Info.StartTs).Format("2006-01-02 15:04:05.999999999 -0700"))) if task.Info.EndTs > 0 { - table.Add("end", fmt.Sprint(oracle.GetTimeFromTS(task.Info.EndTs))) + table.Add("end", fmt.Sprint(oracle.GetTimeFromTS(task.Info.EndTs).Format("2006-01-02 15:04:05.999999999 -0700"))) } s := storage.FormatBackendURL(task.Info.GetStorage()) table.Add("storage", s.String()) From 64c763414268cc46cebda2a380334f7857366116 Mon Sep 17 00:00:00 2001 From: zhanggaoming Date: Thu, 21 Jul 2022 10:48:54 +0800 Subject: [PATCH 3/3] log-backup: remove the timezone from log-date Signed-off-by: zhanggaoming --- br/pkg/stream/stream_status.go | 6 +++--- br/pkg/stream/util.go | 13 +++++++++++++ br/pkg/stream/util_test.go | 31 +++++++++++++++++++++++++++++++ br/pkg/task/stream.go | 4 ++-- 4 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 br/pkg/stream/util.go create mode 100644 br/pkg/stream/util_test.go diff --git a/br/pkg/stream/stream_status.go b/br/pkg/stream/stream_status.go index 21e1aa6c8a362..d21a38204915e 100644 --- a/br/pkg/stream/stream_status.go +++ b/br/pkg/stream/stream_status.go @@ -117,9 +117,9 @@ func (p *printByTable) AddTask(task TaskStatus) { table := p.console.CreateTable() table.Add("name", task.Info.Name) table.Add("status", task.colorfulStatusString()) - table.Add("start", fmt.Sprint(oracle.GetTimeFromTS(task.Info.StartTs).Format("2006-01-02 15:04:05.999999999 -0700"))) + table.Add("start", fmt.Sprint(FormatDate(oracle.GetTimeFromTS(task.Info.StartTs)))) if task.Info.EndTs > 0 { - table.Add("end", fmt.Sprint(oracle.GetTimeFromTS(task.Info.EndTs).Format("2006-01-02 15:04:05.999999999 -0700"))) + table.Add("end", fmt.Sprint(FormatDate(oracle.GetTimeFromTS(task.Info.EndTs)))) } s := storage.FormatBackendURL(task.Info.GetStorage()) table.Add("storage", s.String()) @@ -133,7 +133,7 @@ func (p *printByTable) AddTask(task TaskStatus) { if gap > 5*time.Minute { gapColor = color.New(color.FgRed) } - info := fmt.Sprintf("%s; gap=%s", pTime.Format("2006-01-02 15:04:05.999999999 -0700"), gapColor.Sprint(gap)) + info := fmt.Sprintf("%s; gap=%s", FormatDate(pTime), gapColor.Sprint(gap)) return info } cp := task.GetMinStoreCheckpoint() diff --git a/br/pkg/stream/util.go b/br/pkg/stream/util.go new file mode 100644 index 0000000000000..6ad1018f832b6 --- /dev/null +++ b/br/pkg/stream/util.go @@ -0,0 +1,13 @@ +// Copyright 2022 PingCAP, Inc. Licensed under Apache-2.0. + +package stream + +import ( + "time" +) + +const DATE_FORMAT = "2006-01-02 15:04:05.999999999 -0700" + +func FormatDate(ts time.Time) string { + return ts.Format(DATE_FORMAT) +} diff --git a/br/pkg/stream/util_test.go b/br/pkg/stream/util_test.go new file mode 100644 index 0000000000000..1e2d85a565aff --- /dev/null +++ b/br/pkg/stream/util_test.go @@ -0,0 +1,31 @@ +// Copyright 2022 PingCAP, Inc. Licensed under Apache-2.0. + +package stream + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/tikv/client-go/v2/oracle" +) + +func TestDateFormat(t *testing.T) { + cases := []struct { + ts uint64 + target string + }{ + { + 434604259287760897, + "2022-07-15 19:14:39.534 +0800", + }, + { + 434605479096221697, + "2022-07-15 20:32:12.734 +0800", + }, + } + + for _, ca := range cases { + date := FormatDate(oracle.GetTimeFromTS(ca.ts)) + require.Equal(t, date, ca.target) + } +} diff --git a/br/pkg/task/stream.go b/br/pkg/task/stream.go index b9e3894a230f5..2aecb64aef8e0 100644 --- a/br/pkg/task/stream.go +++ b/br/pkg/task/stream.go @@ -573,8 +573,8 @@ func RunStreamMetadata( return errors.Trace(err) } - logMinDate := oracle.GetTimeFromTS(logMinTS).Format("2006-01-02 15:04:05.999999999 -0700") - logMaxDate := oracle.GetTimeFromTS(logMaxTS).Format("2006-01-02 15:04:05.999999999 -0700") + logMinDate := stream.FormatDate(oracle.GetTimeFromTS(logMinTS)) + logMaxDate := stream.FormatDate(oracle.GetTimeFromTS(logMaxTS)) summary.Log(cmdName, zap.Uint64("log-min-ts", logMinTS), zap.String("log-min-date", logMinDate), zap.Uint64("log-max-ts", logMaxTS),