Skip to content

Commit

Permalink
fix extract log
Browse files Browse the repository at this point in the history
Signed-off-by: Wenqi Qiu <[email protected]>
  • Loading branch information
wenqiq committed Mar 8, 2024
1 parent 739bb90 commit 76d6db5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
5 changes: 3 additions & 2 deletions test/performance/framework/client_pod/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,13 @@ func CreatePod(ctx context.Context, kClient kubernetes.Interface, probes []strin
return nil, err
}

err = wait.PollImmediate(2*time.Second, 60, func() (bool, error) {
err = wait.PollImmediateWithContext(ctx, time.Second, 60, func(ctx context.Context) (bool, error) {
pod, err := kClient.CoreV1().Pods(namespace).Get(ctx, newPod.Name, metav1.GetOptions{})
klog.InfoS("Get client Pod", "Name", newPod.Name, "Namespace", namespace, "Status", pod.Status)
if err != nil {
return false, err
}
return pod.Status.Phase == corev1.PodRunning, nil
return true, nil
})
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions test/performance/utils/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ func PingIP(ctx context.Context, kubeConfig *rest.Config, kc kubernetes.Interfac
return nil
}

func extractNanoseconds(logEntry string) (int64, error) {
re := regexp.MustCompile(`(\d+)\s+Status changed from (unknown|down)? to up after`)
func extractNanoseconds(logEntry, key string) (int64, error) {
re := regexp.MustCompile(fmt.Sprintf(`(\d+)\s+Status changed from (unknown|down|up)? %s after`, key))
matches := re.FindStringSubmatch(logEntry)

if len(matches) < 2 {
Expand Down Expand Up @@ -141,7 +141,7 @@ func FetchTimestampFromLog(ctx context.Context, kc kubernetes.Interface, namespa
}
klog.InfoS("GetLogs from probe container", "podName", podName, "namespace", namespace, "logs", b.String())
if strings.Contains(b.String(), key) {
changedTimeStamp, err := extractNanoseconds(b.String())
changedTimeStamp, err := extractNanoseconds(b.String(), key)
if err != nil {
return false, err
}
Expand Down
14 changes: 11 additions & 3 deletions test/performance/utils/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,26 @@ func TestExtractSeconds(t *testing.T) {
testCases := []struct {
name string
log string
key string
}{
{
name: "",
name: "unknown to up",
log: "1234567 Status changed from unknown to up after 100 seconds",
key: "to up",
},
{
name: "",
name: "down to up",
log: "12345678 Status changed from down to up after 100 seconds",
key: "to up",
},
{
name: "unknown to down",
log: "1709868559530201288 Status changed from unknown to down after 1007982937 nanoseconds",
key: "to down",
},
}
for _, tc := range testCases {
res, err := extractNanoseconds(tc.log)
res, err := extractNanoseconds(tc.log, tc.key)
if err != nil {
fmt.Println(err)
}
Expand Down

0 comments on commit 76d6db5

Please sign in to comment.