Skip to content

Commit

Permalink
add debug log for scale test
Browse files Browse the repository at this point in the history
  • Loading branch information
yabinma committed Nov 18, 2024
1 parent b79d031 commit f722b8a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
6 changes: 6 additions & 0 deletions controllers/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,19 @@ func hostUpdateFallback(w http.ResponseWriter, r *http.Request) {
switch hostUpdate.Action {
case models.CheckIn:
sendPeerUpdate = mq.HandleHostCheckin(&hostUpdate.Host, currentHost)
if sendPeerUpdate {
slog.Error("sendPeerUpdate from CheckIn", "Debug", sendPeerUpdate, &hostUpdate.Host.Name, &hostUpdate.Host.ID)
}

case models.UpdateHost:
if hostUpdate.Host.PublicKey != currentHost.PublicKey {
//remove old peer entry
replacePeers = true
}
sendPeerUpdate = logic.UpdateHostFromClient(&hostUpdate.Host, currentHost)
if sendPeerUpdate {
slog.Error("sendPeerUpdate from UpdateHost", "Debug", sendPeerUpdate, &hostUpdate.Host.Name, &hostUpdate.Host.ID)
}
err := logic.UpsertHost(currentHost)
if err != nil {
slog.Error("failed to update host", "id", currentHost.ID, "error", err)
Expand Down
6 changes: 6 additions & 0 deletions logic/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,25 +243,30 @@ func UpdateHost(newHost, currentHost *models.Host) {
// UpdateHostFromClient - used for updating host on server with update recieved from client
func UpdateHostFromClient(newHost, currHost *models.Host) (sendPeerUpdate bool) {
if newHost.PublicKey != currHost.PublicKey {
slog.Error("PublicKey changed:", "Debug")
currHost.PublicKey = newHost.PublicKey
sendPeerUpdate = true
}
if newHost.ListenPort != 0 && currHost.ListenPort != newHost.ListenPort {
slog.Error("ListenPort changed:", "Debug", currHost.ListenPort, newHost.ListenPort)
currHost.ListenPort = newHost.ListenPort
sendPeerUpdate = true
}
if newHost.WgPublicListenPort != 0 &&
currHost.WgPublicListenPort != newHost.WgPublicListenPort {
slog.Error("WgPublicListenPort changed:", "Debug", currHost.WgPublicListenPort, newHost.WgPublicListenPort)
currHost.WgPublicListenPort = newHost.WgPublicListenPort
sendPeerUpdate = true
}
isEndpointChanged := false
if currHost.EndpointIP.String() != newHost.EndpointIP.String() {
slog.Error("EndpointIP changed:", "Debug", currHost.EndpointIP, newHost.EndpointIP)
currHost.EndpointIP = newHost.EndpointIP
sendPeerUpdate = true
isEndpointChanged = true
}
if currHost.EndpointIPv6.String() != newHost.EndpointIPv6.String() {
slog.Error("EndpointIPv6 changed:", "Debug", currHost.EndpointIPv6, newHost.EndpointIPv6)
currHost.EndpointIPv6 = newHost.EndpointIPv6
sendPeerUpdate = true
isEndpointChanged = true
Expand Down Expand Up @@ -290,6 +295,7 @@ func UpdateHostFromClient(newHost, currHost *models.Host) (sendPeerUpdate bool)

currHost.Name = newHost.Name
if len(newHost.NatType) > 0 && newHost.NatType != currHost.NatType {
slog.Error("NatType changed:", "Debug", currHost.NatType, newHost.NatType)
currHost.NatType = newHost.NatType
sendPeerUpdate = true
}
Expand Down
7 changes: 7 additions & 0 deletions mq/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ func UpdateHost(client mqtt.Client, msg mqtt.Message) {
switch hostUpdate.Action {
case models.CheckIn:
sendPeerUpdate = HandleHostCheckin(&hostUpdate.Host, currentHost)
if sendPeerUpdate {
slog.Error("sendPeerUpdate from UpdateHost.CheckIn", "Debug", sendPeerUpdate, &hostUpdate.Host.Name, &hostUpdate.Host.ID)
}

case models.Acknowledgement:
hu := hostactions.GetAction(currentHost.ID.String())
if hu != nil {
Expand All @@ -129,6 +133,9 @@ func UpdateHost(client mqtt.Client, msg mqtt.Message) {
replacePeers = true
}
sendPeerUpdate = logic.UpdateHostFromClient(&hostUpdate.Host, currentHost)
if sendPeerUpdate {
slog.Error("sendPeerUpdate from UpdateHost.UpdateHost", "Debug", sendPeerUpdate, &hostUpdate.Host.Name, &hostUpdate.Host.ID)
}
err := logic.UpsertHost(currentHost)
if err != nil {
slog.Error("failed to update host", "id", currentHost.ID, "error", err)
Expand Down
11 changes: 6 additions & 5 deletions mq/publishers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ import (

var batchSize = servercfg.GetPeerUpdateBatchSize()
var batchUpdate = servercfg.GetBatchPeerUpdate()
var peerUpdateTS = time.Now().Unix()

//var peerUpdateTS = time.Now().Unix()

// PublishPeerUpdate --- determines and publishes a peer update to all the hosts
func PublishPeerUpdate(replacePeers bool) error {
slog.Error("entering PublishPeerUpdate", "Debug")
t1 := time.Now().Unix()
if time.Now().Unix()-peerUpdateTS < 60 {
return nil
}
peerUpdateTS = time.Now().Unix()
//if time.Now().Unix()-peerUpdateTS < 60 {
// return nil
//}
//peerUpdateTS = time.Now().Unix()

pc, file, no, ok := runtime.Caller(1)
if ok {
Expand Down

0 comments on commit f722b8a

Please sign in to comment.