Skip to content

Commit

Permalink
log-backup: remove the timezone from log-date
Browse files Browse the repository at this point in the history
Signed-off-by: zhanggaoming <[email protected]>
  • Loading branch information
MoCuishle28 committed Jul 21, 2022
1 parent e1cd57f commit 64c7634
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
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

0 comments on commit 64c7634

Please sign in to comment.