Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log-backup: remove the timezone from log-date #36369

Merged
merged 13 commits into from
Jul 21, 2022
Merged
Prev Previous commit
Next Next commit
log-backup: remove the timezone from log-date
Signed-off-by: zhanggaoming <gaoming.zhang@pingcap.com>
  • Loading branch information
MoCuishle28 committed Jul 21, 2022
commit 64c763414268cc46cebda2a380334f7857366116
6 changes: 3 additions & 3 deletions br/pkg/stream/stream_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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()
Expand Down
13 changes: 13 additions & 0 deletions br/pkg/stream/util.go
Original file line number Diff line number Diff line change
@@ -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)
}
31 changes: 31 additions & 0 deletions br/pkg/stream/util_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
4 changes: 2 additions & 2 deletions br/pkg/task/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down