Skip to content

Commit

Permalink
[patch] longer health check
Browse files Browse the repository at this point in the history
- To prevent overload

Signed-off-by: Alan P John <alansandra2013@gmail.com>
  • Loading branch information
alanpjohn committed Aug 14, 2023
1 parent 1230671 commit e57cfa6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func runTest(_ *cobra.Command, _ []string) error {
}

req := types.FunctionDeployment{
Image: "unikraft.org/uk-dynamic-html:latest",
Service: "dynamic-html",
Image: "unikraft.org/uk-py-faas:latest",
Service: "hello-world",
EnvVars: map[string]string{},
Secrets: []string{},
Labels: &map[string]string{},
Expand Down
11 changes: 8 additions & 3 deletions pkg/network/internal/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
)

type InternalNetworkContoller struct {
instanceCount uint64
healthCheckTable sync.Map
instancesMap sync.Map
defaultLoadBalancer LoadBalancerConstructor
Expand Down Expand Up @@ -64,8 +65,9 @@ func (n *InternalNetworkContoller) AddServiceIP(service string, ip networkapi.IP
if err != nil {
return err
}
n.healthCheckTable.Store(ip, true)
n.healthCheckTable.Store(ip, checkHealth(context.TODO(), ip, ""))
n.instancesMap.Store(service, updatedLb)
n.instanceCount += 1
log.Printf("[InternalNetworkController.AddServiceIP] - Added IP %s to Service %s", ip, service)
return nil
}
Expand All @@ -87,6 +89,7 @@ func (n *InternalNetworkContoller) DeleteServiceIP(service string, ip networkapi
n.instancesMap.Store(service, updatedLb)
}
n.healthCheckTable.Delete(ip)
n.instanceCount -= 1
log.Printf("[InternalNetworkController.DeleteServiceIP] - Deleted IP %s from Service %s", ip, service)
return nil
}
Expand All @@ -104,6 +107,7 @@ func (n *InternalNetworkContoller) DeleteService(service string) error {
ips := lb.GetIPs()
for ip := range ips {
n.healthCheckTable.Delete(ip)
n.instanceCount -= 1
}
log.Printf("[InternalNetworkController.DeleteService] - Deleted Service %s", service)
}
Expand Down Expand Up @@ -174,7 +178,8 @@ func (n *InternalNetworkContoller) RunHealthChecks(ctx context.Context) {
ip := key.(networkapi.IP)
health := checkHealth(ctx, ip, "/")
n.healthCheckTable.Store(ip, health)
time.Sleep(2 * time.Second)
delay := time.Duration(300) / time.Duration(n.instanceCount)
time.Sleep(delay * time.Second)
}
return true
})
Expand All @@ -195,5 +200,5 @@ func checkHealth(ctx context.Context, ip networkapi.IP, healthPath string) bool
return false
}
defer resp.Body.Close()
return resp.StatusCode == http.StatusOK
return resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusBadRequest
}
5 changes: 2 additions & 3 deletions pkg/store/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,8 @@ func (m *MachineStore) createMachine(ctx context.Context, mreq MachineRequest) e
go func(ip string) {
url := fmt.Sprintf("%s:%d", ip, pkg.WatchdogPort)
client := &http.Client{}
status := 0

for status != http.StatusOK {
for {
req, err := http.NewRequest("GET", fmt.Sprintf("http://%s", url), nil)
if err != nil {
time.Sleep(2 * time.Second)
Expand All @@ -443,8 +442,8 @@ func (m *MachineStore) createMachine(ctx context.Context, mreq MachineRequest) e
time.Sleep(2 * time.Second)
continue
}
status = resp.StatusCode
resp.Body.Close()
break
}

m.networkController.AddServiceIP(mreq.Service, networkapi.IP(ip))
Expand Down

0 comments on commit e57cfa6

Please sign in to comment.