Skip to content

Commit

Permalink
Fix fetch timestamp from Pod 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 14, 2024
1 parent 4536b3c commit 7f5614d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion test/performance/framework/networkpolicy/scale_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func ScaleUp(ctx context.Context, cs kubernetes.Interface, nss []string, numPerN
actualCheckNum++
go func() {
klog.InfoS("Update test Pod to check NetworkPolicy", "serverIP", serverIP, "StartTimeStamp", startTimeStamp)
key := "to down"
key := "up to down"
if err := utils.FetchTimestampFromLog(ctx, cs, clientPod.Namespace, clientPod.Name, client_pod.ScaleClientPodProbeContainer, ch, startTimeStamp, key); err != nil {
klog.ErrorS(err, "Checking the validity the NetworkPolicy error", "ClientPodName", clientPod.Name, "NetworkPolicy", npInfo)
}
Expand Down
6 changes: 4 additions & 2 deletions test/performance/framework/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func ScaleRestartAgent(ctx context.Context, ch chan time.Duration, data *ScaleDa
if pod.Status.Phase != v1.PodRunning {
continue
}
key := "to up"
key := "down to up"
if err := utils.FetchTimestampFromLog(ctx, data.kubernetesClientSet, pod.Namespace, pod.Name, client_pod.ScaleAgentProbeContainerName, ch, startTime, key); err != nil {
klog.ErrorS(err, "Checking antrea agent restart time error", "ClientPodName", pod.Name)
}
Expand Down Expand Up @@ -125,12 +125,14 @@ func RestartController(ctx context.Context, ch chan time.Duration, data *ScaleDa
return
}

startTime0 := time.Now().UnixNano()
err = data.kubernetesClientSet.CoreV1().Pods(metav1.NamespaceSystem).
DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: "app=antrea,component=antrea-controller"})
if err != nil {
return
}
startTime := time.Now().UnixNano()
klog.InfoS("Deleting operate time", "Duration(ms)", (startTime-startTime0)/1000000)

err = wait.PollImmediateUntil(config.WaitInterval, func() (bool, error) {
var dp *appv1.Deployment
Expand All @@ -156,7 +158,7 @@ func RestartController(ctx context.Context, ch chan time.Duration, data *ScaleDa
continue
}
if pod.Spec.NodeName == controllerPod.Spec.NodeName {
key := "to up"
key := "down to up"
if err := utils.FetchTimestampFromLog(ctx, data.kubernetesClientSet, pod.Namespace, pod.Name, client_pod.ScaleControllerProbeContainerName, ch, startTime, key); err != nil {
klog.ErrorS(err, "Checking antrea controller restart time error", "ClientPodName", pod.Name)
}
Expand Down
2 changes: 1 addition & 1 deletion test/performance/framework/service/scale_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func ScaleUp(ctx context.Context, provider providers.ProviderInterface, controlP
if shouldCheck && clientPod != nil {
go func() {
startTimeStamp := time.Now().UnixNano()
key := "to up"
key := "down to up"
if err := utils.FetchTimestampFromLog(ctx, cs, clientPod.Namespace, clientPod.Name, workload_pod.ScaleTestPodProbeContainerName, ch, startTimeStamp, key); err != nil {
klog.ErrorS(err, "Check readiness of service error", "ClientPodName", clientPod.Name, "svc", svc)
}
Expand Down
3 changes: 2 additions & 1 deletion test/performance/utils/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ func PingIP(ctx context.Context, kubeConfig *rest.Config, kc kubernetes.Interfac
}

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

if len(matches) < 2 {
Expand Down
6 changes: 3 additions & 3 deletions test/performance/utils/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ func TestExtractSeconds(t *testing.T) {
{
name: "unknown to up",
log: "1234567 Status changed from unknown to up after 100 seconds",
key: "to up",
key: "unknown to up",
},
{
name: "down to up",
log: "12345678 Status changed from down to up after 100 seconds",
key: "to up",
key: "down to up",
},
{
name: "unknown to down",
log: "1709868559530201288 Status changed from unknown to down after 1007982937 nanoseconds",
key: "to down",
key: "unknown to down",
},
}
for _, tc := range testCases {
Expand Down

0 comments on commit 7f5614d

Please sign in to comment.