Skip to content

Commit

Permalink
BugFix 🐛 Fix both latency and packet manipulation proxies connectivity
Browse files Browse the repository at this point in the history
  • Loading branch information
lumbrjx committed Sep 4, 2024
1 parent 0e6d4f5 commit e5359f6
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 82 deletions.
2 changes: 1 addition & 1 deletion controller/config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ kind: Kustomization
images:
- name: controller
newName: lumbrjx/obzev0-k8s-controller
newTag: temp7
newTag: temp10
16 changes: 8 additions & 8 deletions controller/config/samples/batch_v1_obzev0resource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ metadata:
name: obzev0resource-sample
spec:
latencySvcConfig:
enabled: false
reqDelay: 3
resDelay: 5
server: "7080"
client: "8080"
enabled: true
reqDelay: 1
resDelay: 1
server: "7070"
client: "10.244.2.4:8080"
tcAnalyserSvcConfig:
enabled: false
netIFace: "eth0"
packetManipulationSvcConfig:
enabled: true
server: "7090"
client: "8080"
server: "9091"
client: "10.244.2.4:8080"
dropRate: "0.8"
corruptRate: "0.4"
durationSeconds: 2
durationSeconds: 8
status:
message: "Server started successfully"

2 changes: 1 addition & 1 deletion controller/internal/controller/grpcClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func callGrpcServices(
ctx,
&pca.RequestForManipulationProxy{Config: &pca.PctmConfig{
Server: config.PctmConfig.Server,
Client: config.LatencyConfig.Server,
Client: config.PctmConfig.Client,

DurationConfig: &pca.DurationConfig{
DurationSeconds: config.PctmConfig.DurationSeconds,
Expand Down
61 changes: 27 additions & 34 deletions daemon/api/grpc/helper/requestSimulator.go
Original file line number Diff line number Diff line change
@@ -1,50 +1,43 @@
package helper

import (
"fmt"
"log"
"net"
"net/http"
"time"
)

func ReqSimulator(
targetAddr string,
duration time.Duration,
) error {
endTime := time.Now().Add(duration)

for time.Now().Before(endTime) {
conn, err := net.Dial("tcp", ":"+targetAddr)
if err != nil {
log.Printf("Failed to connect to target: %v", err)
return err
}

request := "GET / HTTP/1.1\r\n" +
"Host: " + targetAddr + "\r\n" +
"Connection: close\r\n" +
"\r\n"
func sendReq(client *http.Client, targetAddr string) {
resp, err := client.Get("http://127.0.0.1:" + targetAddr)
if err != nil {
log.Printf("Failed to send request: %v", err)
return
}
defer resp.Body.Close()

_, err = conn.Write([]byte(request))
if err != nil {
log.Printf("Failed to write to target: %v", err)
conn.Close()
return err
}
if resp == nil {
log.Println("Response is nil")
return
}

buf := make([]byte, 1024)
n, err := conn.Read(buf)
if err != nil {
log.Printf("Failed to read from target: %v", err)
conn.Close()
return err
}
log.Printf("Response status: %s", resp.Status)
time.Sleep(2 * time.Second)
}

log.Printf("Received response: %s", string(buf[:n]))
func ReqSimulator(targetAddr string, oneTime bool, duration time.Duration) error {
client := &http.Client{}

conn.Close()
if oneTime {
sendReq(client, targetAddr)
} else {
startTime := time.Now()
endTime := startTime.Add(duration - 3*time.Second)

time.Sleep(1 * time.Second)
for time.Now().Before(endTime) {
sendReq(client, targetAddr)
}
}

fmt.Println("Timeout reached, stopping the requests.")
return nil
}
3 changes: 2 additions & 1 deletion daemon/api/grpc/latency/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func (s *LatencyService) StartTcpServer(
time.Sleep(2 * time.Second)
err := helper.ReqSimulator(
config.Server,
time.Duration(1)*time.Second,
true,
time.Duration(0)*time.Second,
)
if err != nil {
log.Printf("Error in ReqSimulator: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion daemon/api/grpc/packetManipulation/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func Proxy(conf ProxyConfig) error {
}
}

clientConn, err := net.Dial("tcp", ":"+conf.Client)
clientConn, err := net.Dial("tcp", conf.Client)
if err != nil {
log.Printf("Error connecting to client: %v", err)
conn.Close()
Expand Down
35 changes: 10 additions & 25 deletions daemon/api/grpc/packetManipulation/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ func (s *PacketManipulationService) StartManipulationProxy(
Client: config.Client,
}

done := make(chan struct{})

// Start proxy in a goroutine
if config.DurationConfig.DurationSeconds != 0 {
proxyConfiguration.DropRate = float64(config.DurationConfig.DropRate)
Expand All @@ -56,32 +54,19 @@ func (s *PacketManipulationService) StartManipulationProxy(
log.Printf("Error in manipulation Proxy: %v", err)
}
}()
for {
select {
case <-done:
break
default:
time.Sleep(2 * time.Second)
err := helper.ReqSimulator(
config.Server,
time.Duration(
config.DurationConfig.DurationSeconds,
)*time.Second,
)
if err != nil {
log.Printf("Request simulation error: %v", err)
}
}
time.Sleep(2 * time.Second)
err := helper.ReqSimulator(
config.Server,
false,
time.Duration(
config.DurationConfig.DurationSeconds,
)*time.Second,
)
if err != nil {
log.Printf("Request simulation error: %v", err)
}
}

time.AfterFunc(
time.Duration(config.DurationConfig.DurationSeconds)*time.Second,
func() {
close(done)
log.Println("Stopping the proxy after duration")
},
)
return &packetManipulation.ResponseFromManipulationProxy{
Message: "User Space program staus :",
}, nil
Expand Down
2 changes: 1 addition & 1 deletion daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
spec:
containers:
- name: grpc-server
image: lumbrjx/obzev0-grpc-daemon:latest
image: lumbrjx/obzev0-grpc-daemon:try.05
ports:
- containerPort: 50051
livenessProbe:
Expand Down
21 changes: 21 additions & 0 deletions expressdep.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-express-app
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: my-express-app
template:
metadata:
labels:
app: my-express-app
spec:
containers:
- name: my-express
image: lumbrjx/my-express:latest # Use the name and tag of your Docker image
ports:
- containerPort: 8080

14 changes: 14 additions & 0 deletions expresssvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: my-express-app-service
namespace: default
spec:
selector:
app: my-express-app
ports:
- protocol: TCP
port: 8080
targetPort: 8080
type: ClusterIP

53 changes: 44 additions & 9 deletions hello-world-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,57 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: hello-world
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: http-echo
image: hashicorp/http-echo:latest
args:
- "-text=Hello, World!"
ports:
- containerPort: 8080
- name: http-echo
image: hashicorp/http-echo:latest
ports:
- containerPort: 8080
resources:
limits:
cpu: 500m
memory: 128Mi
requests:
cpu: 250m
memory: 64Mi
securityContext:
capabilities:
add: ["SYS_RESOURCE", "SYS_ADMIN"]
runAsUser: 0
runAsGroup: 0
privileged: true
allowPrivilegeEscalation: true
readOnlyRootFilesystem: false
nodeSelector:
node-role.kubernetes.io/worker: ""
tolerations:
- key: "node-role.kubernetes.io/control-plane"
operator: "Exists"
effect: "NoSchedule"
- key: "node.kubernetes.io/disk-pressure"
operator: "Exists"
effect: "NoSchedule"
- key: "node.kubernetes.io/memory-pressure"
operator: "Exists"
effect: "NoSchedule"
- key: "node.kubernetes.io/not-ready"
operator: "Exists"
effect: "NoExecute"
- key: "node.kubernetes.io/pid-pressure"
operator: "Exists"
effect: "NoSchedule"
- key: "node.kubernetes.io/unreachable"
operator: "Exists"
effect: "NoExecute"
- key: "node.kubernetes.io/unschedulable"
operator: "Exists"
effect: "NoSchedule"

2 changes: 1 addition & 1 deletion hello-world-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ spec:
- protocol: TCP
port: 8080
targetPort: 8080
type: LoadBalancer
type: NodePort

0 comments on commit e5359f6

Please sign in to comment.