Skip to content

Commit

Permalink
get timestamp
Browse files Browse the repository at this point in the history
Signed-off-by: Wenqi Qiu <[email protected]>
  • Loading branch information
wenqiq committed Feb 27, 2024
1 parent b189ce1 commit 1fae2c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
5 changes: 2 additions & 3 deletions test/performance/utils/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ func PingIP(ctx context.Context, kubeConfig *rest.Config, kc kubernetes.Interfac
}

func extractNanoseconds(logEntry string) (int, error) {
// 1709005058989452190 Status changed from unknown to up after 30217985 seconds
re := regexp.MustCompile(`(\d+) Status changed from`)
re := regexp.MustCompile(`(\d+)\s+Status changed from (unknown|down)? to up after`)
matches := re.FindStringSubmatch(logEntry)

if len(matches) < 2 {
Expand Down Expand Up @@ -135,7 +134,7 @@ func FetchTimestampFromLog(ctx context.Context, kc kubernetes.Interface, namespa
return false, fmt.Errorf("error when copying logs for Pod '%s/%s': %w", namespace, podName, err)
}
klog.InfoS("GetLogs from probe container", "logs", b.String())
if strings.Contains(b.String(), "Status changed from unknown to up") {
if strings.Contains(b.String(), "Status changed") {
changedTimeStamp, err := extractNanoseconds(b.String())
if err != nil {
return false, err
Expand Down
24 changes: 20 additions & 4 deletions test/performance/utils/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,25 @@ import (
)

func TestExtractSeconds(t *testing.T) {
res, err := extractSeconds("Fri Feb 23 06:52:14 UTC 2024 Status changed from unknown to up after 100 seconds")
if err != nil {
fmt.Println(err)
testCases := []struct {
name string
log string
}{
{
name: "",
log: "1234567 Status changed from unknown to up after 100 seconds",
},
{
name: "",
log: "12345678 Status changed from down to up after 100 seconds",
},
}
fmt.Println(res)
for _, tc := range testCases {
res, err := extractNanoseconds(tc.log)
if err != nil {
fmt.Println(err)
}
fmt.Println(res)
}

}

0 comments on commit 1fae2c3

Please sign in to comment.