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
6 changes: 3 additions & 3 deletions br/pkg/stream/stream_status.go
Expand Up @@ -119,9 +119,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(FormatDate(oracle.GetTimeFromTS(task.Info.StartTs))))
if task.Info.EndTs > 0 {
table.Add("end", fmt.Sprint(oracle.GetTimeFromTS(task.Info.EndTs)))
table.Add("end", fmt.Sprint(FormatDate(oracle.GetTimeFromTS(task.Info.EndTs))))
}
s := storage.FormatBackendURL(task.Info.GetStorage())
table.Add("storage", s.String())
Expand All @@ -135,7 +135,7 @@ func (p *printByTable) AddTask(task TaskStatus) {
if gap > 10*time.Minute {
gapColor = color.New(color.FgRed)
}
info := fmt.Sprintf("%s; gap=%s", pTime, gapColor.Sprint(gap))
info := fmt.Sprintf("%s; gap=%s", FormatDate(pTime), gapColor.Sprint(gap))
return info
}
table.Add("checkpoint[global]", formatTS(task.globalCheckpoint))
Expand Down
13 changes: 13 additions & 0 deletions 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)
}
31 changes: 31 additions & 0 deletions 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)
}
}
6 changes: 4 additions & 2 deletions br/pkg/task/stream.go
Expand Up @@ -573,10 +573,12 @@ func RunStreamMetadata(
return errors.Trace(err)
}

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", 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
}
Expand Down