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 29bdc40
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
14 changes: 7 additions & 7 deletions test/performance/framework/service/scale_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,16 @@ func ScaleUp(ctx context.Context, provider providers.ProviderInterface, controlP
// for _, ip := range reservedIPs {
// parsedIPs = append(parsedIPs, net.ParseIP(ip))
// }
allocator, err := ipallocator.NewCIDRAllocator(ipNet, nil)
allocator, err := ipallocator.NewCIDRAllocator(ipNet, []net.IP{net.ParseIP("10.96.0.1"), net.ParseIP("10.96.0.10")})

testPodIndex := 0
for _, ns := range nss {
klog.InfoS("Scale up Services", "Namespace", ns)
testPodIndex := 0
var podList *corev1.PodList
podList, err = cs.CoreV1().Pods(ns).List(ctx, metav1.ListOptions{})
if err != nil {
return
}
for _, svc := range generateService(ns, numPerNs) {
if ipv6 {
ipFamily := corev1.IPv6Protocol
Expand All @@ -146,11 +151,6 @@ func ScaleUp(ctx context.Context, provider providers.ProviderInterface, controlP
return fmt.Errorf("allocate IP from ServiceCIDR error: %+v", err)
}

var podList *corev1.PodList
podList, err = cs.CoreV1().Pods(ns).List(ctx, metav1.ListOptions{})
if err != nil {
return fmt.Errorf("list test Pod error: %+v", err)
}
var fromPod *corev1.Pod
if testPodIndex < len(podList.Items) {
fromPod = &podList.Items[testPodIndex]
Expand Down
7 changes: 3 additions & 4 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 @@ -134,8 +133,8 @@ func FetchTimestampFromLog(ctx context.Context, kc kubernetes.Interface, namespa
if _, err := io.Copy(&b, podLogs); err != nil {
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") {
klog.InfoS("GetLogs from probe container", "podName", podName, "namespace", namespace, "logs", b.String())
if strings.Contains(b.String(), "to up") {
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 29bdc40

Please sign in to comment.